org.apache.pivot.wtk
Class Span

java.lang.Object
  extended by org.apache.pivot.wtk.Span

public final class Span
extends Object

Class representing a range of integer values. The range includes all values in the interval [start, end]. Values may be negative, and the value of start may be less than or equal to the value of end.


Field Summary
 int end
           
static String END_KEY
           
 int start
           
static String START_KEY
           
 
Constructor Summary
Span(Dictionary<String,?> span)
           
Span(int index)
           
Span(int start, int end)
           
Span(Span span)
           
 
Method Summary
 boolean contains(Span span)
          Determines whether this span contains another span.
static Span decode(String value)
           
 boolean equals(Object o)
           
 long getLength()
          Returns the length of the span.
 int hashCode()
           
 Span intersect(Span span)
          Calculates the intersection of this span and another span.
 boolean intersects(Span span)
          Determines whether this span intersects with another span.
 Span normalize()
          Returns a normalized equivalent of the span in which start is guaranteed to be less than end.
 Span offset(int offset)
          Returns a new Span with both values offset by the given value.
 String toString()
           
 Span union(Span span)
          Calculates the union of this span and another span.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

start

public final int start

end

public final int end

START_KEY

public static final String START_KEY
See Also:
Constant Field Values

END_KEY

public static final String END_KEY
See Also:
Constant Field Values
Constructor Detail

Span

public Span(int index)

Span

public Span(int start,
            int end)

Span

public Span(Span span)

Span

public Span(Dictionary<String,?> span)
Method Detail

getLength

public long getLength()
Returns the length of the span.

Returns:
The absolute value of (end minus start) + 1.

contains

public boolean contains(Span span)
Determines whether this span contains another span.

Parameters:
span - The span to test for containment.
Returns:
true if this span contains span; false, otherwise.

intersects

public boolean intersects(Span span)
Determines whether this span intersects with another span.

Parameters:
span - The span to test for intersection.
Returns:
true if this span intersects with span; false, otherwise.

intersect

public Span intersect(Span span)
Calculates the intersection of this span and another span.

Parameters:
span - The span to intersect with this span.
Returns:
A new Span instance representing the intersection of this span and span, or null if the spans do not intersect.

union

public Span union(Span span)
Calculates the union of this span and another span.

Parameters:
span - The span to union with this span.
Returns:
A new Span instance representing the union of this span and span.

normalize

public Span normalize()
Returns a normalized equivalent of the span in which start is guaranteed to be less than end.


offset

public Span offset(int offset)
Returns a new Span with both values offset by the given value.

This is useful while moving through a TextPane document for instance, where you have to subtract off the starting offset for child nodes.

Parameters:
offset - The positive or negative amount by which to "move" this span (both start and end).
Returns:
A new Span with updated values.

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

decode

public static Span decode(String value)