public int popLast() { assertNotEmpty(); int index = index(--size); int value = elements[index]; return value; }
/** * Increase the capacity of the bag. * * @param newCapacity * new capacity to grow to * * @throws ArrayIndexOutOfBoundsException if new capacity is smaller than old */ private void grow(int newCapacity) throws ArrayIndexOutOfBoundsException { int[] newElements = new int[newCapacity]; for (int i = 0; i < size; i++) newElements[i] = get(i); elements = newElements; beginIndex = 0; }
/** * 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; }
/** * Returns the element at the specified position in Bag. * * @param index * index of the element to return * * @return the element at the specified position in bag * * @throws ArrayIndexOutOfBoundsException */ public int get(int index) throws ArrayIndexOutOfBoundsException { return elements[index(index)]; }
private void free(int entityId) { limbo.add(entityId); recycled.unsafeSet(entityId); } }
public int popFirst() { assertNotEmpty(); int value = elements[beginIndex]; beginIndex = (beginIndex + 1) % elements.length; size--; return 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 >= elements.length) { grow(index); } }
/** * <p>If all entties have been deleted, resets the entity cache - with next entity * entity receiving id <code>0</code>. There mustn't be any active entities in * the world for this method to work. This method does nothing if it fails.</p> * * <p>For the reset to take effect, a new {@link World#process()} must initiate.</p> * * @return true if entity id was successfully reset. * */ public boolean reset() { int count = world.getAspectSubscriptionManager() .get(all()) .getActiveEntityIds() .cardinality(); if (count > 0) return false; limbo.clear(); recycled.clear(); entities.clear(); nextId = 0; return true; }
/** * Returns the element at the specified position in Bag. * * @param index * index of the element to return * * @return the element at the specified position in bag * * @throws ArrayIndexOutOfBoundsException */ public int get(int index) throws ArrayIndexOutOfBoundsException { return elements[index(index)]; }
private void free(int entityId) { limbo.add(entityId); recycled.unsafeSet(entityId); } }
public int popFirst() { assertNotEmpty(); int value = elements[beginIndex]; beginIndex = (beginIndex + 1) % elements.length; size--; return 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 >= elements.length) { grow(index); } }
/** * <p>If all entties have been deleted, resets the entity cache - with next entity * entity receiving id <code>0</code>. There mustn't be any active entities in * the world for this method to work. This method does nothing if it fails.</p> * * <p>For the reset to take effect, a new {@link World#process()} must initiate.</p> * * @return true if entity id was successfully reset. * */ public boolean reset() { int count = world.getAspectSubscriptionManager() .get(all()) .getActiveEntityIds() .cardinality(); if (count > 0) return false; limbo.clear(); recycled.clear(); entities.clear(); nextId = 0; return true; }
/** * 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; }
public int popLast() { assertNotEmpty(); int index = index(--size); int value = elements[index]; return value; }
/** * Check if bag contains this element. * * @param e * element to check * * @return {@code true} if the bag contains this element */ public boolean contains(int e) { for(int i = 0; size > i; i++) { if(e == elements[index(i)]) { return true; } } return false; }
/** * Increase the capacity of the bag. * * @param newCapacity * new capacity to grow to * * @throws ArrayIndexOutOfBoundsException if new capacity is smaller than old */ private void grow(int newCapacity) throws ArrayIndexOutOfBoundsException { int[] newElements = new int[newCapacity]; for (int i = 0; i < size; i++) newElements[i] = get(i); elements = newElements; beginIndex = 0; }