|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The basic interface for tree nodes. Each tree item class implementing
this interface inherits methods the for access to a key and a value-object from
interface KeyValueHolder
, which is a superinterface of
TreeItem
. Besides, methods are declared for setting and getting the
TreeItem's
Owner
as well as for access to
child-nodes and the parent-node (like child(int)
, sibling()
or
parent()
). It is possible to check a TreeItem
if it is a leaf,
i.e. it has no child-nodes, or if it is an inner node (having children).
Finally there are methods for setting and getting the maximal rank (the
maximal number of children) and for the connection to other
TreeItems
.
Although BasicTree
, etc. implements Serializable
,
TreeItem
doesn't. Thus you can avoid serialization from list's
using TreeItem
s not implementing Serializable
. Take
care not to forget to implement Serializable
, if you need to.
Field Summary | |
static int |
CLEAR_CONNECTIONS
Clear all connections. |
static int |
CONNECT
Connection to a child node. |
static int |
CONNECT_PARENT
Connection to parent node. |
static int |
LAST_CHILD
Last child node. |
static int |
LEFT
Left child node. |
static int |
PARENT
Parent node. |
static int |
REMOVE
Remove this object from the structure. |
static int |
RIGHT
Rigth child node. |
static int |
SET_BALANCE
Setting balance data. |
static int |
SET_MAX_RANK
Setting the maximal rank (the maximal number of child nodes). |
static int |
SET_OWNER
The Owner shall be set. |
static int |
UNKNOWN
Unknown element. |
Fields inherited from interface gishur.core.KeyValueHolder |
SET_KEY, SET_VALUE |
Method Summary | |
boolean |
answerConnect(TreeItem node,
int pos)
Completes the connection process and should thus only be called by connect(TreeItem, int) .
|
byte |
balance()
Returns this node's balance data. |
TreeItem |
child(int pos)
Returns the child node no. |
boolean |
clearConnections()
Clears all connections starting and ending at this TreeItem . |
java.lang.Object |
clone()
Clones the object flat. |
java.lang.Object |
clone(java.util.Hashtable h,
int level)
Clones the object according to ControlledCloneable . |
boolean |
connect(TreeItem node,
int pos)
Connects this TreeItem to another one given by node ,
setting this node as child no. |
boolean |
cut()
Cuts the partial tree beginning with this node out of the tree. |
Owner |
getOwningTree()
Returns this TreeItem's Owner . |
boolean |
isInner()
Returns true , if this node is an inner node, i.e. has at least
one child node. |
boolean |
isLeaf()
Returns true , if this node is a leaf (i.e. has no child nodes). |
boolean |
isRoot()
Returns true if this node is a root node, i.e. has no parent
node. |
int |
level()
Computes the level in which a node is situated. |
int |
maxRank()
Returns the maximal rank (the maximal number of child nodes). |
int |
nextChildPos(int pos)
Returns the position of the first child-node after position pos ,
which is not null . |
TreeItem |
parent()
Returns the parent node within the structure. |
int |
pos(TreeItem child)
Returns the position at which child is connected to
this TreeItem . |
int |
prevChildPos(int pos)
Returns the position of the last child-node before or at position pos ,
which is not null . |
int |
rank()
Returns this node's rank which is the number of connections to child nodes. |
boolean |
remove()
Removes the node from the tree. |
boolean |
setBalance(byte b)
Sets the balance data for rebalancing operations. |
boolean |
setMaxRank(int mr)
Sets the maximal rank of this node to mr after the Owner
was asked for permission. |
boolean |
setOwningTree(Owner owner)
Defines this TreeItem's Owner . |
TreeItem |
sibling()
Returns this TreeItem's brother node. |
Methods inherited from interface gishur.core.KeyValueHolder |
key, setKey, setValue, value |
Field Detail |
public static final int PARENT
public static final int UNKNOWN
public static final int LAST_CHILD
public static final int LEFT
public static final int RIGHT
public static final int SET_OWNER
Owner
shall be set.public static final int REMOVE
public static final int CLEAR_CONNECTIONS
public static final int CONNECT_PARENT
public static final int CONNECT
public static final int SET_MAX_RANK
public static final int SET_BALANCE
Method Detail |
public java.lang.Object clone()
ListItem
is not connected and has no
owner. The attached keys and objects will not be cloned. They will occure as reference
in the Object.clone
in class java.lang.Object
InternalError
- - if the Object could not be cloned properlypublic java.lang.Object clone(java.util.Hashtable h, int level)
ControlledCloneable
. The new
ListItem
is not connected.h
- Hashtable to indicate which objects are already cloned (see also: ControlledCloneable
)level
- indicates how deep the objects should be cloned (see also: ControlledCloneable
)InternalError
- - if the Object could not be cloned properlypublic boolean setOwningTree(Owner owner)
TreeItem's
Owner
. If there is already
an Owner
, he will be asked for permission. Besides, the new
Owner
will be asked. The operation only takes place, if
both agreed.
If old and new Owner
are the same, no one will be asked for
permission and true
will be returned.owner
- new Owner
true
, if operation was allowed and performed
successfullypublic Owner getOwningTree()
TreeItem's
Owner
.Owner
public byte balance()
public boolean setBalance(byte b)
Owner
will
be ased for permission.b
- new balance-valuetrue
, if the operation was allowed and performed
successfullypublic TreeItem parent()
TreeItem
public TreeItem child(int pos)
pos
within the surrounding
structure. If pos==PARENT
, the parent node will be returned.pos
- the position at which the requested node is attached to its
parentpublic TreeItem sibling()
TreeItem's
brother node. This method is
especially use- and senseful with binary trees. Otherwise, the symmetric
brother will be returned.public int pos(TreeItem child)
child
is connected to
this TreeItem
. If PARENT
is returned, child
is this node's parent node. Otherwise, either UNKNOWN
will be
returned, if child
was not found to be a child node
to this
or the position of child
will be
returned.child
- a TreeItem
whose position at this node shall be
returnedchild
's position or PARENT
or UNKNOWN
public int nextChildPos(int pos)
pos
,
which is not null
. If there is no such child or pos==LAST_CHILD,
UNKNOWN
is returned. If pos==UNKNOWN
or pos==PARENT
,
the position of the first child which is not null
will be returned.pos
- position from which the search for the next child-node starts!=null
public int prevChildPos(int pos)
pos
,
which is not null
. If there is no such node, UNKNOWN
will be returned.
If pos==LAST_CHILD, pos==UNKNOWN
or pos==PARENT
, the
child!=null
with the largest pos
value is returned.pos
- position before and at which to search for a child-nodenull
, or UNKNOWN
public boolean isLeaf()
true
, if this node is a leaf (i.e. has no child nodes).true
, if the node is a leafpublic boolean isInner()
true
, if this node is an inner node, i.e. has at least
one child node.true
, if this node has at least one child nodepublic boolean isRoot()
true
if this node is a root node, i.e. has no parent
node.true
, if this node is a rootpublic int rank()
public int maxRank()
public int level()
public boolean setMaxRank(int mr)
mr
after the Owner
was asked for permission. If access was granted and the operation has been performed
successfully, true
is returned.mr
- new maximal ranktrue
, if the Owner
allows the operation and it was
successfully performedpublic boolean answerConnect(TreeItem node, int pos)
connect(TreeItem, int)
.
The Owner
must not be asked for permission again (all necessary
tests are performed by connect(TreeItem, int)
, but answerConnect(TreeItem, int)
needs
to ensure that it was called by connect(TreeItem, int)
. This is possible by
checking if 'half' the connection has been established yet.node
- the node which should become the parent for this TreeItem
pos
- position to which this TreeItem
shall be connectedtrue
, if the connection was allowed and successfully performedpublic boolean connect(TreeItem node, int pos)
TreeItem
to another one given by node
,
setting this node as child no. pos
to node
.
It is only possible to connect two nodes belonging to the same
structure. To establish a correct connection, answerConnect(TreeItem, int)
is
called by node
. If the connection is not allowed by
the Owner
or if an error occurrs while connecting, false
is returned. If pos==PARENT, node
will be ignored and the
TreeItem
is connected to null
as parent.node
- node to connect this
as child topos
- the position to which this
shall be connected as child of node
true
, if the connection is allowed and performed successfullypublic boolean cut()
owning tree
is asked for permission only by the
parent node, if it is allowed to set its son's parent connection to
null
, all other connections remain untouched.true
, if cutting off the partial tree was allowed and
performed successfullypublic boolean remove()
rank()<2
,
that means if this node has maximally one child. If it has a child, this will be
connected in its parent's position.
The balance value is set to 0, if the removal was successful.true
, if the removal was allowed and successfulpublic boolean clearConnections()
TreeItem
. Thus the
connections will not be removed correctly. In difference to remove()
there
will be only one request for permission to the Owner
! The Owner
himself will not be changed. This TreeItem's
balance value will
be cleared as well.true
, if successful
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |