diff --git a/vtm/src/org/oscim/utils/pool/Inlist.java b/vtm/src/org/oscim/utils/pool/Inlist.java index 68c55378..dd2096cb 100644 --- a/vtm/src/org/oscim/utils/pool/Inlist.java +++ b/vtm/src/org/oscim/utils/pool/Inlist.java @@ -51,7 +51,7 @@ public class Inlist> { */ static > int size(T list) { int count = 0; - for (Inlist l = list; l != null; l = l.next) + for (T l = list; l != null; l = l.next) count++; return count; } @@ -71,7 +71,7 @@ public class Inlist> { return head; } - for (Inlist prev = list, it = list.next; it != null; it = it.next) { + for (T prev = list, it = list.next; it != null; it = it.next) { if (it == item) { prev.next = item.next; item.next = null; @@ -121,8 +121,7 @@ public class Inlist> { if (list == null) return item; - Inlist it = list; - + T it = list; while (it.next != null) it = it.next; @@ -147,15 +146,14 @@ public class Inlist> { if (list == other) return list; - Inlist it = list; - - while (it.next != null) { - if (it.next == other) + for (T it = list;; it = it.next) { + if (it.next == null) { + it.next = other; + break; + } else if (it.next == other) { throw new IllegalArgumentException("'other' alreay in 'list'"); - - it = it.next; + } } - it.next = other; return list; } @@ -198,7 +196,7 @@ public class Inlist> { return item; } - Inlist it = list; + T it = list; while (it != null && it.next != other) it = it.next; diff --git a/vtm/src/org/oscim/utils/pool/Pool.java b/vtm/src/org/oscim/utils/pool/Pool.java index 480f93e1..cc84fa32 100644 --- a/vtm/src/org/oscim/utils/pool/Pool.java +++ b/vtm/src/org/oscim/utils/pool/Pool.java @@ -21,6 +21,8 @@ import javax.annotation.CheckReturnValue; public abstract class Pool> { protected T pool; + protected int limit; + protected int fill; /** * @param item release resources @@ -75,41 +77,20 @@ public abstract class Pool> { return null; } - // remove 'item' from 'list' and add back to pool + /** remove 'item' from 'list' and add back to pool */ public T release(T list, T item) { if (item == null) return list; clearItem(item); - if (item == list) { - T ret = item.next; - - item.next = pool; - pool = item; - - return ret; - } - - for (T prev = list, it = list.next; it != null; it = it.next) { - - if (it == item) { - prev.next = it.next; - - item.next = pool; - pool = item; - break; - } - prev = it; - } + Inlist.remove(list, item); return list; } - protected abstract T createItem(); - + /** get an item from pool */ public T get() { - if (pool == null) return createItem(); @@ -119,4 +100,6 @@ public abstract class Pool> { ret.next = null; return ret; } + + protected abstract T createItem(); } diff --git a/vtm/src/org/oscim/utils/pool/SyncPool.java b/vtm/src/org/oscim/utils/pool/SyncPool.java index 18b66999..fe8cd4f7 100644 --- a/vtm/src/org/oscim/utils/pool/SyncPool.java +++ b/vtm/src/org/oscim/utils/pool/SyncPool.java @@ -39,17 +39,21 @@ public abstract class SyncPool> { } /** + * To be implemented by subclass. + * * @param items - * number of initial items. NOTE: default does nothing! + * number of initial items */ public void init(int items) { + fill = 0; + pool = null; } /** * @param item * set initial state - * @return true when item should be added back to pool - * when returning false freeItem will not be called. + * @return 'true' when item should be added back to pool, + * 'false' when freeItem should be called. */ protected boolean clearItem(T item) { return true;