Interface Index<E>

  • Type Parameters:
    E - the type parameter
    All Superinterfaces:
    Copyable<Index<E>>, Iterable<E>
    All Known Implementing Classes:
    HashMapIndex

    public interface Index<E>
    extends Iterable<E>, Copyable<Index<E>>

    An index represents a mapping from an Item to an id. All ids are positive integers.

    Author:
    David B. Bracewell
    • Method Detail

      • add

        int add​(E item)

        Adds an item to the index. If the item is already in the index, the item's id is returned otherwise the newly generated id is returned.

        Parameters:
        item - the item to add
        Returns:
        The id of the item
      • addAll

        void addAll​(Iterable<E> items)

        Adds all the items in the iterable to the index

        Parameters:
        items - The items to add.
      • asList

        List<E> asList()
        Retrieves an unmodifiable list view of the index
        Returns:
        an unmodifiable list view of the index
      • clear

        void clear()
        Clears the index
      • contains

        boolean contains​(E item)
        Determines if an item is in the index
        Parameters:
        item - The item
        Returns:
        True if the item is in the index, False if not
      • get

        E get​(int id)
        Gets the item with the given id.
        Parameters:
        id - The id
        Returns:
        The item associated with the id or null if there is none.
      • getId

        int getId​(E item)
        Gets the id of the item or -1 if it is not in the index.
        Parameters:
        item - The item whose id we want
        Returns:
        The id of the item or -1 if it is not in the index
      • isEmpty

        boolean isEmpty()
        Determines if the index is empty
        Returns:
        True if there are no items in the index
      • itemSet

        Set<E> itemSet()
        Gets a set of the items in the Index
        Returns:
        the set
      • size

        int size()
        The number of items in the index
        Returns:
        The number of items in the index
      • stream

        default Stream<E> stream()
        Stream stream.
        Returns:
        the stream