pivot.wtk
Class SpanSequence

java.lang.Object
  extended by pivot.wtk.SpanSequence
All Implemented Interfaces:
Sequence<Span>

public class SpanSequence
extends Object
implements Sequence<Span>

Class representing a sequence of sorted, consolidated spans.

Author:
gbrown

Nested Class Summary
static class SpanSequence.SpanComparator
          Determines the relative order of two spans.
 
Nested classes/interfaces inherited from interface pivot.collections.Sequence
Sequence.Search, Sequence.Sort, Sequence.Tree
 
Constructor Summary
SpanSequence()
           
 
Method Summary
 int add(Span span)
          Adds a span to the sequence, merging and removing intersecting spans as needed.
 void clear()
          Removes all spans from the sequence.
 Span get(int index)
          Retrieves the span at the given index.
 int getLength()
          Returns the length of the sequence.
 int indexOf(Span span)
          Returns the index of the first identified span that intersects with the given span, or a negative value representing the insertion point of the span as defined by the binary search algorithm.
 void insert(Span span, int index)
          Not supported.
 void insertIndex(int index)
          Inserts an index into the span sequence.
 Sequence<Span> remove(int index, int count)
          Removes one or more spans from the sequence.
 int remove(Span span)
          Removes a span from the sequence, truncating and removing intersecting spans as needed.
 void removeIndexes(int index, int count)
          Removes a range of indexes from the span sequence.
 Span update(int index, Span span)
          Not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpanSequence

public SpanSequence()
Method Detail

add

public int add(Span span)
Adds a span to the sequence, merging and removing intersecting spans as needed.

Specified by:
add in interface Sequence<Span>
Parameters:
span - The span to add to the sequence.
Returns:
The index at which the span was added.

insert

public final void insert(Span span,
                         int index)
Not supported.

Specified by:
insert in interface Sequence<Span>
Parameters:
span - The item to be added to the sequence.
index - The index at which the item should be inserted. Must be a value between 0 and getLength().

update

public final Span update(int index,
                         Span span)
Not supported.

Specified by:
update in interface Sequence<Span>
Parameters:
index - The index of the item to update.
span - The item that will replace any existing value at the given index.
Returns:
The item that was previously stored at the given index.

remove

public int remove(Span span)
Removes a span from the sequence, truncating and removing intersecting spans as needed.

Specified by:
remove in interface Sequence<Span>
Parameters:
span - The span to remove from the sequence.
Returns:
The index from which the span was removed.
See Also:
Sequence.remove(int, int)

remove

public Sequence<Span> remove(int index,
                             int count)
Removes one or more spans from the sequence.

Specified by:
remove in interface Sequence<Span>
Parameters:
index - The starting index to remove.
count - The number of items to remove, beginning with index.
Returns:
A sequence containing the spans that were removed.

clear

public void clear()
Removes all spans from the sequence.


get

public Span get(int index)
Retrieves the span at the given index.

Specified by:
get in interface Sequence<Span>
Parameters:
index - The index of the span to retrieve.

indexOf

public int indexOf(Span span)
Returns the index of the first identified span that intersects with the given span, or a negative value representing the insertion point of the span as defined by the binary search algorithm.

Specified by:
indexOf in interface Sequence<Span>
Parameters:
span - The item to locate.
Returns:
The index of first occurrence of the item if it exists in the sequence; -1, otherwise.

getLength

public int getLength()
Returns the length of the sequence.

Specified by:
getLength in interface Sequence<Span>
Returns:
The number of spans in the sequence.

insertIndex

public void insertIndex(int index)
Inserts an index into the span sequence.

Parameters:
index - The index to insert.

removeIndexes

public void removeIndexes(int index,
                          int count)
Removes a range of indexes from the span sequence.

Parameters:
index - The first index to remove.
count - The number of indexes to remove.