/** Constructs an instance with the specified capacity. * * @param capacity the initial capacity to use. * @throws NegativeArraySizeException if the specified {@code capacity} is negative. * @see #capacity() */ public StringBuilder (int capacity) { if (capacity < 0) { throw new NegativeArraySizeException(); } chars = new char[capacity]; }
/** Constructs an instance with the specified capacity. * * @param capacity the initial capacity to use. * @throws NegativeArraySizeException if the specified {@code capacity} is negative. * @see #capacity() */ public StringBuilder (int capacity) { if (capacity < 0) { throw new NegativeArraySizeException(); } chars = new char[capacity]; }
public void setBufferSize(final int size) { if (size < 0) { throw new NegativeArraySizeException("size"); } synchronized (buffer) { bufferSize = (size < 1) ? 1 : size; buffer.notifyAll(); } }
/** * Sets the number of messages allowed in the event buffer * before the calling thread is blocked (if blocking is true) * or until messages are summarized and discarded. Changing * the size will not affect messages already in the buffer. * * @param size buffer size, must be positive. */ public void setBufferSize(final int size) { // // log4j 1.2 would throw exception if size was negative // and deadlock if size was zero. // if (size < 0) { throw new java.lang.NegativeArraySizeException("size"); } synchronized (buffer) { // // don't let size be zero. // bufferSize = (size < 1) ? 1 : size; buffer.notifyAll(); } }
public IcedBitSet(byte[] v, int nbits, int offset) { if(nbits < 0) throw new NegativeArraySizeException("nbits < 0: " + nbits); if(offset < 0) throw new IndexOutOfBoundsException("offset < 0: " + offset); assert (nbits >> 3) <= v.length; _val = v; _nbits = nbits; _offset = offset; } public IcedBitSet(int nbits) { this(nbits, 0); }
public IcedBitSet(int nbits, int offset) { if(nbits < 0) throw new NegativeArraySizeException("nbits < 0: " + nbits); if(offset < 0) throw new IndexOutOfBoundsException("offset < 0: " + offset); _nbits = nbits; _offset = offset; _val = new byte[((nbits-1) >> 3) + 1]; }
AbstractStringBuilder(int capacity) { if (capacity < 0) { throw new NegativeArraySizeException(Integer.toString(capacity)); } value = new char[capacity]; }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code false}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static boolean[] copyOf(boolean[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code 0L}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static long[] copyOf(long[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code '\\u0000'}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static char[] copyOf(char[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code (short) 0}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static short[] copyOf(short[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code (byte) 0}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static byte[] copyOf(byte[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code 0.0d}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static double[] copyOf(double[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code 0}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static int[] copyOf(int[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code 0.0f}. * * @param original the original array * @param newLength the length of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @since 1.6 */ public static float[] copyOf(float[] original, int newLength) { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Creates a bit set whose initial size is the range {@code 0} through * {@code size-1}. All bits are initially {@code false}. * @param size the initial size of the bit set (in bits). * @throws NegativeArraySizeException if the specified initial size is negative */ public FixedSizeBitSet(int size) { if(size < 0) // nbits can't be negative; size 0 is OK throw new NegativeArraySizeException("size < 0: " + size); this.size=size; words=new long[wordIndex(size - 1) + 1]; }
/** * Copies {@code newLength} elements from {@code original} into a new array. * If {@code newLength} is greater than {@code original.length}, the result is padded * with the value {@code null}. * * @param original the original array * @param newLength the length of the new array * @param newType the class of the new array * @return the new array * @throws NegativeArraySizeException if {@code newLength < 0} * @throws NullPointerException if {@code original == null} * @throws ArrayStoreException if a value in {@code original} is incompatible with T * @since 1.6 */ public static <T, U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) { // We use the null pointer check in copyOfRange for exception priority compatibility. if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength, newType); }
/** * Creates a new {@code BitSet} with size equal to {@code bitCount}, rounded up to * a multiple of 64. * * @throws NegativeArraySizeException if {@code bitCount < 0}. */ public BitSet(int bitCount) { if (bitCount < 0) { throw new NegativeArraySizeException(Integer.toString(bitCount)); } this.bits = arrayForBits(bitCount); this.longCount = 0; }
protected static byte[] copyOf(byte[] original, int newLength) throws NegativeArraySizeException { if (newLength < 0) { throw new NegativeArraySizeException(Integer.toString(newLength)); } return copyOfRange(original, 0, newLength); }
/** * Read byte-array written with a WritableableUtils.vint prefix. * @param in Input to read from. * @return byte array read off <code>in</code> * @throws IOException e */ public static byte [] readByteArray(final DataInput in) throws IOException { int len = WritableUtils.readVInt(in); if (len < 0) { throw new NegativeArraySizeException(Integer.toString(len)); } byte [] result = new byte[len]; in.readFully(result, 0, len); return result; }