Class BagObject
- All Implemented Interfaces:
Selectable<BagObject>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd an object to a BagArray stored at the requested key.int
getCount()
Return the number of elements stored in the BagObject.Return an object stored at the requested key value.boolean
Return whether or not the requested key or path is present in the BagObject or hierarchical "bedrock-of-bags"String[]
keys()
Returns an array of the keys contained in the underlying container. it does not enumerate the container and all of its children.static BagObject
static BagObject
Create a new BagObject and "put" the object using its key value.Store an object at the requested key value.Remove an object stored at the requested key.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
-
Constructor Details
-
BagObject
public BagObject()Create a new BagObject with a default underlying storage size. -
BagObject
public BagObject(int size) Create a new BagObject with hint for the underlying storage size.- Parameters:
size
- The expected number of elements in the BagObject, treated as a hint to optimize memory allocation. If additional elements are stored, the BagObject will revert to normal allocation behavior.
-
BagObject
Create a new BagObject as deep copy of another BagObject
-
-
Method Details
-
getCount
public int getCount()Return the number of elements stored in the BagObject.- Returns:
- the count of elements in the underlying store. This is distinct from the capacity of the underlying store.
-
getObject
Return an object stored at the requested key value. The key may be a simple name, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively.Using a binary search of the underlying store, finds where the first component of the path should be and returns it.
-
put
Store an object at the requested key value. The key may be a simple name, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively.Using a binary search of the underlying store, finds where the first component of the path should be. If it does not already exist, it is created (recursively in the case of a path), and the underlying store is shifted to make a space for it. The shift might cause the underlying store to be resized if there is insufficient room.
Note that null values for the element are NOT stored at the leaf of the tree denoted by a path, as returning null from getObject would be indistinguishable from a call to getObject with an unknown key. This check is performed before the tree traversal, so the underlying store will NOT contain the path after an attempt to add a null value.
- Parameters:
key
- A string value used to index the element, using "/" as separators, for example: "com/brettonw/bedrock/key".object
- The element to store.- Returns:
- The BagObject, so that operations can be chained together.
-
open
Create a new BagObject and "put" the object using its key value. The key may be a simple name, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively.- Parameters:
key
- A string value used to index the element, using "/" as separators, for example: "com/brettonw/bedrock/key".object
- The element to store.- Returns:
- The newly created BagObject.
-
add
Add an object to a BagArray stored at the requested key. The key may be a simple name, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively. If the key does not already exist a non-null value will be stored as a bare value, just as if "put" had been called. If it does exist, and is not already an array or the stored value is null, then a new array will be created to store any existing values and the requested element.Using a binary search of the underlying store, finds where the first component of the path should be. If it does not already exist, it is created (recursively in the case of a path), and the underlying store is shifted to make a space for it. The shift might cause the underlying store to be resized if there is insufficient room.
Note that null values for the BagArray ARE stored per the design decision for arrays.
- Parameters:
key
- A string value used to index the element, using "/" as separators, for example: "com/brettonw/bedrock/key".object
- The element to store.- Returns:
- The BagObject, so that operations can be chained together.
-
remove
Remove an object stored at the requested key. The key may be a simple name, or it may be a path (with keys separated by "/") to create a hierarchical "bedrock-of-bags" that is indexed recursively.Using a binary search of the underlying store, finds where the element mapped to the key should be, and removes it. If the element doesn't exist, nothing happens. If the element is removed, the underlying store is shifted to close the space where it was. removing elements will never cause the underlying store to shrink.
- Parameters:
key
- A string value used to index the element, using "/" as separators, for example: "com/brettonw/bedrock/key".- Returns:
- The BagObject, so that operations can be chained together.
-
has
Return whether or not the requested key or path is present in the BagObject or hierarchical "bedrock-of-bags"- Parameters:
key
- A string value used to index the element, using "/" as separators, for example: "com/brettonw/bedrock/key".- Returns:
- A boolean value, true if the key is present in the underlying store. Note that null values are not stored (design decision), so this equivalent to checking for null.
-
keys
Returns an array of the keys contained in the underlying container. it does not enumerate the container and all of its children.- Returns:
- The keys in the underlying map as an array of Strings.
-
toString
-
select
- Specified by:
select
in interfaceSelectable<BagObject>
- Parameters:
selectKey
-- Returns:
-
merge
-