Class Sequence.Tree<T>

  • Type Parameters:
    T - note that in Tree the type parameter currently is not used
    Enclosing interface:
    Sequence<T>

    public static class Sequence.Tree<T>
    extends java.lang.Object
    Collection of static utility methods providing path access to nested sequence data.
    • Constructor Detail

      • Tree

        public Tree()
    • Method Detail

      • add

        public static <T> int add​(Sequence<T> sequence,
                                  T item,
                                  Sequence.Tree.Path path)
        Adds an item to a nested sequence.
        Type Parameters:
        T - Type of the items in this sequence.
        Parameters:
        sequence - The root sequence.
        item - The item to be added to the sequence.
        path - The path of the sequence to which the item should be added.
        Returns:
        The index at which the item was inserted, relative to the parent sequence.
      • insert

        public static <T> void insert​(Sequence<T> sequence,
                                      T item,
                                      Sequence.Tree.Path path,
                                      int index)
        Inserts an item into a nested sequence.
        Type Parameters:
        T - Type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        item - The item to be inserted into the sequence.
        path - The path of the sequence into which the item should be inserted.
        index - The index at which the item should be inserted within the parent sequence.
      • update

        public static <T> T update​(Sequence<T> sequence,
                                   Sequence.Tree.Path path,
                                   T item)
        Updates an item in a nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        path - The path of the item to update.
        item - The item that will replace any existing value at the given path.
        Returns:
        The item that was previously stored at the given path.
      • remove

        public static <T> Sequence.Tree.Path remove​(Sequence<T> sequence,
                                                    T item)
        Removes the first occurrence of an item from a nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        item - The item to remove.
        Returns:
        The path of the item that was removed.
      • remove

        public static <T> Sequence<T> remove​(Sequence<T> sequence,
                                             Sequence.Tree.Path path,
                                             int count)
        Removes items from a nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        path - The path of the item(s) to remove.
        count - The number of items to remove.
        Returns:
        The sequence of items that were removed.
      • get

        public static <T> T get​(Sequence<T> sequence,
                                Sequence.Tree.Path path)
        Retrieves an item from a nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        path - The path of the item to retrieve.
        Returns:
        The item at the given path, or null if the path is empty.
      • pathOf

        public static <T> Sequence.Tree.Path pathOf​(Sequence<T> sequence,
                                                    T item)
        Returns the path to an item in a nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The root sequence.
        item - The item to locate.
        Returns:
        The path of first occurrence of the item if it exists in the sequence; null otherwise.
      • depthFirstIterator

        public static <T> Sequence.Tree.ItemIterator<T> depthFirstIterator​(Sequence<T> sequence)
        Returns an iterator that will perform a depth-first traversal of the nested sequence.
        Type Parameters:
        T - The type of items in this sequence.
        Parameters:
        sequence - The sequence for which we are requesting an iterator.
        Returns:
        The new iterator over the sequence (depth-first order).
      • isDescendant

        public static boolean isDescendant​(Sequence.Tree.Path ancestorPath,
                                           Sequence.Tree.Path descendantPath)
        Determines whether the path represented by the second argument is a descendant of the path represented by the first argument.
        Parameters:
        ancestorPath - The ancestor path to test.
        descendantPath - The descendant path to test.
        Returns:
        true if the second argument is a descendant of the first path argument, false otherwise.