Class IndexedList<T>

java.lang.Object
org.jlab.utils.groups.IndexedList<T>
Type Parameters:
T - the type of elements stored in the list

public class IndexedList<T> extends Object
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 Link icon

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Utility class for generating and decoding a long key from a multi-dimensional index.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constructs 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 Link icon

    Modifier and Type
    Method
    Description
    void
    add(T item, int... index)
    Adds an item to the collection with its index.
    void
    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.
    Returns the collection of items.
    boolean
    hasItem(int... index)
    Checks whether an item exists for the specified index.
    void
    Sets the index generator for this collection.
    void
    Displays the collection

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details Link icon

    • IndexedList Link icon

      public IndexedList()
      Constructs an empty IndexedList with the default index size (3).
    • IndexedList Link icon

      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 Link icon

      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 Link icon

    • add Link icon

      public void add(T item, int... index)
      Adds an item to the collection with its index.
      Parameters:
      item - the item to be added
      index - the index array used to identify the item
    • hasItem Link icon

      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 Link icon

      public T getItem(int... index)
      Retrieves an item by its index.
      Parameters:
      index - the index to find
      Returns:
      the item at the index, null if not found
    • clear Link icon

      public void clear()
      Clears items from the collection.
    • getIndexSize Link icon

      public int getIndexSize()
      Gets the number of indices used to identify elements.
      Returns:
      the index size
    • getMap Link icon

      public Map<Long,T> getMap()
      Returns the collection of items.
      Returns:
      the map of hashed keys to items
    • getIndexGenerator Link icon

      public IndexedList.IndexGenerator getIndexGenerator()
      Returns the index generator for this collection.
      Returns:
      the index generator
    • setIndexGenerator Link icon

      public void setIndexGenerator(IndexedList.IndexGenerator indexGenerator)
      Sets the index generator for this collection.
      Parameters:
      indexGenerator - , the {
    • show Link icon

      public void show()
      Displays the collection