sk.uniba.euromath.document.interval
Class DOMIntervalSet

java.lang.Object
  extended by sk.uniba.euromath.document.interval.DOMIntervalSet
All Implemented Interfaces:
Iterable<DOMInterval>, ISelection

public final class DOMIntervalSet
extends Object
implements ISelection, Iterable<DOMInterval>

An ordered set of disjunctive non-empty intervals. Mutable, thread unsafe.

References live instance of the document - the interval may become invalid when the document is changed.

Author:
Martin Vysny

Constructor Summary
DOMIntervalSet(DomCore doc)
          Constructs an empty set.
DOMIntervalSet(DomCore doc, DOMInterval interval)
          Constructs set with one item.
DOMIntervalSet(DomCore doc, DOMIntervalSet other)
          Copy-constructor.
 
Method Summary
 void clear()
          Removes all intervals from this set.
 List<IDSelectionAction> complement()
          Inverts the interval set - all nodes that were not part of the set will become contents of the set and vice versa.
 boolean contains(DOMInterval interval)
          Checks if this set fully covers given interval.
 boolean equals(Object obj)
           
 IntervalOrInsertPoint findIntervalOrInsertPoint(DomPointer ptr)
           Finds index of interval that contains given pointer, or an insert point where interval starting with given pointer would be inserted.
 Set<String> getContentIds()
          Returns set of IDs, covered (partially) by some interval(s).
 List<DOMInterval> getIntervals()
          Returns an list of all intervals.
 int hashCode()
           
 DOMIntervalSet intersect(DOMInterval interval)
          Intersects given interval with this set.
 DOMIntervalSet intersect(DOMIntervalSet other)
          Intersects given set with this set.
 boolean isEmpty()
          Checks if this set covers at least one node (or some characters of some node).
 Iterator<DOMInterval> iterator()
           
 DOMIntervalSet subtract(DOMInterval interval)
          Subtracts given interval to this interval set.
 DOMIntervalSet subtract(DOMIntervalSet other)
          Subtracts all intervals from given set to this interval set.
 List<IDSelectionAction> toSelectionActions(boolean select)
          Returns this set as a list of IDSelectionAction elements.
 String toString()
           
 DOMIntervalSet union(DOMInterval interval)
          Adds given interval to this interval set.
 DOMIntervalSet union(DOMIntervalSet other)
          Adds all intervals from given set to this interval set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DOMIntervalSet

DOMIntervalSet(DomCore doc)
Constructs an empty set.

Parameters:
doc - owner document.

DOMIntervalSet

DOMIntervalSet(DomCore doc,
               DOMIntervalSet other)
Copy-constructor.

Parameters:
doc - owner document.
other - clone this interval set.

DOMIntervalSet

DOMIntervalSet(DomCore doc,
               DOMInterval interval)
Constructs set with one item.

Parameters:
doc - owner document.
interval - the interval.
Method Detail

iterator

public Iterator<DOMInterval> iterator()
Specified by:
iterator in interface Iterable<DOMInterval>

getIntervals

public List<DOMInterval> getIntervals()
Returns an list of all intervals. The intervals are sorted and not adjacent.

Returns:
unmodifiable list of intervals.

getContentIds

public Set<String> getContentIds()
Returns set of IDs, covered (partially) by some interval(s).

Returns:
unmodifiable set of IDs.

union

public DOMIntervalSet union(DOMInterval interval)
Adds given interval to this interval set. This will take O(log(|this|)) in worst case.

Parameters:
interval - interval to add. Adjacent nodes are merged automatically.
Returns:
a set difference between new set and the old set. A list of intervals that would have been added to the old set in order to obtain the new set. Never null.

union

public DOMIntervalSet union(DOMIntervalSet other)
Adds all intervals from given set to this interval set. This will take |other|.O(log(|this|)) in worst case.

Parameters:
other - set of intervals to add. Adjacent nodes are merged automatically.
Returns:
a set difference between new set and the old set. A list of intervals that would have been added to the old set in order to obtain the new set. Never null.

subtract

public DOMIntervalSet subtract(DOMInterval interval)
Subtracts given interval to this interval set. This will take O(log(|this|)) in worst case.

Parameters:
interval - interval to subtract.
Returns:
a set difference between new set and the old set. A list of intervals that would have been removed from the old set in order to obtain the new set. Never null.

subtract

public DOMIntervalSet subtract(DOMIntervalSet other)
Subtracts all intervals from given set to this interval set. This will take |other|.O(log(|this|)) in worst case.

Parameters:
other - set of intervals to add.
Returns:
a set difference between new set and the old set. A list of intervals that would have been removed from the old set in order to obtain the new set. Never null.

intersect

public DOMIntervalSet intersect(DOMIntervalSet other)
Intersects given set with this set. This will take |other|.O(log(|this|)) in worst case.

Parameters:
other - the set to intersect with.
Returns:
a set difference between new set and the old set. A list of intervals that would have been removed from the old set in order to obtain the new set. Never null.

intersect

public DOMIntervalSet intersect(DOMInterval interval)
Intersects given interval with this set. This will take O(log(|this|)) in the worst case.

Parameters:
interval - the set to intersect with.
Returns:
a set difference between new set and the old set. A list of intervals that would have been removed from the old set in order to obtain the new set. Never null.

contains

public boolean contains(DOMInterval interval)
Checks if this set fully covers given interval. This will take O(log(|this|)) in worst case.

Parameters:
interval - interval to check
Returns:
true if all content of given interval is fully covered by the set, false if some nodes (or parts of nodes) are outside the set.

complement

public List<IDSelectionAction> complement()
Inverts the interval set - all nodes that were not part of the set will become contents of the set and vice versa.

Returns:
list of selection action that needs to be executed in order for the selection to be in sync with the set. Never null.

toSelectionActions

public List<IDSelectionAction> toSelectionActions(boolean select)
Returns this set as a list of IDSelectionAction elements.

Parameters:
select - the value of the IDSelectionAction.select attribute for all returned instances.
Returns:
list of actions to execute when you want to display selection for the entire set. Never null, may be empty if this set is empty.

isEmpty

public boolean isEmpty()
Checks if this set covers at least one node (or some characters of some node).

Specified by:
isEmpty in interface ISelection
Returns:
true if this set is empty, false if it contains at least one non-empty interval.

findIntervalOrInsertPoint

public IntervalOrInsertPoint findIntervalOrInsertPoint(DomPointer ptr)

Finds index of interval that contains given pointer, or an insert point where interval starting with given pointer would be inserted. This will take O(log(n)) in worst case.

Parameters:
ptr - pointer to check.
Returns:
instance of IntervalOrInsertPoint class providing information about the pointer.

clear

public void clear()
Removes all intervals from this set.


equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright 2003-2003-2006 null. All Rights Reserved.