Class HashMapIndex<TYPE>

    • Constructor Detail

      • HashMapIndex

        public HashMapIndex()
        Instantiates a new Hash map index.
      • HashMapIndex

        public HashMapIndex​(@NonNull
                            @NonNull Iterable<TYPE> items)
        Instantiates a new Hash map index.
        Parameters:
        items - the items
    • Method Detail

      • add

        public int add​(TYPE item)
        Description copied from interface: Index

        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.

        Specified by:
        add in interface Index<TYPE>
        Parameters:
        item - the item to add
        Returns:
        The id of the item
      • addAll

        public void addAll​(Iterable<TYPE> items)
        Description copied from interface: Index

        Adds all the items in the iterable to the index

        Specified by:
        addAll in interface Index<TYPE>
        Parameters:
        items - The items to add.
      • asList

        public List<TYPE> asList()
        Description copied from interface: Index
        Retrieves an unmodifiable list view of the index
        Specified by:
        asList in interface Index<TYPE>
        Returns:
        an unmodifiable list view of the index
      • clear

        public void clear()
        Description copied from interface: Index
        Clears the index
        Specified by:
        clear in interface Index<TYPE>
      • contains

        public boolean contains​(TYPE item)
        Description copied from interface: Index
        Determines if an item is in the index
        Specified by:
        contains in interface Index<TYPE>
        Parameters:
        item - The item
        Returns:
        True if the item is in the index, False if not
      • copy

        public Index<TYPE> copy()
        Description copied from interface: Copyable

        Makes a copy of this object.

        Specified by:
        copy in interface Copyable<TYPE>
        Returns:
        A copy of this object.
      • get

        public TYPE get​(int id)
        Description copied from interface: Index
        Gets the item with the given id.
        Specified by:
        get in interface Index<TYPE>
        Parameters:
        id - The id
        Returns:
        The item associated with the id or null if there is none.
      • getId

        public int getId​(TYPE item)
        Description copied from interface: Index
        Gets the id of the item or -1 if it is not in the index.
        Specified by:
        getId in interface Index<TYPE>
        Parameters:
        item - The item whose id we want
        Returns:
        The id of the item or -1 if it is not in the index
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Index
        Determines if the index is empty
        Specified by:
        isEmpty in interface Index<TYPE>
        Returns:
        True if there are no items in the index
      • itemSet

        public Set<TYPE> itemSet()
        Description copied from interface: Index
        Gets a set of the items in the Index
        Specified by:
        itemSet in interface Index<TYPE>
        Returns:
        the set
      • size

        public int size()
        Description copied from interface: Index
        The number of items in the index
        Specified by:
        size in interface Index<TYPE>
        Returns:
        The number of items in the index