/** * Check if an item, if added at the given item will fit into the bag. * <p> * If not, the bag capacity will be increased to hold an item at the index. * </p> * * @param index * index to check */ public void ensureCapacity(int index) { if(index >= data.length) { grow(index + 1); } }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param value * element to be added to this list */ public void add(int value) { // is size greater than capacity increase capacity if (size == data.length) grow(2 * data.length); data[size++] = value; }
/** * Check if an item, if added at the given item will fit into the bag. * <p> * If not, the bag capacity will be increased to hold an item at the index. * </p> * * @param index * index to check */ public void ensureCapacity(int index) { if(index >= data.length) { grow(index + 1); } }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param value * element to be added to this list */ public void add(int value) { // is size greater than capacity increase capacity if (size == data.length) grow(2 * data.length); data[size++] = value; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param value * the element */ public void set(int index, int value) { if(index >= data.length) { grow(max((2 * data.length), index + 1)); } size = max(size, index + 1); data[index] = value; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param value * the element */ public void set(int index, int value) { if(index >= data.length) { grow(max((2 * data.length), index + 1)); } size = max(size, index + 1); data[index] = value; }