- Type Parameters:
T- the type of object stored in the namespace
- All Superinterfaces:
Iterable<T>
- All Known Subinterfaces:
RecordTokenType
A mapping of names to objects, similar to a
Map.
A Namespace, however, also always remembers the order
of insertion. Entries can be referenced either by name
or by position as needed.-
Method Summary
Modifier and TypeMethodDescriptionget(int i) Gets the entry at the specified index.Gets the entry associated with the specified namefrom the namespace.getBinding(int i) Gets the name-entry association at the specified index.List<NameBinding<T>>Gets a collection of all the name-entry associations.getName(int i) Gets the name associated with entry at the specified index.String[]getNames()Gets all names registered in the namespace.intGets the index of the entry associated with the given name.booleanisEmpty()Indicates whether the namespace is empty.nameSet()Get an unmodifiable collection of all names.intsize()Retrieves the number of elements in the namespace.toList()Gets a list containing all namespace entries.Extracts all namespace entries to the specified list.toMap()Create a map containing the same mapping between names and entries.voidverifyNames(Iterable<String> names) Verifies that one or more names exist in the namespace.voidverifyNames(String... names) Verifies that one or more names exist in the namespace.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
size
int size()Retrieves the number of elements in the namespace.- Returns:
- the count of elements
-
isEmpty
boolean isEmpty()Indicates whether the namespace is empty. This is equivalent to checkingsize() == 0.- Returns:
trueif empty,falseotherwise
-
get
Gets the entry at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element to retrieve- Returns:
- the ith entry inserted into the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
getBinding
Gets the name-entry association at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element to retrieve- Returns:
- the ith name-entry binding in the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
getName
Gets the name associated with entry at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element name to retrieve- Returns:
- the name of the ith entry inserted into the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
indexOf
Gets the index of the entry associated with the given name.- Parameters:
name- the name of the entry to find- Returns:
- the index of the matching entry,
-1if no entry with the given name exists
-
get
Gets the entry associated with the specified namefrom the namespace.- Parameters:
name- the name of the entry to find- Returns:
- the associated entry, or
nullif there is no such entry
-
getNames
String[] getNames()Gets all names registered in the namespace. The names are ordered according to the order in which the entries were added.- Returns:
- the namespace's registered names
-
nameSet
Get an unmodifiable collection of all names. The order of entries when iterating over the set does not preserve the order in the namespace.- Returns:
- the set of the namespace's registered names
-
getBindings
List<NameBinding<T>> getBindings()Gets a collection of all the name-entry associations. The ordering of the result is the same as that of the namespace.- Returns:
- a list of bindings in the namespace
-
toList
Gets a list containing all namespace entries. The entries are in the list in the same order in which they were added to the namespace.- Returns:
- a list of namespace's registered entries
-
toList
Extracts all namespace entries to the specified list. The entries are added to the target list in the same order in which they were added to the namespace.- Parameters:
list- the list to which to add namespace entries- Returns:
- the target list
-
toMap
Create a map containing the same mapping between names and entries. The returned map preserves the iteration ordering of the namespace.- Returns:
- a map of names to entries
-
verifyNames
Verifies that one or more names exist in the namespace.- Parameters:
names- the names to verify- Throws:
InvalidFieldException- if any of the specified names are not present in the namespace
-
verifyNames
Verifies that one or more names exist in the namespace.- Parameters:
names- the names to verify- Throws:
InvalidFieldException- if any of the specified names are not present in the namespace
-