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

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

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

Stack.ensureCapacity介绍

暂无

代码示例

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

/**
 * <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 &gt; 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);
}

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

@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;
}

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

@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());
}

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

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

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

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

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

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

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

/**
 * 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);
}

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

/**
 * 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);
}

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

/**
 * <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 &gt; 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);
}

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

/**
 * <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 &gt; 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);
}

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

/**
 * <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 &gt; 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);
}

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

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));
  }
 }

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

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));
  }
 }

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

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<?>>();
}

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

/**
 * 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;
  }
}

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

/**
 * 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;
  }
}

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

/**
 * 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;
  }
}

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

/**
 * 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;
  }
}

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

@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;
}

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

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

相关文章