/** * Ensures that this array list can contain the given number of entries without resizing. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity(final int capacity) { if (wrapped) a = ObjectArrays.ensureCapacity(a, capacity, size); else { if (capacity > a.length) { final Object t[] = new Object[capacity]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } } if (ASSERTS) assert size <= a.length; }
/** * Ensures that an array can contain the given number of entries. * * <p> * If you cannot foresee whether this array will need again to be enlarged, you * should probably use {@code grow()} instead. * * @param array * an array. * @param length * the new minimum length for this array. * @return {@code array}, if it contains {@code length} entries or more; * otherwise, an array with {@code length} entries whose first * {@code array.length} entries are the same as those of {@code array}. */ public static <K> K[] ensureCapacity(final K[] array, final int length) { return ensureCapacity(array, length, array.length); } /**
/** Ensures that this array list can contain the given number of entries without resizing. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity( final int capacity ) { if ( wrapped ) a = ObjectArrays.ensureCapacity( a, capacity, size ); else { if ( capacity > a.length ) { final Object t[] = new Object[ capacity ]; System.arraycopy( a, 0, t, 0, size ); a = (K[])t; } } if ( ASSERTS ) assert size <= a.length; } /** Grows this array list, ensuring that it can contain the given number of entries without resizing,
/** * Ensures that this array list can contain the given number of entries without * resizing. * * @param capacity * the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity(final int capacity) { if (capacity <= a.length || a == ObjectArrays.DEFAULT_EMPTY_ARRAY) return; if (wrapped) a = ObjectArrays.ensureCapacity(a, capacity, size); else { if (capacity > a.length) { final Object t[] = new Object[capacity]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } } assert size <= a.length; } /**
/** * Ensures that this array list can contain the given number of entries without * resizing. * * @param capacity * the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") public void ensureCapacity(final int capacity) { if (capacity <= a.length || a == ObjectArrays.DEFAULT_EMPTY_ARRAY) return; if (wrapped) a = ObjectArrays.ensureCapacity(a, capacity, size); else { if (capacity > a.length) { final Object t[] = new Object[capacity]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } } assert size <= a.length; } /**
/** Adds the given number of nodes, numbering them from {@link #numNodes()} onwards. The new nodes have no successors. * * @param numNewNodes the number of new nodes. */ public void addNodes(final int numNewNodes) { if (numNewNodes != 0) { modificationCount++; final int newN = n + numNewNodes; successors = ObjectArrays.ensureCapacity(successors, newN, n); while(n < newN) successors[n++] = new IntArrayList(); } }
/** * Sets the length of the given array. * * @param array * an array. * @param length * the new length for the array. * @return {@code array}, if it contains exactly {@code length} entries; * otherwise, if it contains <em>more</em> than {@code length} entries, * an array with {@code length} entries whose entries are the same as * the first {@code length} entries of {@code array}; otherwise, an * array with {@code length} entries whose first {@code array.length} * entries are the same as those of {@code array}. * */ public static <K> K[] setLength(final K[] array, final int length) { if (length == array.length) return array; if (length < array.length) return trim(array, length); return ensureCapacity(array, length); } /**
/** * Merges a new collection in this one, by rebuilding the gzFile array and * appending the other object one, concatenating the descriptors while * rebuilding all. * <p> * It is supposed that the passed object contains no duplicates for the * local collection. */ public void merge( TRECDocumentCollection other ) { int oldLength = this.file.length; this.file = ObjectArrays.ensureCapacity( this.file, this.file.length + other.file.length ); System.arraycopy( other.file, 0, this.file, oldLength, other.file.length ); ObjectIterator<TRECDocumentDescriptor> iter = other.descriptors.iterator(); while ( iter.hasNext() ) { final TRECDocumentDescriptor tdd = (TRECDocumentDescriptor)iter.next().clone(); tdd.fileIndex += oldLength; this.descriptors.add( tdd ); } }
/** * Merges a new collection in this one, by rebuilding the gzFile array and * appending the other object one, concatenating the descriptors while * rebuilding all. * <p> * It is supposed that the passed object contains no duplicates for the * local collection. */ public void merge( TRECDocumentCollection other ) { int oldLength = this.file.length; this.file = ObjectArrays.ensureCapacity( this.file, this.file.length + other.file.length ); System.arraycopy( other.file, 0, this.file, oldLength, other.file.length ); ObjectIterator<TRECDocumentDescriptor> iter = other.descriptors.iterator(); while ( iter.hasNext() ) { final TRECDocumentDescriptor tdd = (TRECDocumentDescriptor)iter.next().clone(); tdd.fileIndex += oldLength; this.descriptors.add( tdd ); } }
/** * Merges a new collection in this one, by rebuilding the gzFile array and * appending the other object one, concatenating the descriptors while * rebuilding all. * <p> * It is supposed that the passed object contains no duplicates for the * local collection. */ public void merge( TRECDocumentCollection other ) { int oldLength = this.file.length; this.file = ObjectArrays.ensureCapacity( this.file, this.file.length + other.file.length ); System.arraycopy( other.file, 0, this.file, oldLength, other.file.length ); ObjectIterator<TRECDocumentDescriptor> iter = other.descriptors.iterator(); while ( iter.hasNext() ) { final TRECDocumentDescriptor tdd = (TRECDocumentDescriptor)iter.next().clone(); tdd.fileIndex += oldLength; this.descriptors.add( tdd ); } }
/** * Merges a new collection in this one, by rebuilding the gzFile array and * appending the other object one, concatenating the descriptors while * rebuilding all. * <p> * It is supposed that the passed object contains no duplicates for the * local collection. */ public void merge( TRECDocumentCollection other ) { int oldLength = this.file.length; this.file = ObjectArrays.ensureCapacity( this.file, this.file.length + other.file.length ); System.arraycopy( other.file, 0, this.file, oldLength, other.file.length ); ObjectIterator<TRECDocumentDescriptor> iter = other.descriptors.iterator(); while ( iter.hasNext() ) { final TRECDocumentDescriptor tdd = (TRECDocumentDescriptor)iter.next().clone(); tdd.fileIndex += oldLength; this.descriptors.add( tdd ); } }