Package com.gengoai.collection
Interface Index<E>
-
- Type Parameters:
E
- the type parameter
- 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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
add(E item)
Adds an item to the index.void
addAll(Iterable<E> items)
Adds all the items in the iterable to the indexList<E>
asList()
Retrieves an unmodifiable list view of the indexvoid
clear()
Clears the indexboolean
contains(E item)
Determines if an item is in the indexE
get(int id)
Gets the item with the given id.int
getId(E item)
Gets the id of the item or -1 if it is not in the index.boolean
isEmpty()
Determines if the index is emptySet<E>
itemSet()
Gets a set of the items in the Indexint
size()
The number of items in the indexdefault Stream<E>
stream()
Stream stream.-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
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
-
size
int size()
The number of items in the index- Returns:
- The number of items in the index
-
-