コード例 #1
0
 /**
  * Grow the internal array as needed to accommodate the specified number of elements. The size of
  * the array bytes on each resize unless capacity requires more than twice the current capacity.
  */
 public void ensureCapacity(int capacity) {
   int oldCapacity = capacity();
   if (capacity > oldCapacity) {
     int newCap = Math.max(oldCapacity << 1, capacity);
     _data.resize(newCap);
   }
 }
コード例 #2
0
 /**
  * Flushes the internal state of the list, setting the capacity of the empty list to
  * <tt>capacity</tt>.
  */
 public void clear(int capacity) {
   _data.resize(capacity);
   _data.clear();
   _pos = 0;
 }
コード例 #3
0
 /** Sheds any excess capacity above and beyond the current size of the list. */
 public void trimToSize() {
   if (capacity() > size()) {
     _data.resize(size());
   }
 }