gov.sandia.cognition.collection
Interface Indexer<ValueType>

Type Parameters:
ValueType - The type of value to be indexed.
All Known Implementing Classes:
DefaultIndexer

public interface Indexer<ValueType>

Defines the functionality of a collection that can map between values and integer indices. Indexers are typically used in places where unique objects need to be mapped to some fixed range of indices, such as 0 to n-1. The indexer can be used to bidirectionally map between indices and values.

Since:
3.3.3
Author:
Justin Basilico
See Also:
DefaultIndexer

Method Summary
 Integer add(ValueType value)
          Adds a value to the indexer and returns the index assigned to the value.
 void addAll(Iterable<? extends ValueType> values)
          Adds all of the given values to the index.
 Map<ValueType,Integer> asMap()
          Gets mapping of values to indices.
 Integer getIndex(ValueType value)
          Gets the index associated with the value.
 ValueType getValue(int index)
          Gets the value associated with the given index.
 ValueType getValue(Integer index)
          Gets the value associated with the given index.
 boolean hasIndex(int index)
          Determines if the given index is valid for this indexer, which means it has a value associated with it.
 boolean hasIndex(Integer index)
          Determines if the given index is valid for this indexer, which means it has a value associated with it.
 boolean hasValue(ValueType value)
          Determines if the given value is known to the indexer and has an index.
 boolean isEmpty()
          Returns true if this indexer is empty, which means it has no values.
 int size()
          Gets the number of items in the index.
 List<ValueType> valueList()
          Gets the list of values in the index.
 Set<ValueType> valueSet()
          Gets the set of values in the index.
 

Method Detail

add

Integer add(ValueType value)
Adds a value to the indexer and returns the index assigned to the value. If the value is already in the index, then its existing index will be returned.

Parameters:
value - The value to add.
Returns:
The index assigned to the value.

addAll

void addAll(Iterable<? extends ValueType> values)
Adds all of the given values to the index.

Parameters:
values - The values to add.

getIndex

Integer getIndex(ValueType value)
Gets the index associated with the value.

Parameters:
value - The value to get the index of.
Returns:
The index of the given value or null if there is no such index.

getValue

ValueType getValue(int index)
Gets the value associated with the given index. Will throw an exception if the index is invalid.

Parameters:
index - The index to get.
Returns:
The value at the index.

getValue

ValueType getValue(Integer index)
Gets the value associated with the given index. Will throw an exception if the index is invalid.

Parameters:
index - The index to get.
Returns:
The value at the index.

hasValue

boolean hasValue(ValueType value)
Determines if the given value is known to the indexer and has an index.

Parameters:
value - The value.
Returns:
True if the value has a valid index; otherwise, false.

hasIndex

boolean hasIndex(int index)
Determines if the given index is valid for this indexer, which means it has a value associated with it.

Parameters:
index - The index.
Returns:
True if the index has a valid value; otherwise, false.

hasIndex

boolean hasIndex(Integer index)
Determines if the given index is valid for this indexer, which means it has a value associated with it.

Parameters:
index - The index.
Returns:
True if the index has a valid value; otherwise, false.

isEmpty

boolean isEmpty()
Returns true if this indexer is empty, which means it has no values.

Returns:
True if the indexer is empty, which means it has no values and its size is zero.

size

int size()
Gets the number of items in the index.

Returns:
The number of items in the index.

valueSet

Set<ValueType> valueSet()
Gets the set of values in the index.

Returns:
The set of values.

valueList

List<ValueType> valueList()
Gets the list of values in the index.

Returns:
The list of values in the index.

asMap

Map<ValueType,Integer> asMap()
Gets mapping of values to indices.

Returns:
The mapping of values to indices.