Creates a short buffer based on a newly allocated short array.

@param capacity the capacity of the new buffer.
@return the created short buffer.
@throws IllegalArgumentException if {@code capacity} is less than zero.
482194
public static ShortBuffer allocate (int capacity) {
        if (capacity < 0) {
            throw new IllegalArgumentException();
        }
        ByteBuffer bb = ByteBuffer.allocateDirect(capacity * 2);
        bb.order(ByteOrder.nativeOrder());
        return bb.asShortBuffer();
    }
14315
public char[] allocSmallCBuffer(int minSize)
    {
        if (mCurrRecycler != null) {
            char[] result = mCurrRecycler.getSmallCBuffer(minSize);
            if (result != null) {
                return result;
            }
        }
        // Nope; no recycler, or it has no suitable buffers, let's create:
        return new char[minSize];
    }
771945
public void addUnsignedByte( short value ) {
        if ( 1 + length < capacity ) {
            DynamicByteBufferHelper.unsignedByteTo( buffer, length, value );
        } else {
            buffer = DynamicByteBufferHelper.grow( buffer, buffer.length * 2 + 1 );
            capacity = buffer.length;

            DynamicByteBufferHelper.unsignedByteTo( buffer, length, value );
        }

        length += 1;

    }
790355
public WrappedByteBuffer compact() {
        int remaining = remaining();
        int capacity = capacity();

        if (capacity == 0) {
            return this;
        }

        if (remaining <= capacity >>> 2 && capacity > _minimumCapacity) {
            int newCapacity = capacity;
            int minCapacity = max(_minimumCapacity, remaining << 1);
            for (;;) {
                if (newCapacity >>> 1 < minCapacity) {
                    break;
                }
                newCapacity >>>= 1;
            }

            newCapacity = max(minCapacity, newCapacity);

            if (newCapacity == capacity) {
                if (_buf.remaining() == 0) {
                    _buf.position(0);
                    _buf.limit(_buf.capacity());                    
                }
                else {
                    java.nio.ByteBuffer dup = _buf.duplicate();
                    _buf.position(0);
                    _buf.limit(_buf.capacity());
                    _buf.put(dup);
                }
                return this;
            }

            // Shrink and compact:
            // // Save the state.
            ByteOrder bo = order();

            // // Sanity check.
            if (remaining > newCapacity) {
                throw new IllegalStateException("The amount of the remaining bytes is greater than " + "the new capacity.");
            }

            // // Reallocate.
            java.nio.ByteBuffer oldBuf = _buf;
            java.nio.ByteBuffer newBuf = java.nio.ByteBuffer.allocate(newCapacity);
            newBuf.put(oldBuf);
            _buf = newBuf;

            // // Restore the state.
            _buf.order(bo);
        } else {
            _buf.compact();
        }

        return this;
    }
894516
public StrBuilder ensureCapacity(final int capacity) {
        if (capacity > buffer.length) {
            final char[] old = buffer;
            buffer = new char[capacity * 2];
            System.arraycopy(old, 0, buffer, 0, size);
        }
        return this;
    }
79121
public static <T> BlockingQueue<T> newBlockingQueue(int capacity, boolean isLinked) {
		BlockingQueue<T> queue;
		if (isLinked) {
			queue = new LinkedBlockingDeque<>(capacity);
		} else {
			queue = new ArrayBlockingQueue<>(capacity);
		}
		return queue;
	}
1027801
public void setCapacity(int capacity) {
        if (capacity < 0) {
            throw new IllegalArgumentException();
        }
        this.capacity = Math.min(capacity, MAXIMUM_CAPACITY);

        evictionLock.lock();
        try {
            drainBuffers(AMORTIZED_DRAIN_THRESHOLD);
            evict();
        } finally {
            evictionLock.unlock();
        }
        notifyListener();
    }
1351528
static final byte[] resizeBuffer(final byte[] buf, final int newsize) {
		if (buf.length == newsize)
			return buf;
		final byte[] newbuf = new byte[newsize];
		System.arraycopy(buf, 0, newbuf, 0, Math.min(buf.length, newbuf.length));
		return newbuf;
	}
444277
@Override
	// @NotThreadSafe
	protected void ensureCapacity(long capacity) throws IOException {
		long curCapacity = pbuffer.capacity();
		if(curCapacity<capacity) expandCapacity(curCapacity, capacity);
	}
680477
public void add(byte b) throws BufferIsFullException {
        if (isFull()) {
            throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")");
        }

        // buffer is not full
        this.buffer[this.currentWritePosition] = b;
        this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length;
        this.currentBufferSize += 1;
    }
734173
public byte[] getFullBBuffer(int minSize)
    {
        byte[] result = null;
        if (mFullBBuffer != null && mFullBBuffer.length >= minSize) {
            result = mFullBBuffer;
            mFullBBuffer = null;
        }
//System.err.println("DEBUG: Alloc BFull: "+result);
        return result;
    }
405062
@Nonnull
    public BufferedImage createBufferedImage(final int imageWidth, final int imageHeight) {
        return new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
    }
587626
private void initialize(int bytes) {
		int capacity = bytes / ELEMENT_LENGTH_IN_BYTES;

		Preconditions.checkArgument(capacity > 0, "Requested array with zero capacity");
		Preconditions.checkArgument(capacity <= MAX_ARRAY_SIZE, "Requested capacity exceeds limit of " + MAX_ARRAY_SIZE);

		data = new double[capacity];
	}
756520
public Buffer capacity(long capacity) {
    if (capacity > maxCapacity) {
      throw new IllegalArgumentException("capacity cannot be greater than maximum capacity");
    } else if (capacity < this.capacity) {
      throw new IllegalArgumentException("capacity cannot be decreased");
    } else if (capacity != this.capacity) {
      // It's possible that the bytes could already meet the requirements of the capacity.
      if (offset(capacity) > bytes.size()) {
        bytes.resize(Memory.Util.toPow2(offset(capacity)));
      }
      this.capacity = capacity;
    }
    return this;
  }
465609
@SafeVarargs
    public static <T> ArrayList<T> getArrayList(int capacity, T... values) {
        return new ArrayList<T>(capacity) {{addAll(Arrays.asList(values));}};
    }
1354804
public <T extends CacheSpec<K, V>> T initialCapacity(int initialCapacity) {
      checkArgument(initialCapacity > 0, "Capacity must be > 0");
      this.initialCapacity = initialCapacity;
      return Cast.as(this);
   }
1016100
public static IntBuffer allocate (int capacity) {
        if (capacity < 0) {
            throw new IllegalArgumentException();
        }
        ByteBuffer bb = ByteBuffer.allocateDirect(capacity * 4);
        bb.order(ByteOrder.nativeOrder());
        return bb.asIntBuffer();
    }