Class UniqueFieldIndex<T,​V>

  • Type Parameters:
    T - type of objects in this index
    V - type of the field used for indexing
    All Implemented Interfaces:
    FieldIndex<T,​V>, java.lang.Iterable<T>

    @ThreadSafe
    public class UniqueFieldIndex<T,​V>
    extends java.lang.Object
    implements FieldIndex<T,​V>
    A class representing a unique index. A unique index is an index where each index value only maps to one object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T object)
      Adds an object o to the index.
      void clear()
      Removes all the entries in this index.
      boolean containsField​(V fieldValue)
      Returns whether there is an object with the specified index field value in the set.
      boolean containsObject​(T object)
      Returns whether there is an object in the set.
      java.util.Set<T> getByField​(V value)
      Gets a subset of objects with the specified field value.
      T getFirst​(V value)
      Gets an object from the set of objects with the specified field value.
      java.util.Iterator<T> iterator()
      Returns an iterator over the elements in this index.
      boolean remove​(T object)
      Removes the object o from the index.
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • UniqueFieldIndex

        public UniqueFieldIndex​(IndexDefinition<T,​V> indexDefinition)
        Constructs a new UniqueFieldIndex instance.
        Parameters:
        indexDefinition - definition of index
    • Method Detail

      • add

        public boolean add​(T object)
        Description copied from interface: FieldIndex
        Adds an object o to the index.
        Specified by:
        add in interface FieldIndex<T,​V>
        Parameters:
        object - the object to add to the index
        Returns:
        true if object is added successfully, false otherwise
      • remove

        public boolean remove​(T object)
        Description copied from interface: FieldIndex
        Removes the object o from the index.
        Specified by:
        remove in interface FieldIndex<T,​V>
        Parameters:
        object - the object to remove from index
        Returns:
        whether the specified element was in the index
      • clear

        public void clear()
        Description copied from interface: FieldIndex
        Removes all the entries in this index.
        Specified by:
        clear in interface FieldIndex<T,​V>
      • containsField

        public boolean containsField​(V fieldValue)
        Description copied from interface: FieldIndex
        Returns whether there is an object with the specified index field value in the set.
        Specified by:
        containsField in interface FieldIndex<T,​V>
        Parameters:
        fieldValue - the field value to be satisfied
        Returns:
        true if there is one such object, otherwise false
      • containsObject

        public boolean containsObject​(T object)
        Description copied from interface: FieldIndex
        Returns whether there is an object in the set.
        Specified by:
        containsObject in interface FieldIndex<T,​V>
        Parameters:
        object - the object to be checked
        Returns:
        true if there is one such object, otherwise false
      • getByField

        public java.util.Set<T> getByField​(V value)
        Description copied from interface: FieldIndex
        Gets a subset of objects with the specified field value. If there is no object with the specified field value, an empty set is returned.
        Specified by:
        getByField in interface FieldIndex<T,​V>
        Parameters:
        value - the field value to be satisfied
        Returns:
        the set of objects or an empty set if no such object exists
      • getFirst

        public T getFirst​(V value)
        Description copied from interface: FieldIndex
        Gets an object from the set of objects with the specified field value.
        Specified by:
        getFirst in interface FieldIndex<T,​V>
        Parameters:
        value - the field value to be satisfied
        Returns:
        the object or null if there is no such object
      • iterator

        public java.util.Iterator<T> iterator()
        Description copied from interface: FieldIndex
        Returns an iterator over the elements in this index. The elements are returned in no particular order. Note that the behavior of the iterator is unspecified if the underlying collection is modified while a thread is going through the iterator.
        Specified by:
        iterator in interface FieldIndex<T,​V>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        an iterator over the elements in this FieldIndex
      • size

        public int size()
        Specified by:
        size in interface FieldIndex<T,​V>
        Returns:
        the number of objects in this index set