|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.ajaest.lib.data.SequenceTree<S,E>
S
- the class of the sequence objectsE
- the class of the stored nodes objectspublic class SequenceTree<S,E>
Search tree by sequence. This class allows to sort a list of node objects
using a unique sequence of other objects. Every level of the tree represents
all the node objects that can be retrieved through the same object sequence.
This class can use either ArrayList
or LinkedList
implementations for final nodes list. It's recommended to use ArrayList
implementation for fixed trees and LinkedList
implementation for dynamic trees.
You must be aware that the node circularity of the tree isn't checked when a
new node is added. Circular connection between nodes could cause unexpected
behavior.
Keep in mind too that if the serialization process of an instance of this
class won't retrieve information about the parent structure. This means that
the readObject()
method will always assign null
to the parent
field of the tree's root node.
Nested Class Summary | |
---|---|
private class |
SequenceTree.TreeIterator
|
Field Summary | |
---|---|
protected java.util.List<E> |
finalNodes
|
protected boolean |
isLinked
|
protected SequenceTree<S,E> |
parent
|
protected S |
sequenceValue
|
protected int |
serialID
Used to keep node reference in serialization |
protected static java.lang.Integer |
serialIDseed
|
private static long |
serialVersionUID
|
protected java.util.Map<S,SequenceTree<S,E>> |
subtrees
Serialization of big trees causes stack overflow because of recursive reflection, so maps are serialized horizontally instead of deeply. |
Constructor Summary | |
---|---|
SequenceTree()
Creates a sequence tree using either the LinkedList implementation
for final nodes list. |
|
SequenceTree(boolean linked)
Creates a sequence tree using either ArrayList or LinkedList implementation for final nodes list. |
Method Summary | |
---|---|
void |
add(java.util.List<S> sequence,
E finalNode)
Creates needed sequence tree if necessary in order to add a final node to the tree. |
void |
add(S[] sequence,
E finalNode)
Creates needed sequence tree if necessary in order to add a final node to the tree. |
boolean |
addFinalNode(E node)
Appends the specified element to the end of this list. |
void |
addSubTree(S sequenceValue,
SequenceTree<S,E> subtree)
Adds a subtree to this tree using either provided sequenceValue
or subtree.sequenceValue . |
protected java.util.Map<S,SequenceTree<S,E>> |
createSubTreeMapInstance()
|
boolean |
equals(java.lang.Object obj)
To sequence tree equals if they have the same sequence value and final nodes. |
boolean |
exist(java.util.List<S> sequence)
Says whether exists or not any final node in this tree referenced by the specified sequence |
java.util.List<E> |
getFinalNodes()
|
SequenceTree<S,E> |
getParent()
|
S |
getSequenceValue()
|
SequenceTree<S,E> |
getSubTree(S sequenceValue)
Returns the subtree whose sequence value equals the specified one. |
java.util.Map<S,SequenceTree<S,E>> |
getSubTrees()
Returns an unmodifiable map that maps subtrees from this tree by his sequence value. |
int |
hashCode()
|
protected void |
init(boolean linked)
Me Method extracted in order to allow post-construction initialization in inherited classes(For example, in SequenceEnumTree |
java.util.Iterator<SequenceTree<S,E>> |
iterator()
Returns an iterator that iterates through all the nodes contained in this tree. |
protected void |
readAndAssignToThis(java.io.ObjectInput in)
|
void |
readExternal(java.io.ObjectInput in)
Reconstitute the OrderedSequenceTree instance from a stream (i.e., deserialize it). |
protected SequenceTree<S,E> |
readTreeSequentially(java.io.ObjectInput in)
Parent field is not retrieved |
boolean |
removeFinalNode(E node)
Removes the first occurrence of the specified element from this list, if it is present. |
E |
removeFinalNode(int index)
Removes the element at the specified position in this list. |
SequenceTree<S,E> |
removeSubTree(S sequenceValue)
Removes the mapping for the specified key from this map if present. |
java.util.List<E> |
search(java.util.List<S> sequence)
Does a recursive search along subtrees of this tree in order to get final nodes that matches the specified sequence. |
java.util.List<E> |
search(S[] sequence)
Does a recursive search along subtrees of this tree in order to get final nodes that matches the specified sequence. |
E |
searchFirst(java.util.List<S> sequence)
Does a recursive search along subtrees of this tree in order to get the first final node added to this tree that matches the specified sequence. |
E |
searchFirst(S[] sequence)
Does a recursive search along subtrees of this tree in order to get the first final node added to this tree that matches the specified sequence. |
E |
setFinalNode(int index,
E element)
Replaces the element at the specified position in this list with the specified element. |
void |
writeExternal(java.io.ObjectOutput out)
Save the state of the OrderedSequenceTree instance to a stream (i.e., serialize it). |
protected void |
writeTreeSequentially(java.io.ObjectOutput out,
SequenceTree<S,E> ost)
Parent field is not stored |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
protected static java.lang.Integer serialIDseed
protected int serialID
protected SequenceTree<S,E> parent
protected S sequenceValue
protected transient java.util.Map<S,SequenceTree<S,E>> subtrees
writeExternal(ObjectOutput)
,
readExternal(ObjectInput)
protected java.util.List<E> finalNodes
protected boolean isLinked
Constructor Detail |
---|
public SequenceTree()
LinkedList
implementation
for final nodes list.
public SequenceTree(boolean linked)
ArrayList
or LinkedList
implementation for final nodes list. It's recommended to use
ArrayList
implementations for fixed trees and LinkedList
implementation for dynamic trees.
linked
- if it's true, object will use LinkedList
implementation. Object will use ArrayList
implementation if it's false.Method Detail |
---|
protected void init(boolean linked)
SequenceEnumTree
linked
- public void add(java.util.List<S> sequence, E finalNode)
sequence.size()==0
, the final node is added to
this tree.
sequence
- the sorting sequencefinalNode
- the final nodepublic void add(S[] sequence, E finalNode)
sequence.length==0
, the final node is added to
this tree.
sequence
- the sorting sequencefinalNode
- the final nodepublic java.util.Map<S,SequenceTree<S,E>> getSubTrees()
public java.util.List<E> getFinalNodes()
public SequenceTree<S,E> getSubTree(S sequenceValue)
sequenceValue
- the sequence value of the requested subtree
public S getSequenceValue()
public SequenceTree<S,E> getParent()
public void addSubTree(S sequenceValue, SequenceTree<S,E> subtree)
sequenceValue
or subtree.sequenceValue
. If sequenceValue
don't equals
null
, this value will be used to map the subtree. subtree.sequenceValue
will be used to map the subtree if sequenceValue
equals null
only if subtree.sequenceValue
does not equals null
. If both sequence values equals null
exception will be thrown.
sequenceValue
- order mapping value, if null sequenceValue
will be
usedsubtree
- subtree to be added
java.lang.NullPointerException
- if sequenceValue
and subtree.sequenceValue
are both nullpublic E setFinalNode(int index, E element)
index
- index of the element to replaceelement
- element to be stored at the specified position
java.lang.IndexOutOfBoundsException
public boolean addFinalNode(E node)
node
- element to be appended to this list
Collection.add(E)
)public SequenceTree<S,E> removeSubTree(S sequenceValue)
sequenceValue
- key whose mapping is to be removed from the map
public E removeFinalNode(int index)
index
- the index of the element to be removed
java.lang.IndexOutOfBoundsException
public boolean removeFinalNode(E node)
node
- element to be removed from this list, if present
public java.util.List<E> search(java.util.List<S> sequence)
sequence
- sequence to be searched
public E searchFirst(java.util.List<S> sequence)
sequence
- sequence to be searched
public E searchFirst(S[] sequence)
sequence
- sequence to be searched
public java.util.List<E> search(S[] sequence)
sequence
- sequence to be searched
public boolean exist(java.util.List<S> sequence)
sequence
- sequence to be checked
search(sequence)
does not returns an empty list,
false otherwisepublic java.util.Iterator<SequenceTree<S,E>> iterator()
next()
.
iterator
in interface java.lang.Iterable<SequenceTree<S,E>>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
protected java.util.Map<S,SequenceTree<S,E>> createSubTreeMapInstance()
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
writeExternal(ObjectOutput)
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
protected void writeTreeSequentially(java.io.ObjectOutput out, SequenceTree<S,E> ost) throws java.io.IOException
java.io.IOException
protected SequenceTree<S,E> readTreeSequentially(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
protected void readAndAssignToThis(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |