|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.uniba.euromath.document.interval.DOMInterval
public final class DOMInterval
A simple selection implementation. Selects all nodes between two DOM pointers. References live instance of the document - the interval may become invalid when the document is changed. Immutable.
DOMInterval A is less (greater) than DOMInterval B if and only if: A.from is less (greater) than B.from, or A.to is less (greater) than B.to (if A.from.equals(B.from)).
Two DOMIntervals are equal when they cover the same contents: the same nodes
and same amount of text. This does not however imply that first interval's
from
pointer is equal to the second interval's
from
.
The object's compareTo(DOMInterval)
operates on DomPointers and is
thus inconsistent with equals(Object)
.
Field Summary | |
---|---|
DomPointer |
from
Select nodes from this pointer. |
DomPointer |
to
Select nodes up to this pointer. |
Constructor Summary | |
---|---|
DOMInterval(DomPointer from,
DomPointer to,
DomCore doc)
Constructor. |
Method Summary | |
---|---|
int |
compareTo(DOMInterval o)
|
boolean |
contains(DOMInterval other)
Checks if given interval is fully covered by this interval. |
boolean |
contains(DomPointer pointer)
Checks if given pointer points into contents of this interval. |
boolean |
contains(Node node)
Checks if this interval contains given node (or a part of given node). |
boolean |
endsOnNodeBoundary()
Checks if the interval fully covers the last node. |
boolean |
endsWithText()
Checks if last node is a text node. |
boolean |
equals(Object obj)
|
DocumentFragment |
extractContents(boolean replaceEntities)
Extracts nodes from given interval and copies them into a document fragment. |
List<Attr> |
getAttributes(boolean descendants)
Returns all attributes from all elements from the content node list. |
Set<String> |
getContentIds()
Returns set of identifiers for all content nodes. |
List<Node> |
getContents()
Retrieves contents of this interval. |
int |
getEndingIndex()
Checks if last node belongs only partially to the interval. |
DOMInterval |
getIntersection(DOMInterval other)
Checks if two intervals shares at least one common element / common letters from same text/cdata nodes, and returns interval containing this intersection. |
List<IDSelectionAction> |
getSelectionActions(boolean select)
Converts this interval into a list of selection actions. |
int |
getStartingIndex()
Checks if first node belongs only partially to the interval. |
String |
getTextContents()
Returns contents of all textual nodes contained in the contents. |
int |
hashCode()
|
boolean |
isAdjacentTo(DOMInterval other)
Checks if two intervals do not overlap and union(DOMInterval)
would return a valid interval. |
boolean |
isDeletable()
Checks if nodes between given interval can be safely cut out. |
boolean |
isEmpty()
Checks if this interval contains any content nodes. |
DOMInterval |
skipFromEntities()
For both interval ends tries to skip out from entities. |
boolean |
startsOnNodeBoundary()
Checks if the interval fully covers the first node. |
boolean |
startsWithText()
Checks if first interval node is a text node. |
String |
toString()
|
DOMInterval |
union(DOMInterval other)
Computes and returns union of two intervals if the result would still be a single interval. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final DomPointer from
null
.
public final DomPointer to
null
.
Constructor Detail |
---|
DOMInterval(DomPointer from, DomPointer to, DomCore doc)
factory
, obtainable via the
XMLAccess.getIntervalFactory()
method.
from
- select nodes from this pointer. Must not be null
.to
- select nodes up to this pointer. Must not be null
.doc
- owner document.Method Detail |
---|
public List<Node> getContents()
Retrieves contents of this interval.
If the from
and/or to
points into a text/cdata node(s),
these nodes are included in the returned list. However, elements are
listed only when all child nodes fully belong to the interval, and
from
neither to
descends from the element. Attribute
nodes are not part of the document tree and are not listed in the result
list.
If an element is listed in the list, none of its children and/or descendants are listed.
Nodes are sorted in the document ordering (parent first, then its children).
Nodes being returned may not have same parent. If you need this
functionality, please see the extractContents(boolean)
method.
null
. May be empty. Result is cached.public boolean isDeletable()
true
if both pointers point outside an entity.public DOMInterval skipFromEntities()
deletable
. This method does
not modify the contents
of this interval.
null
, may return itself.public boolean isEmpty()
true
if this interval is empty, false
if getContents()
will return non-empty list.public String getTextContents()
getContents()
method, or their descendants. Never null
, may be empty.
Result is cached.public int getStartingIndex()
from
pointer points into a textual node.
-1
if the pointer does not point into a text node.public boolean startsWithText()
false
if getStartingIndex()
would return
-1
, true
otherwise.public boolean startsOnNodeBoundary()
true
if first node is fully covered by the
interval, false
otherwise.public int getEndingIndex()
to
pointer points into a textual node.
-1
if the pointer does not point into a text node.public boolean endsOnNodeBoundary()
true
if last node is fully covered by the
interval, false
otherwise.public boolean endsWithText()
false
if getEndingIndex()
would return
-1
, true
otherwise.public List<Attr> getAttributes(boolean descendants)
descendants
- if true
then all elements (descendants
of the content nodes) are considered.
null
, may be empty. Result is cached.public DocumentFragment extractContents(boolean replaceEntities)
Extracts nodes from given interval and copies them into a document
fragment. Original nodes are left intact. The structure of the original
tree is kept, thus the fragment may contain nodes not listed in the
interval contents
.
You may get identical result if you follow the following algorithm:
Note: the result is not cached. Subsequent calls to this method can degrade the application performance.
replaceEntities
- if true
then
EntityReference
nodes are replaced by their contents. If
isDeletable()
returns false
then this parameter
must be true
.
null
. Will contain no nodes if the interval is empty.public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public int compareTo(DOMInterval o)
compareTo
in interface Comparable<DOMInterval>
public DOMInterval getIntersection(DOMInterval other)
other
- the other interval to check.
null
otherwise. Will never return empty
interval.public Set<String> getContentIds()
public boolean contains(DOMInterval other)
other
- the other interval
true
if given interval does not contain other
content than the one contained in this interval.public DOMInterval union(DOMInterval other)
other
- the other interval.
null
if
such an interval would cover content not present in both intervals.public boolean isAdjacentTo(DOMInterval other)
union(DOMInterval)
would return a valid interval.
other
- the other interval.
true
if two intervals are adjacent,
false
otherwise.public boolean contains(Node node)
node
- node to check.
true
if this interval covers (partially at least) given node.public boolean contains(DomPointer pointer)
pointer
- pointer to check
true
if given pointer lies inbetween from
and to
.public List<IDSelectionAction> getSelectionActions(boolean select)
select
- the value of the IDSelectionAction.select
attribute
for all returned instances.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |