Class ForestChange

Object
ForestChange
Direct Known Subclasses:
ForestChange.Add, ForestChange.Move, ForestChange.Remove, ForestChange.Reorder

@PublicApi @Immutable public abstract class ForestChange extends Object

ForestChange represents a single change on a forest. A list of ForestChanges represent a difference between two forests. ForestChanges are used only to represent the difference - to optimize event processing, traffic and to provide data to make visual cues about the change. ForestChanges are not used to record history or provide additional information about the forest.

There are several types of the operations, all defined as the inner classes of ForestChange:

Note that Reorder operation can be expressed as a series of Move operations. Structure can use either one Reorder or several Move changes to express reordering.

All classes are immutable.

  • Method Details

    • add

      public static ForestChange add(long under, long after, Forest added)
      Creates an "add" forest change.
      Parameters:
      under - the row under which the addition took place, or 0 if added at the top level
      after - the previous sibling to the first added row, or 0 if added as a first row under the parent
      added - forest that was added
      Returns:
      change
    • move

      public static ForestChange move(long under, long after, LongList rows)
      Creates a "move" forest change.
      Parameters:
      under - the row under which the moved rows were placed
      after - the row after which the moved rows were placed
      rows - a list of rows that were moved
      Returns:
      change
    • remove

      public static ForestChange remove(LongList rows)
      Creates a "remove" forest change.
      Parameters:
      rows - a list of rows that were removed from the forest
      Returns:
      change
    • reorder

      public static ForestChange reorder(long under, LongList children)
      Creates a "reorder" forest change.
      Parameters:
      under - the row under which the reordering took place, or 0 if added at the top level
      children - row IDs of the children, in the desired new order
      Returns:
      change
    • apply

      public abstract void apply(@NotNull ArrayForest forest)
      Given mutable forest, apply the change to it.
      Parameters:
      forest - forest to change
    • accept

      public abstract void accept(ForestChange.Visitor visitor)
      Apply the change to the visitor
      Parameters:
      visitor - receiver of the call based on the type of this change