Class BagArray
java.lang.Object
us.irdev.bedrock.bag.Bag
us.irdev.bedrock.bag.BagArray
- All Implemented Interfaces:
Iterable<Object>
,Selectable<BagArray>
A collection of text-based values stored in a zero-based indexed array.
Note: the BagArray class, from a memory allocation standpoint, is not designed to work efficiently with dynamic storage of very large numbers of elements (more than 1,000s). It will work, but we have not chosen to focus on this as a potential use-case.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds the element at the end of the underlying array store.static BagArray
dequeue()
getAndRemove
(int index) getBagArray
(int index) Retrieve an indexed element and return it as a BagArray.getBagObject
(int index) Retrieve an indexed element and return it as a BagObject.getBoolean
(int index) Retrieve an indexed element and return it as a Boolean.int
getCount()
Return the number of elements stored in the BagArray.getDouble
(int index) Retrieve an indexed element and return it as a Double.getFloat
(int index) Retrieve an indexed element and return it as a Float.getInteger
(int index) Retrieve an indexed element and return it as an Integer.getLong
(int index) Retrieve an indexed element and return it as a Long.getObject
(int index) Return an object stored at the requested key value.getString
(int index) Retrieve an indexed element and return it as a String.Inserts the element at the given index of the underlying array store.iterator()
static BagArray
Create a new BagArray and "add" the object.pop()
query
(BooleanExpr match) query
(BooleanExpr match, SelectKey selectKey) queryTree
(BooleanExpr match, String childrenName) queryTree
(BooleanExpr match, SelectKey selectKey, String childrenName) query a tree, assuming a structure of a BagArray of BagObjects where the objects might have children in a named field.remove
(int index) Removes the element at the given index of the underlying array store.Replaces the element at the given index of the underlying array store.subset
(int start) trim only from the endsubset
(int start, int count) <Type> Type[]
Methods inherited from class us.irdev.bedrock.bag.Bag
equals, getBagArray, getBagArray, getBagObject, getBagObject, getBoolean, getBoolean, getDouble, getDouble, getEnum, getEnum, getFloat, getFloat, getInteger, getInteger, getLong, getLong, getString, getString, hashCode, match, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
BagArray
public BagArray()Create a new BagArray with a default underlying storage size. -
BagArray
public BagArray(int size) Create a new BagArray with hint for the underlying storage size.- Parameters:
size
- The expected number of elements in the BagArray, treated as a hint to optimize memory allocation. If additional elements are stored, the BagArray will revert to normal allocation behavior.
-
BagArray
Create a new BagArray as deep copy of another BagArray
-
-
Method Details
-
getCount
public int getCount()Return the number of elements stored in the BagArray.- Returns:
- the count of elements in the underlying store. This is distinct from the capacity of the underlying store.
-
insert
Inserts the element at the given index of the underlying array store. The underlying store is shifted to make space for the new element. The shift might cause the underlying store to be resized if there is insufficient room.Note that null values for the element ARE stored, as the underlying store is not a sparse array.
- Parameters:
index
- An integer value specifying the offset from the beginning of the array.object
- The element to store.- Returns:
- The BagArray, so that operations can be chained together.
-
add
Adds the element at the end of the underlying array store. The underlying store might be resized if there is insufficient room.Note that null values for the element ARE stored, as the underlying store is not a sparse array.
- Parameters:
object
- The element to store.- Returns:
- The BagArray, so that operations can be chained together.
-
open
-
concat
-
replace
Replaces the element at the given index of the underlying array store. The underlying store is not shifted, and will not be resized.Note that null values for the element ARE stored, as the underlying store is not a sparse array.
- Parameters:
index
- An integer value specifying the offset from the beginning of the array.object
- The element to store.- Returns:
- The BagArray, so that operations can be chained together.
-
remove
Removes the element at the given index of the underlying array store. The underlying store is shifted to cover the removed item. The underlying store will not be resized. Using invalid indices is ignored.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The BagArray, so that operations can be chained together.
-
getObject
-
getAndRemove
- Parameters:
index
-- Returns:
-
pop
- Returns:
-
dequeue
- Returns:
-
getObject
Return an object stored at the requested key value. The key may be a simple number, or a special keyword indicating the #first or #last element in the array, #add for putting at the end of the array, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively. -
getString
Retrieve an indexed element and return it as a String.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a string, or null if the element is not found (or not a String).
-
getBoolean
Retrieve an indexed element and return it as a Boolean.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a Boolean, or null if the element is not found.
-
getLong
Retrieve an indexed element and return it as a Long.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a Long, or null if the element is not found.
-
getInteger
Retrieve an indexed element and return it as an Integer.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as an Integer, or null if the element is not found.
-
getDouble
Retrieve an indexed element and return it as a Double.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a Double, or null if the element is not found.
-
getFloat
Retrieve an indexed element and return it as a Float.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a Float, or null if the element is not found.
-
getBagObject
Retrieve an indexed element and return it as a BagObject.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a BagObject, or null if the element is not found.
-
getBagArray
Retrieve an indexed element and return it as a BagArray.- Parameters:
index
- An integer value specifying the offset from the beginning of the array.- Returns:
- The element as a BagArray, or null if the element is not found.
-
toString
-
map
-
filter
-
iterator
-
select
- Specified by:
select
in interfaceSelectable<BagArray>
- Parameters:
selectKey
-- Returns:
-
sort
-
query
- Parameters:
match
- a BooleanExpr describing the match criteriaselectKey
- a SelectKey with the values to extract- Returns:
- array of elements matching the query
-
query
- Parameters:
match
- a BooleanExpr describing the match criteria- Returns:
- array of elements matching the query
-
queryTree
query a tree, assuming a structure of a BagArray of BagObjects where the objects might have children in a named field.- Parameters:
match
- a BooleanExpr describing the match criteriaselectKey
- a SelectKey with the values to extractchildrenName
- name of a field in found objects that will contain a child or list of children to query- Returns:
- array of elements matching the query throughout the tree
-
queryTree
-
subset
-
subset
trim only from the end -
toArray
-