|
Ila | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.topoweb.ila.NodeSet
Immutable encapsulation of a list of monotonically ascending
Node
instances within a given lexical range.
The nodes are guaranteed to be sorted in ascending
order with no duplicates, if the reference to the node
array passed in at instantiation is discarded by the caller. See note
below.
A NodeSet
represents not just a list of nodes, but
also the lexical range of the Ori
of the nodes in the list.
A NodeSet
may be complete, or
truncated. When an instance is complete,
it means the instance represents all the nodes in its range; when it is truncated, the instance represents a contiguous
subset of the nodes of its range. If a node is not complete (is truncated),
then the nodes in its list start from either end of it range. This is
indicated by the getPageOrder
method.
Node
instances as one of their arguments. This array itself is not copied.
The caller, therefore, must take care not to change the elements of the
array after instantiation. This requirement is best achieved if the caller
discards the reference to the node
array after construction.
Note: Will probably adapt this class so that it implements
java.util.SortedSet
.
Field Summary | |
static NodeSet |
EMPTY
An empty set with infinite range. |
protected static java.util.Comparator |
searchComparator
The comparator used to implement index-of-cursor searches. |
static NodeSet |
UNKNOWN
An empty set with no range. |
Fields inherited from interface org.topoweb.ila.NodeConstants |
BACK, FIRST_PAGE, FORE, LAST_PAGE, LINK_MASK, PAGE_MASK |
Constructor Summary | |
NodeSet(Node[] nodes,
org.topoweb.util.StringRange range)
Convenience constructor. |
|
NodeSet(Node[] nodes,
org.topoweb.util.StringRange range,
int page,
int size)
Creates a new instance with the given nodes array
and range , and optional page flag and
size .. |
Method Summary | |
protected boolean |
checkForm(Node node)
Checks the form of the node . |
int |
count()
Returns the number of nodes stored in this instance. |
Node |
getNode(int index)
Returns the node at the specified index. |
int |
getPageOrder()
Returns the page order of this instance. |
org.topoweb.util.StringRange |
getRange()
Returns the lexical range of the Ori s of
nodes that this set covers. |
int |
indexOfCursor(java.lang.String cursor)
Returns the index of the Node whose Ori is lexically equal to the given string cursor . |
boolean |
isComplete()
Returns whether this instance contains all the nodes in its range. |
boolean |
isFirstPage()
Tests whether this instance represents the first page. |
boolean |
isLastPage()
Tests whether this instance represents the last page. |
boolean |
isTruncated()
Returns whether this instance contains only a subset of the nodes in its range. |
int |
size()
Returns the number of elements in the range of this instance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.util.Comparator searchComparator
StringComparator
.
indexOfCursor(String)
public static final NodeSet EMPTY
StringRange.ALL
public static final NodeSet UNKNOWN
StringRange.Z
Constructor Detail |
public NodeSet(Node[] nodes, org.topoweb.util.StringRange range) throws java.lang.IllegalArgumentException
NodeSet(nodes, range, FIRST_PAGE, 0)
.
NodeSet(Node[],StringRange,int,int)
,
Implementation Note on Immutabilitypublic NodeSet(Node[] nodes, org.topoweb.util.StringRange range, int page, int size) throws java.lang.IllegalArgumentException
nodes
array
and range
, and optional page
flag and
size
..
Subclasses may impose furthur restrictions on the form of the
nodes by overriding checkForm(Node)
.
nodes
- an array of Node
s sorted in
ascending orderrange
- lexical range of the Ori
s
of the nodes
page
- page order flag (FIRST_PAGE
or LAST_PAGE
.size
- the number of nodes in the lexical
range
(defaults to nodes.length
)
java.lang.IllegalArgumentException
- if nodes
is null
;
if nodes
contains null
elements; if the elements of nodes
are not monotonically ascending;
if the checkForm
method returns false
for
any of the elements in the nodes
array;
if range
does not contain all the
elements in nodes
;checkForm(Node)
Method Detail |
protected boolean checkForm(Node node)
node
. Subclasses may override
in order to enforce other constraints on the elements of the set. The
default implementation always returns true
.
node
- the Node
whose form is checked;
never null
true
, if node
is
well formed; false
, o.w.public final int indexOfCursor(java.lang.String cursor)
Node
whose Ori
is lexically equal to the given string cursor
.
If no match is found, then the value returned is -1 - insertionPoint
, where insertionPoint is defined as documented in
java.util.Arrays.binarySearch()
.
cursor
- the string cursor
public final Node getNode(int index)
index
- the index of the node to be returned
index
, or
null
, if the index
is
out of boundspublic final int count()
getNode
method will return non-null values.
public final org.topoweb.util.StringRange getRange()
Ori
s of
nodes that this set covers. The returned range can have
application-specific semantics, such as an indication of knowledge
about nodes in some lexical region.
public final int size()
public final boolean isComplete()
true
iff count() == size()
.
true
, if all the nodes in this
instance's range may
be returned through the getNode
method; false
, o.w.isTruncated()
public final boolean isTruncated()
!isComplete()
isComplete()
public final int getPageOrder()
FIRST_PAGE
or
LAST_PAGE
. The page order is
significant only if the instance is truncated; if the instance is complete,
then FIRST_PAGE
and LAST_PAGE
represent
the same thing.
public final boolean isFirstPage()
true
, if getPageOrder()
== FIRST_PAGE
; false
, o.w.public final boolean isLastPage()
true
, if getPageOrder()
== LAST_PAGE
; false
, o.w.
|
Ila | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |