java.util.Stack.ensureCapacity()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中java.util.Stack.ensureCapacity()方法的一些代码示例,展示了Stack.ensureCapacity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stack.ensureCapacity()方法的具体详情如下:
包路径:java.util.Stack
类名称:Stack
方法名:ensureCapacity

Stack.ensureCapacity介绍

暂无

代码示例

代码示例来源:origin: commons-pool/commons-pool

  1. /**
  2. * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances,
  3. * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container
  4. * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated.
  5. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying
  6. * container, which can increase beyond this value if <code>maxIdle &gt; initIdleCapacity.</code></p>
  7. *
  8. * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using
  9. * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code>
  10. *
  11. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  12. * @param maxIdle cap on the number of "sleeping" instances in the pool
  13. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  14. * it does not cause the pool to be pre-populated.)
  15. */
  16. public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
  17. _factory = factory;
  18. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  19. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  20. _pool = new Stack<T>();
  21. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  22. }

代码示例来源:origin: org.apache.logging.log4j/log4j-api

  1. @PerformanceSensitive
  2. public Stack<Class<?>> getCurrentStackTrace() {
  3. // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
  4. if (getSecurityManager() != null) {
  5. final Class<?>[] array = getSecurityManager().getClassContext();
  6. final Stack<Class<?>> classes = new Stack<>();
  7. classes.ensureCapacity(array.length);
  8. for (final Class<?> clazz : array) {
  9. classes.push(clazz);
  10. }
  11. return classes;
  12. }
  13. // slower version using getCallerClass where we cannot use a SecurityManager
  14. final Stack<Class<?>> classes = new Stack<>();
  15. Class<?> clazz;
  16. for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
  17. classes.push(clazz);
  18. }
  19. return classes;
  20. }

代码示例来源:origin: org.apache.logging.log4j/log4j-api

  1. @Test
  2. public void testGetCurrentStackTrace() throws Exception {
  3. final Stack<Class<?>> classes = StackLocatorUtil.getCurrentStackTrace();
  4. final Stack<Class<?>> reversed = new Stack<>();
  5. reversed.ensureCapacity(classes.size());
  6. while (!classes.empty()) {
  7. reversed.push(classes.pop());
  8. }
  9. while (reversed.peek() != StackLocatorUtil.class) {
  10. reversed.pop();
  11. }
  12. reversed.pop(); // ReflectionUtil
  13. assertSame(StackLocatorUtilTest.class, reversed.pop());
  14. }

代码示例来源:origin: commons-pool/commons-pool

  1. if(null == stack) {
  2. stack = new Stack<V>();
  3. stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
  4. _pools.put(key,stack);

代码示例来源:origin: commons-pool/commons-pool

  1. if(null == stack) {
  2. stack = new Stack<V>();
  3. stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
  4. _pools.put(key,stack);

代码示例来源:origin: commons-pool/commons-pool

  1. if(null == stack) {
  2. stack = new Stack<V>();
  3. stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
  4. _pools.put(key,stack);

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.pool

  1. /**
  2. * Create a new <tt>SimpleObjectPool</tt> using
  3. * the specified <i>factory</i> to create new instances,
  4. * capping the number of "sleeping" instances to <i>max</i>,
  5. * and initially allocating a container capable of containing
  6. * at least <i>init</i> instances.
  7. *
  8. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  9. * @param maxIdle cap on the number of "sleeping" instances in the pool
  10. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  11. * it does not cause the pool to be pre-populated.)
  12. */
  13. public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
  14. _factory = factory;
  15. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  16. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  17. _pool = new Stack();
  18. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  19. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-pool

  1. /**
  2. * Create a new <tt>SimpleObjectPool</tt> using
  3. * the specified <i>factory</i> to create new instances,
  4. * capping the number of "sleeping" instances to <i>max</i>,
  5. * and initially allocating a container capable of containing
  6. * at least <i>init</i> instances.
  7. *
  8. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  9. * @param maxIdle cap on the number of "sleeping" instances in the pool
  10. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  11. * it does not cause the pool to be pre-populated.)
  12. */
  13. public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
  14. _factory = factory;
  15. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  16. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  17. _pool = new Stack();
  18. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  19. }

代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7

  1. /**
  2. * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances,
  3. * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container
  4. * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated.
  5. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying
  6. * container, which can increase beyond this value if <code>maxIdle &gt; initIdleCapacity.</code></p>
  7. *
  8. * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using
  9. * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code>
  10. *
  11. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  12. * @param maxIdle cap on the number of "sleeping" instances in the pool
  13. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  14. * it does not cause the pool to be pre-populated.)
  15. */
  16. public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
  17. _factory = factory;
  18. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  19. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  20. _pool = new Stack();
  21. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  22. }

代码示例来源:origin: org.apache.commons/pool

  1. /**
  2. * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances,
  3. * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container
  4. * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated.
  5. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying
  6. * container, which can increase beyond this value if <code>maxIdle &gt; initIdleCapacity.</code></p>
  7. *
  8. * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using
  9. * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code>
  10. *
  11. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  12. * @param maxIdle cap on the number of "sleeping" instances in the pool
  13. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  14. * it does not cause the pool to be pre-populated.)
  15. */
  16. public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
  17. _factory = factory;
  18. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  19. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  20. _pool = new Stack<T>();
  21. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  22. }

代码示例来源:origin: org.apache.openjpa/openjpa-all

  1. /**
  2. * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances,
  3. * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container
  4. * capable of containing at least <code>initIdleCapacity</code> instances. The pool is not pre-populated.
  5. * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying
  6. * container, which can increase beyond this value if <code>maxIdle &gt; initIdleCapacity.</code></p>
  7. *
  8. * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using
  9. * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code>
  10. *
  11. * @param factory the {@link PoolableObjectFactory} used to populate the pool
  12. * @param maxIdle cap on the number of "sleeping" instances in the pool
  13. * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
  14. * it does not cause the pool to be pre-populated.)
  15. */
  16. public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
  17. _factory = factory;
  18. _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
  19. int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
  20. _pool = new Stack<T>();
  21. _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
  22. }

代码示例来源:origin: usethesource/capsule

  1. public BottomUpImmutableNodeTransformer(final SN srcRootNode,
  2. final BiFunction<SN, DN[], DN> nodeMapper, final IntFunction<DN[]> arrayConstructor) {
  3. mappedNodesStack.ensureCapacity(128);
  4. this.nodeMapper = nodeMapper;
  5. this.arrayConstructor = arrayConstructor;
  6. this.mutator = new AtomicReference<>(Thread.currentThread());
  7. this.dstRootNode = null; // nodeMapper.apply(srcRootNode, mutator);
  8. final ListIterator<SN> srcIterator = (ListIterator<SN>) srcRootNode.nodeArray().iterator();
  9. if (srcIterator.hasNext()) {
  10. // final ListIterator<DN> dstIterator = (ListIterator<DN>) dstRootNode.nodeArray().iterator();
  11. //
  12. // pushOnStack(srcIterator, dstIterator);
  13. pushOnStack(srcRootNode);
  14. } else {
  15. // TODO: Transform Leaf Node
  16. mappedNodesStack.push(nodeMapper.apply(srcRootNode, (DN[]) EMPTY_DN_ARRAY));
  17. }
  18. }

代码示例来源:origin: io.usethesource/capsule

  1. public BottomUpImmutableNodeTransformer(final SN srcRootNode,
  2. final BiFunction<SN, DN[], DN> nodeMapper) {
  3. mappedNodesStack.ensureCapacity(128);
  4. this.nodeMapper = nodeMapper;
  5. this.mutator = new AtomicReference<>(Thread.currentThread());
  6. this.dstRootNode = null; // nodeMapper.apply(srcRootNode, mutator);
  7. final ListIterator<SN> srcIterator = (ListIterator<SN>) srcRootNode.nodeArray().iterator();
  8. if (srcIterator.hasNext()) {
  9. // final ListIterator<DN> dstIterator = (ListIterator<DN>) dstRootNode.nodeArray().iterator();
  10. //
  11. // pushOnStack(srcIterator, dstIterator);
  12. pushOnStack(srcRootNode);
  13. } else {
  14. // TODO: Transform Leaf Node
  15. mappedNodesStack.push(nodeMapper.apply(srcRootNode, (DN[]) EMPTY_DN_ARRAY));
  16. }
  17. }

代码示例来源:origin: org.apache.logging.log4j/log4j2-stacktrace-origins

  1. public static Stack<Class<?>> getCurrentStackTrace() {
  2. // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
  3. if (SECURITY_MANAGER != null) {
  4. final Class<?>[] array = SECURITY_MANAGER.getClassContext();
  5. final Stack<Class<?>> classes = new Stack<Class<?>>();
  6. classes.ensureCapacity(array.length);
  7. for (final Class<?> clazz : array) {
  8. classes.push(clazz);
  9. }
  10. return classes;
  11. }
  12. // slower version using getCallerClass where we cannot use a SecurityManager
  13. if (supportsFastReflection()) {
  14. final Stack<Class<?>> classes = new Stack<Class<?>>();
  15. Class<?> clazz;
  16. for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
  17. classes.push(clazz);
  18. }
  19. return classes;
  20. }
  21. return new Stack<Class<?>>();
  22. }

代码示例来源:origin: lemire/javaewah

  1. /**
  2. * Instantiates a new reverse EWAH iterator.
  3. *
  4. * @param buffer the buffer
  5. */
  6. public ReverseEWAHIterator(final Buffer buffer) {
  7. this.pointer = 0;
  8. this.rlw = new RunningLengthWord(buffer, this.pointer);
  9. this.positions = new Stack<Integer>();
  10. this.positions.ensureCapacity(buffer.sizeInWords());
  11. while(this.pointer < buffer.sizeInWords()) {
  12. this.positions.push(this.pointer);
  13. this.rlw.position = this.pointer;
  14. this.pointer += this.rlw.getNumberOfLiteralWords() + 1;
  15. }
  16. }

代码示例来源:origin: com.googlecode.javaewah/JavaEWAH

  1. /**
  2. * Instantiates a new reverse EWAH iterator.
  3. *
  4. * @param buffer the buffer
  5. */
  6. public ReverseEWAHIterator(final Buffer buffer) {
  7. this.pointer = 0;
  8. this.rlw = new RunningLengthWord(buffer, this.pointer);
  9. this.positions = new Stack<Integer>();
  10. this.positions.ensureCapacity(buffer.sizeInWords());
  11. while(this.pointer < buffer.sizeInWords()) {
  12. this.positions.push(this.pointer);
  13. this.rlw.position = this.pointer;
  14. this.pointer += this.rlw.getNumberOfLiteralWords() + 1;
  15. }
  16. }

代码示例来源:origin: com.googlecode.javaewah/JavaEWAH

  1. /**
  2. * Instantiates a new reverse EWAH iterator.
  3. *
  4. * @param buffer the buffer
  5. */
  6. public ReverseEWAHIterator32(final Buffer32 buffer) {
  7. this.pointer = 0;
  8. this.rlw = new RunningLengthWord32(buffer, this.pointer);
  9. this.positions = new Stack<Integer>();
  10. this.positions.ensureCapacity(buffer.sizeInWords());
  11. while(this.pointer < buffer.sizeInWords()) {
  12. this.positions.push(this.pointer);
  13. this.rlw.position = this.pointer;
  14. this.pointer += this.rlw.getNumberOfLiteralWords() + 1;
  15. }
  16. }

代码示例来源:origin: lemire/javaewah

  1. /**
  2. * Instantiates a new reverse EWAH iterator.
  3. *
  4. * @param buffer the buffer
  5. */
  6. public ReverseEWAHIterator32(final Buffer32 buffer) {
  7. this.pointer = 0;
  8. this.rlw = new RunningLengthWord32(buffer, this.pointer);
  9. this.positions = new Stack<Integer>();
  10. this.positions.ensureCapacity(buffer.sizeInWords());
  11. while(this.pointer < buffer.sizeInWords()) {
  12. this.positions.push(this.pointer);
  13. this.rlw.position = this.pointer;
  14. this.pointer += this.rlw.getNumberOfLiteralWords() + 1;
  15. }
  16. }

代码示例来源:origin: ops4j/org.ops4j.pax.logging

  1. @PerformanceSensitive
  2. public Stack<Class<?>> getCurrentStackTrace() {
  3. // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
  4. if (getSecurityManager() != null) {
  5. final Class<?>[] array = getSecurityManager().getClassContext();
  6. final Stack<Class<?>> classes = new Stack<>();
  7. classes.ensureCapacity(array.length);
  8. for (final Class<?> clazz : array) {
  9. classes.push(clazz);
  10. }
  11. return classes;
  12. }
  13. // slower version using getCallerClass where we cannot use a SecurityManager
  14. final Stack<Class<?>> classes = new Stack<>();
  15. Class<?> clazz;
  16. for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
  17. classes.push(clazz);
  18. }
  19. return classes;
  20. }

代码示例来源:origin: broadgsa/gatk-protected

  1. stack.ensureCapacity(end - start + 1);
  2. stack.push(new Pair<>(prefix,start));
  3. while (!stack.isEmpty()) {

相关文章