/** * 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 >= elements.length) { grow(index); } }
/** * 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 >= elements.length) { grow(index); } }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param e * element to be added to this list */ public void add(int e) { if (size == elements.length) grow((elements.length * 7) / 4 + 1); elements[index(size++)] = e; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param e * the element */ public void set(int index, int e) { if(index >= elements.length) { grow((index * 7) / 4 + 1); } size = Math.max(size, index + 1); elements[index(index)] = e; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param e * the element */ public void set(int index, int e) { if(index >= elements.length) { grow((index * 7) / 4 + 1); } size = Math.max(size, index + 1); elements[index(index)] = e; }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param e * element to be added to this list */ public void add(int e) { if (size == elements.length) grow((elements.length * 7) / 4 + 1); elements[index(size++)] = e; }