/** * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances, * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying * container, which can increase beyond this value if <code>maxIdle > initIdleCapacity.</code></p> * * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code> * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack<T>(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
@PerformanceSensitive public Stack<Class<?>> getCurrentStackTrace() { // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int) if (getSecurityManager() != null) { final Class<?>[] array = getSecurityManager().getClassContext(); final Stack<Class<?>> classes = new Stack<>(); classes.ensureCapacity(array.length); for (final Class<?> clazz : array) { classes.push(clazz); } return classes; } // slower version using getCallerClass where we cannot use a SecurityManager final Stack<Class<?>> classes = new Stack<>(); Class<?> clazz; for (int i = 1; null != (clazz = getCallerClass(i)); i++) { classes.push(clazz); } return classes; }
@Test public void testGetCurrentStackTrace() throws Exception { final Stack<Class<?>> classes = StackLocatorUtil.getCurrentStackTrace(); final Stack<Class<?>> reversed = new Stack<>(); reversed.ensureCapacity(classes.size()); while (!classes.empty()) { reversed.push(classes.pop()); } while (reversed.peek() != StackLocatorUtil.class) { reversed.pop(); } reversed.pop(); // ReflectionUtil assertSame(StackLocatorUtilTest.class, reversed.pop()); }
if(null == stack) { stack = new Stack<V>(); stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity); _pools.put(key,stack);
if(null == stack) { stack = new Stack<V>(); stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity); _pools.put(key,stack);
if(null == stack) { stack = new Stack<V>(); stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity); _pools.put(key,stack);
/** * Create a new <tt>SimpleObjectPool</tt> using * the specified <i>factory</i> to create new instances, * capping the number of "sleeping" instances to <i>max</i>, * and initially allocating a container capable of containing * at least <i>init</i> instances. * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
/** * Create a new <tt>SimpleObjectPool</tt> using * the specified <i>factory</i> to create new instances, * capping the number of "sleeping" instances to <i>max</i>, * and initially allocating a container capable of containing * at least <i>init</i> instances. * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
/** * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances, * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying * container, which can increase beyond this value if <code>maxIdle > initIdleCapacity.</code></p> * * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code> * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
/** * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances, * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying * container, which can increase beyond this value if <code>maxIdle > initIdleCapacity.</code></p> * * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code> * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack<T>(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
/** * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances, * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying * container, which can increase beyond this value if <code>maxIdle > initIdleCapacity.</code></p> * * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code> * * @param factory the {@link PoolableObjectFactory} used to populate the pool * @param maxIdle cap on the number of "sleeping" instances in the pool * @param initIdleCapacity initial size of the pool (this specifies the size of the container, * it does not cause the pool to be pre-populated.) */ public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) { _factory = factory; _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle); int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity); _pool = new Stack<T>(); _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity); }
public BottomUpImmutableNodeTransformer(final SN srcRootNode, final BiFunction<SN, DN[], DN> nodeMapper, final IntFunction<DN[]> arrayConstructor) { mappedNodesStack.ensureCapacity(128); this.nodeMapper = nodeMapper; this.arrayConstructor = arrayConstructor; this.mutator = new AtomicReference<>(Thread.currentThread()); this.dstRootNode = null; // nodeMapper.apply(srcRootNode, mutator); final ListIterator<SN> srcIterator = (ListIterator<SN>) srcRootNode.nodeArray().iterator(); if (srcIterator.hasNext()) { // final ListIterator<DN> dstIterator = (ListIterator<DN>) dstRootNode.nodeArray().iterator(); // // pushOnStack(srcIterator, dstIterator); pushOnStack(srcRootNode); } else { // TODO: Transform Leaf Node mappedNodesStack.push(nodeMapper.apply(srcRootNode, (DN[]) EMPTY_DN_ARRAY)); } }
public BottomUpImmutableNodeTransformer(final SN srcRootNode, final BiFunction<SN, DN[], DN> nodeMapper) { mappedNodesStack.ensureCapacity(128); this.nodeMapper = nodeMapper; this.mutator = new AtomicReference<>(Thread.currentThread()); this.dstRootNode = null; // nodeMapper.apply(srcRootNode, mutator); final ListIterator<SN> srcIterator = (ListIterator<SN>) srcRootNode.nodeArray().iterator(); if (srcIterator.hasNext()) { // final ListIterator<DN> dstIterator = (ListIterator<DN>) dstRootNode.nodeArray().iterator(); // // pushOnStack(srcIterator, dstIterator); pushOnStack(srcRootNode); } else { // TODO: Transform Leaf Node mappedNodesStack.push(nodeMapper.apply(srcRootNode, (DN[]) EMPTY_DN_ARRAY)); } }
public static Stack<Class<?>> getCurrentStackTrace() { // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int) if (SECURITY_MANAGER != null) { final Class<?>[] array = SECURITY_MANAGER.getClassContext(); final Stack<Class<?>> classes = new Stack<Class<?>>(); classes.ensureCapacity(array.length); for (final Class<?> clazz : array) { classes.push(clazz); } return classes; } // slower version using getCallerClass where we cannot use a SecurityManager if (supportsFastReflection()) { final Stack<Class<?>> classes = new Stack<Class<?>>(); Class<?> clazz; for (int i = 1; null != (clazz = getCallerClass(i)); i++) { classes.push(clazz); } return classes; } return new Stack<Class<?>>(); }
/** * Instantiates a new reverse EWAH iterator. * * @param buffer the buffer */ public ReverseEWAHIterator(final Buffer buffer) { this.pointer = 0; this.rlw = new RunningLengthWord(buffer, this.pointer); this.positions = new Stack<Integer>(); this.positions.ensureCapacity(buffer.sizeInWords()); while(this.pointer < buffer.sizeInWords()) { this.positions.push(this.pointer); this.rlw.position = this.pointer; this.pointer += this.rlw.getNumberOfLiteralWords() + 1; } }
/** * Instantiates a new reverse EWAH iterator. * * @param buffer the buffer */ public ReverseEWAHIterator(final Buffer buffer) { this.pointer = 0; this.rlw = new RunningLengthWord(buffer, this.pointer); this.positions = new Stack<Integer>(); this.positions.ensureCapacity(buffer.sizeInWords()); while(this.pointer < buffer.sizeInWords()) { this.positions.push(this.pointer); this.rlw.position = this.pointer; this.pointer += this.rlw.getNumberOfLiteralWords() + 1; } }
/** * Instantiates a new reverse EWAH iterator. * * @param buffer the buffer */ public ReverseEWAHIterator32(final Buffer32 buffer) { this.pointer = 0; this.rlw = new RunningLengthWord32(buffer, this.pointer); this.positions = new Stack<Integer>(); this.positions.ensureCapacity(buffer.sizeInWords()); while(this.pointer < buffer.sizeInWords()) { this.positions.push(this.pointer); this.rlw.position = this.pointer; this.pointer += this.rlw.getNumberOfLiteralWords() + 1; } }
/** * Instantiates a new reverse EWAH iterator. * * @param buffer the buffer */ public ReverseEWAHIterator32(final Buffer32 buffer) { this.pointer = 0; this.rlw = new RunningLengthWord32(buffer, this.pointer); this.positions = new Stack<Integer>(); this.positions.ensureCapacity(buffer.sizeInWords()); while(this.pointer < buffer.sizeInWords()) { this.positions.push(this.pointer); this.rlw.position = this.pointer; this.pointer += this.rlw.getNumberOfLiteralWords() + 1; } }
@PerformanceSensitive public Stack<Class<?>> getCurrentStackTrace() { // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int) if (getSecurityManager() != null) { final Class<?>[] array = getSecurityManager().getClassContext(); final Stack<Class<?>> classes = new Stack<>(); classes.ensureCapacity(array.length); for (final Class<?> clazz : array) { classes.push(clazz); } return classes; } // slower version using getCallerClass where we cannot use a SecurityManager final Stack<Class<?>> classes = new Stack<>(); Class<?> clazz; for (int i = 1; null != (clazz = getCallerClass(i)); i++) { classes.push(clazz); } return classes; }
stack.ensureCapacity(end - start + 1); stack.push(new Pair<>(prefix,start)); while (!stack.isEmpty()) {