Package com.gengoai.collection
Class HashMapIndex<TYPE>
- java.lang.Object
-
- com.gengoai.collection.HashMapIndex<TYPE>
-
- Type Parameters:
TYPE
- the type being indexed.
- All Implemented Interfaces:
Index<TYPE>
,Copyable<Index<TYPE>>
,Serializable
,Iterable<TYPE>
public class HashMapIndex<TYPE> extends Object implements Index<TYPE>, Serializable
An Index implementation that uses a combination of a HashMap and List.
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HashMapIndex()
Instantiates a new Hash map index.HashMapIndex(@NonNull Iterable<TYPE> items)
Instantiates a new Hash map index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
add(TYPE item)
Adds an item to the index.void
addAll(Iterable<TYPE> items)
Adds all the items in the iterable to the indexList<TYPE>
asList()
Retrieves an unmodifiable list view of the indexvoid
clear()
Clears the indexboolean
contains(TYPE item)
Determines if an item is in the indexIndex<TYPE>
copy()
Makes a copy of this object.boolean
equals(Object obj)
TYPE
get(int id)
Gets the item with the given id.int
getId(TYPE item)
Gets the id of the item or -1 if it is not in the index.int
hashCode()
boolean
isEmpty()
Determines if the index is emptySet<TYPE>
itemSet()
Gets a set of the items in the IndexIterator<TYPE>
iterator()
int
size()
The number of items in the indexString
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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.
-
addAll
public void addAll(Iterable<TYPE> items)
Description copied from interface:Index
Adds all the items in the iterable to the index
-
asList
public List<TYPE> asList()
Description copied from interface:Index
Retrieves an unmodifiable list view of the index
-
clear
public void clear()
Description copied from interface:Index
Clears the index
-
contains
public boolean contains(TYPE item)
Description copied from interface:Index
Determines if an item is in the index
-
copy
public Index<TYPE> copy()
Description copied from interface:Copyable
Makes a copy of this object.
-
get
public TYPE get(int id)
Description copied from interface:Index
Gets the item with the given id.
-
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.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Index
Determines if the index is empty
-
itemSet
public Set<TYPE> itemSet()
Description copied from interface:Index
Gets a set of the items in the Index
-
size
public int size()
Description copied from interface:Index
The number of items in the index
-
-