Package com.topologi.diffx.algorithm
Class ElementState
java.lang.Object
com.topologi.diffx.algorithm.ElementState
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
FieldsModifier and TypeFieldDescriptionprivate char[]The stack open elements changes.private OpenElementEvent[]The stack of open elements.private intThe size of both lists (the number of elements they contains). -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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 TypeMethodDescriptionprivate voidcheckRange(int index) Checks if the given index is in range.voidclear()Removes all of the elements from this list.booleancontains(OpenElementEvent element) Returnstrueif this list contains the specified element.current()Returns the current open element.charReturns the change of the current open element.voiddelete(DiffXEvent e) Updates the state from the deleted event.voidensureCapacity(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.voidformat(DiffXEvent e) Updates the state from the formatted event.get(int index) Returns the open element at the specified position in this list.booleanhasPriorityOver(DiffXEvent e1, DiffXEvent e2) Indicates whether the first specified event has priority over the second element.intindexOf(OpenElementEvent element) Searches for the first occurrence of the given argument, testing for equality using theequalsmethod.voidinsert(DiffXEvent e) Updates the state from the inserted event.booleanisEmpty()Tests if this list has no elements.intlastIndexOf(OpenElementEvent element) Returns the index of the last occurrence of the specified object in this list.booleanIndicates whether the specified event is a close element that matches the name and URI of the current open element.booleanIndicates whether the specified event is a close element that matches the name and URI of the current open element.booleanIndicates whether the specified event is a close element that matches the name and URI of the current open element.booleanIndicates 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 voidpush(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.intsize()Returns the number of elements in this stack.
-
Field Details
-
openElements
The stack of open elements. -
openChanges
private transient char[] openChangesThe stack open elements changes. -
size
private transient int sizeThe size of both lists (the number of elements they contains).
-
-
Constructor Details
-
ElementState
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:
trueif this list has no elements;falseotherwise.
-
contains
Returnstrueif this list contains the specified element.- Parameters:
element- Element whose presence is to be tested.- Returns:
trueif the specified element is present;falseotherwise.
-
indexOf
Searches for the first occurrence of the given argument, testing for equality using theequalsmethod.- 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
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
Returns the current open element.- Returns:
- The current open element; or
nullif 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
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:
trueif it matches the current element;falseotherwise.
-
insert
Updates the state from the inserted event.- Parameters:
e- The inserted event.
-
format
Updates the state from the formatted event.- Parameters:
e- The formatted event.
-
delete
Updates the state from the deleted event.- Parameters:
e- The deleted event.
-
okFormat
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:
trueif it matches the current element;falseotherwise.
-
okInsert
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:
trueif it matches the current element;falseotherwise.
-
okDelete
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:
trueif it matches the current element;falseotherwise.
-
hasPriorityOver
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:
trueif first specified event has priority over the second element;falseotherwise.
-
push
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
Removes the last element from the top of the stack.- Returns:
- The last element from the top of the stack.
-
get
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
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
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()).
-