edu.uky.rch.ept.xmlSegmentTree
Class ElementSet

java.lang.Object
  extended byedu.uky.rch.ept.xmlSegmentTree.ElementSet

public class ElementSet
extends Object

A set of Elements. Modifications to the set return the new set; the old set is unmodified.


Nested Class Summary
 class ElementSet.Iterator
          An iterator over an ElementSet.
 
Constructor Summary
ElementSet()
          Create an empty set of elements.
 
Method Summary
 void addTo(Collection c)
          Append the elements of this set to a specfied collection.
protected static int compare(Element a, Element b)
          Compare two elements, returning -1, 1, 0 as the first precedes, follows, or is order-equivalent to the second.
 ElementSet insert(Element e)
          Return the result of inserting a new element into this set.
 boolean isEmpty()
          Test whether this set is empty
 Iterator iterator()
          Return an iterator over the elements of this set.
 ElementSet remove(Element e)
          Return the result of removing an element from this set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementSet

public ElementSet()
Create an empty set of elements.

Method Detail

isEmpty

public boolean isEmpty()
Test whether this set is empty

Returns:
true if this set is empty, false otherwise.

insert

public ElementSet insert(Element e)
Return the result of inserting a new element into this set.

Parameters:
e - the new element to add.
Returns:
a new ElementSet containing the elements in this set, as well as e.

remove

public ElementSet remove(Element e)
Return the result of removing an element from this set. Elements are tested with equals(). If multiple elements in the set are equal to the specified element, only one of them is removed.

Parameters:
e - the element to remove.
Returns:
a new ElementSet containing the elements in this set, except for e.

iterator

public Iterator iterator()
Return an iterator over the elements of this set. The elements are returned in sorted order (according to compare(edu.uky.rch.ept.xmlSegmentTree.element.Element, edu.uky.rch.ept.xmlSegmentTree.element.Element)). The returned iterator may not be used to modify the set.

Returns:
an iterator over the elements of this set.

addTo

public void addTo(Collection c)
Append the elements of this set to a specfied collection. Elements are added in sorted order (according to compare(edu.uky.rch.ept.xmlSegmentTree.element.Element, edu.uky.rch.ept.xmlSegmentTree.element.Element)).

Parameters:
c - the collection to modify.

compare

protected static int compare(Element a,
                             Element b)
Compare two elements, returning -1, 1, 0 as the first precedes, follows, or is order-equivalent to the second. For the purposes of this method, all string elements follow all tag elements, and elements with larger lengths follow those with smaller lengths.

Parameters:
a - the first element to compare.
b - the second element to compare.
Returns:
-1, 1, 0 as the a precedes, follows, or is order-equivalent to b.