Class ElementState

java.lang.Object
com.topologi.diffx.algorithm.ElementState

public final class ElementState extends Object
Maintains the state of open and closed elements during the processing the Diff-X algorithm.

This class has two purposes, firstly to provide an object that is more specialised than the generic lists and stack for use by the DiffX algorithms. Second, to delegate some of the complexity of algorithm.

This class has several methods that are similar to List interface but does not implement it.

This class is not synchronised and is not meant to be serializable.

Version:
12 May 2005
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private char[]
    The stack open elements changes.
    The stack of open elements.
    private int
    The size of both lists (the number of elements they contains).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty stack with an initial capacity of 12.
    ElementState(int initialCapacity)
    Constructs an stack of elements with the specified initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    checkRange(int index)
    Checks if the given index is in range.
    void
    Removes all of the elements from this list.
    boolean
    Returns true if this list contains the specified element.
    Returns the current open element.
    char
    Returns the change of the current open element.
    void
    Updates the state from the deleted event.
    void
    ensureCapacity(int minCapacity)
    Increases the capacity of this class instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
    void
    Updates the state from the formatted event.
    get(int index)
    Returns the open element at the specified position in this list.
    boolean
    Indicates whether the first specified event has priority over the second element.
    int
    Searches for the first occurrence of the given argument, testing for equality using the equals method.
    void
    Updates the state from the inserted event.
    boolean
    Tests if this list has no elements.
    int
    Returns the index of the last occurrence of the specified object in this list.
    boolean
    Indicates whether the specified event is a close element that matches the name and URI of the current open element.
    boolean
    Indicates whether the specified event is a close element that matches the name and URI of the current open element.
    boolean
    Indicates whether the specified event is a close element that matches the name and URI of the current open element.
    boolean
    Indicates whether the specified event is a close element that matches the name and URI of the current open element.
    pop()
    Removes the last element from the top of the stack.
    private void
    push(OpenElementEvent e, char c)
    Push the specified open element and flags it with the specified change.
    remove(int index)
    Removes the element at the specified position in this list.
    int
    Returns the number of elements in this stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • openElements

      private transient OpenElementEvent[] openElements
      The stack of open elements.
    • openChanges

      private transient char[] openChanges
      The stack open elements changes.
    • size

      private transient int size
      The size of both lists (the number of elements they contains).
  • Constructor Details

    • ElementState

      public ElementState(int initialCapacity) throws IllegalArgumentException
      Constructs an stack of elements with the specified initial capacity.
      Parameters:
      initialCapacity - The initial capacity of the list.
      Throws:
      IllegalArgumentException - if the specified initial capacity is negative.
    • ElementState

      public ElementState()
      Constructs an empty stack with an initial capacity of 12.
  • Method Details

    • ensureCapacity

      public void ensureCapacity(int minCapacity)
      Increases the capacity of this class instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
      Parameters:
      minCapacity - The desired minimum capacity.
    • size

      public int size()
      Returns the number of elements in this stack.
      Returns:
      the number of elements in this stack.
    • isEmpty

      public boolean isEmpty()
      Tests if this list has no elements.
      Returns:
      true if this list has no elements; false otherwise.
    • contains

      public boolean contains(OpenElementEvent element)
      Returns true if this list contains the specified element.
      Parameters:
      element - Element whose presence is to be tested.
      Returns:
      true if the specified element is present; false otherwise.
    • indexOf

      public int indexOf(OpenElementEvent element)
      Searches for the first occurrence of the given argument, testing for equality using the equals method.
      Parameters:
      element - The open elemnt to find.
      Returns:
      The index of the first occurrence of the argument in this list; returns -1</code if the object is not found.
      See Also:
    • lastIndexOf

      public int lastIndexOf(OpenElementEvent element)
      Returns the index of the last occurrence of the specified object in this list.
      Parameters:
      element - The desired element.
      Returns:
      The index of the last occurrence of the specified open element; or -1 if not found.
    • current

      public OpenElementEvent current()
      Returns the current open element.
      Returns:
      The current open element; or null if none.
    • currentChange

      public char currentChange()
      Returns the change of the current open element.
      Returns:
      The change of the current open element; or ' ' if none.
    • matchCurrent

      public boolean matchCurrent(DiffXEvent e)
      Indicates whether the specified event is a close element that matches the name and URI of the current open element.
      Parameters:
      e - The event to check.
      Returns:
      true if it matches the current element; false otherwise.
    • insert

      public void insert(DiffXEvent e)
      Updates the state from the inserted event.
      Parameters:
      e - The inserted event.
    • format

      public void format(DiffXEvent e)
      Updates the state from the formatted event.
      Parameters:
      e - The formatted event.
    • delete

      public void delete(DiffXEvent e)
      Updates the state from the deleted event.
      Parameters:
      e - The deleted event.
    • okFormat

      public boolean okFormat(DiffXEvent e)
      Indicates whether the specified event is a close element that matches the name and URI of the current open element.
      Parameters:
      e - The event to check.
      Returns:
      true if it matches the current element; false otherwise.
    • okInsert

      public boolean okInsert(DiffXEvent e)
      Indicates whether the specified event is a close element that matches the name and URI of the current open element.
      Parameters:
      e - The event to check.
      Returns:
      true if it matches the current element; false otherwise.
    • okDelete

      public boolean okDelete(DiffXEvent e)
      Indicates whether the specified event is a close element that matches the name and URI of the current open element.
      Parameters:
      e - The event to check.
      Returns:
      true if it matches the current element; false otherwise.
    • hasPriorityOver

      public boolean hasPriorityOver(DiffXEvent e1, DiffXEvent e2)
      Indicates whether the first specified event has priority over the second element. It only seem to be the case when the algorithm has the choice between an attribute and another element.
      Parameters:
      e1 - The element assumed to have priority.
      e2 - The other element.
      Returns:
      true if first specified event has priority over the second element; false otherwise.
    • push

      private void push(OpenElementEvent e, char c)
      Push the specified open element and flags it with the specified change.
      Parameters:
      e - The open element to push.
      c - The character corresponding to change.
    • pop

      public OpenElementEvent pop()
      Removes the last element from the top of the stack.
      Returns:
      The last element from the top of the stack.
    • get

      public OpenElementEvent get(int index) throws IndexOutOfBoundsException
      Returns the open element at the specified position in this list.
      Parameters:
      index - index of element to return.
      Returns:
      The element at the specified position in this list.
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).
    • remove

      public OpenElementEvent remove(int index) throws IndexOutOfBoundsException
      Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
      Parameters:
      index - The index of the element to removed.
      Returns:
      The element that was removed from the list.
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).
    • clear

      public void clear()
      Removes all of the elements from this list. The list will be empty after this call returns.
    • checkRange

      private void checkRange(int index) throws IndexOutOfBoundsException
      Checks if the given index is in range. If not, throw an appropriate runtime exception. This method does *not* check if the index is negative: It is always used immediately prior to an array access, which throws an ArrayIndexOutOfBoundsException if index is negative.
      Parameters:
      index - The index to check.
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).