/** * Increase the capacity of the bag. * <p> * Capacity will increase by (3/2)*capacity + 1. * </p> */ private void grow() { int newCapacity = (data.length * 7) / 4 + 1; grow(newCapacity); }
/** * Increase the capacity of the bag. * <p> * Capacity will increase by (3/2)*capacity + 1. * </p> */ private void grow() { int newCapacity = (data.length * 7) / 4 + 1; grow(newCapacity); }
/** * 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(short value) { // is size greater than capacity increase capacity if (size == data.length) { grow(); } 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(short value) { // is size greater than capacity increase capacity if (size == data.length) { grow(); } 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, short value) { if(index >= data.length) { grow((index * 7) / 4 + 1); } size = Math.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, short value) { if(index >= data.length) { grow((index * 7) / 4 + 1); } size = Math.max(size, index + 1); data[index] = value; }