/** * Moves the contents of another stack into this one, * but only up to the limit of this stack. If the source stack * contains more objects than free positions in this stack, then objects * will be lost. * * @param os The object stack to copy from. This stack will be cleared. */ void copy(ObjectStack os) { int len = stack.length - count; if (len > os.count) { len = os.count; } if (len > 0) { System.arraycopy(os.stack, os.count - len, stack, count, len); count += len; } os.clear(); }
npOS.copy(os); nextPool.put(TYPE_OBJECTSTACK, os);
/** * METHOD TO DO * * @param type PARAMETER TO DO * @param key PARAMETER TO DO * @param o PARAMETER TO DO */ public void put(int type, int key, Object o) { assert refCount > 0; if ( (type == TYPE_S_BLOCK) && (key == 8192)) { put(TYPE_BLOCK_8192, o); return; } Key k = newKeyInstance(type, key); ObjectStack os = (ObjectStack) sizedObjectStacks.get(k); if (os == null) { os = newObjectStackInstance(); sizedObjectStacks.put(k, os); } else { put(TYPE_KEY, k); } os.push(o); }
/** * Gets a pooled object of a given type and size from this pool. * * @param type The ID of the type of object to find. * @param key The size of the object to find. * @return A pooled object, or <code>null</code> if no objects are available. */ public Object get(int type, int key) { assert refCount > 0; if ( (type == TYPE_S_BLOCK) && (key == 8192)) { return get(TYPE_BLOCK_8192); } Key k = newKeyInstance(type, key); ObjectStack os = (ObjectStack) sizedObjectStacks.get(k); put(TYPE_KEY, k); if ( (os != null) && !os.isEmpty()) { return os.pop(); } if (nextPool != null) { synchronized (nextPool) { return nextPool.get(type, key); } } return null; }
/** * Creates a new ObjectStack. * * @return A fresh {@link ObjectStack}. */ private ObjectStack newObjectStackInstance() { ObjectStack os = (ObjectStack) get(TYPE_OBJECTSTACK); if (os == null) { os = new ObjectStack(OBJECT_STACK_SIZE_LIMIT); } return os; }