Contents
Class IndexedList<T>
java.lang.Object
org.jlab.utils.groups.IndexedList<T>
- Type Parameters:
T
- the type of elements stored in the list
A generic class representing a collection of elements identified by a series
of indices which length can vary. The indices are hashed into a single long
key indexing the collection.
- Author:
- gavalian
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Utility class for generating and decoding a long key from a multi-dimensional index. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty IndexedList with the default index size (3).IndexedList
(int indsize) Constructs an IndexedList with the specified number of indices.IndexedList
(int[] byteShifts) Constructs an IndexedList with the specified number of indices. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an item to the collection with its index.void
clear()
Clears items from the collection.Returns the index generator for this collection.int
Gets the number of indices used to identify elements.getItem
(int... index) Retrieves an item by its index.getMap()
Returns the collection of items.boolean
hasItem
(int... index) Checks whether an item exists for the specified index.void
setIndexGenerator
(IndexedList.IndexGenerator indexGenerator) Sets the index generator for this collection.void
show()
Displays the collection
-
Constructor Details
-
IndexedList
public IndexedList()Constructs an empty IndexedList with the default index size (3). -
IndexedList
public IndexedList(int indsize) Constructs an IndexedList with the specified number of indices.- Parameters:
indsize
- the number of indices- Throws:
IllegalArgumentException
- if indsize is greater than 4, in which case a custom byte shift array should be used
-
IndexedList
public IndexedList(int[] byteShifts) Constructs an IndexedList with the specified number of indices.- Parameters:
byteShifts
- the byte shifts to consider to build the index
-
-
Method Details
-
add
Adds an item to the collection with its index.- Parameters:
item
- the item to be addedindex
- the index array used to identify the item
-
hasItem
public boolean hasItem(int... index) Checks whether an item exists for the specified index.- Parameters:
index
- the index to look up- Returns:
- true if an item exists at the index; false otherwise
-
getItem
Retrieves an item by its index.- Parameters:
index
- the index to find- Returns:
- the item at the index, null if not found
-
clear
public void clear()Clears items from the collection. -
getIndexSize
public int getIndexSize()Gets the number of indices used to identify elements.- Returns:
- the index size
-
getMap
-
getIndexGenerator
Returns the index generator for this collection.- Returns:
- the index generator
-
setIndexGenerator
Sets the index generator for this collection.- Parameters:
indexGenerator
- , the {
-
show
public void show()Displays the collection
-