new entitas.utils.Bag(capacity)
Constructs an empty Bag with the specified initial capacity.
Constructs an empty Bag with an initial capacity of 64.
Name | Type | Description |
---|---|---|
capacity |
the initial capacity of Bag |
Methods
-
add(e)
-
Adds the specified element to the end of this bag. if needed also
increases the capacity of the bag.Name Type Description e
element to be added to this list
-
addAll(items)
-
Add all items into this bag.
Name Type Description items
-
clear()
-
Removes all of the elements from this bag. The bag will be empty after
this call returns. -
contains(e){boolean}
-
Check if bag contains this element.
Name Type Description e
Returns:
Type Description boolean -
get(index){Object}
-
Returns the element at the specified position in Bag.
Name Type Description index
index of the element to return
Returns:
Type Description Object the element at the specified position in bag -
getCapacity(){number}
-
Returns the number of elements the bag can hold without growing.
Returns:
Type Description number the number of elements the bag can hold without growing. -
isEmpty(){boolean}
-
Returns true if this list contains no elements.
Returns:
Type Description boolean true if this list contains no elements -
isIndexWithinBounds(index){boolean}
-
Checks if the internal storage supports this index.
Name Type Description index
Returns:
Type Description boolean -
remove(e){boolean}
-
Removes the first occurrence of the specified element from this Bag, if
it is present. If the Bag does not contain the element, it is unchanged.
does this by overwriting it was last element then removing last elementName Type Description e
element to be removed from this list, if present
Returns:
Type Description boolean true if this list contained the specified element -
removeAll(bag){boolean}
-
Removes from this Bag all of its elements that are contained in the
specified Bag.Name Type Description bag
Bag containing elements to be removed from this Bag
Returns:
Type Description boolean true if this Bag changed as a result of the call -
removeAt(index){Object}
-
Removes the element at the specified position in this Bag. does this by
overwriting it was last element then removing last elementName Type Description index
the index of element to be removed
Returns:
Type Description Object element that was removed from the Bag -
removeLast(){Object}
-
Remove and return the last object in the bag.
Returns:
Type Description Object the last object in the bag, null if empty. -
safeGet(index){Object}
-
Returns the element at the specified position in Bag. This method
ensures that the bag grows if the requested index is outside the bounds
of the current backing array.Name Type Description index
index of the element to return
Returns:
Type Description Object the element at the specified position in bag -
set(index, e)
-
Set element at specified index in the bag.
Name Type Description index
position of element
e
the element
-
size(){number}
-
Returns the number of elements in this bag.
Returns:
Type Description number the number of elements in this bag