Interface Namespace<T>

  • Type Parameters:
    T - the type of object stored in the namespace
    All Superinterfaces:
    Iterable<T>
    All Known Subinterfaces:
    RecordTokenType

    public interface Namespace<T>
    extends Iterable<T>
    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 Detail

      • 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 checking size() == 0.
        Returns:
        true if empty, false otherwise
      • get

        T get​(int i)
        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 - if i < 0 || i >= size()
      • getBinding

        NameBinding<T> getBinding​(int i)
        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 - if i < 0 || i >= size()
      • getName

        String getName​(int i)
        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 - if i < 0 || i >= size()
      • indexOf

        int indexOf​(String name)
        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, -1 if no entry with the given name exists
      • get

        T get​(String name)
        Gets the entry associated with the specified namefrom the namespace.
        Parameters:
        name - the name of the entry to find
        Returns:
        the associated entry, or null if 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

        Set<String> 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

        List<T> 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

        List<? super T> toList​(List<? super T> list)
        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

        Map<String,​T> 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

        void verifyNames​(String... names)
                  throws InvalidFieldException
        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