|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gishur.core.BasicTreeItem
Most simple TreeItem
. All methods of TreeItem
are implemented
correctly. A simple BasicTreeItem
is not able to store a key or a value.
It is the basis class for SimpleTreeItem
and StdTreeItem
.
Fields inherited from interface gishur.core.TreeItem |
CLEAR_CONNECTIONS, CONNECT, CONNECT_PARENT, LAST_CHILD, LEFT, PARENT, REMOVE, RIGHT, SET_BALANCE, SET_MAX_RANK, SET_OWNER, UNKNOWN |
Fields inherited from interface gishur.core.KeyValueHolder |
SET_KEY, SET_VALUE |
Fields inherited from interface gishur.core.ControlledCloneable |
DEEP, FLAT |
Constructor Summary | |
BasicTreeItem(int maxrank)
Creates a TreeItem that is able to own up to maxrank
children. |
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 the balance value of this node. |
TreeItem |
child(int pos)
Returns the child-node at position pos within the
tree structure. |
boolean |
clearConnections()
Clears all connections starting and ending at this TreeItem . |
java.lang.Object |
clone()
Clones the object. |
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. |
boolean |
equals(java.lang.Object object)
Compares two TreeItems . |
Owner |
getOwningTree()
Returns the Owner of this ListItem |
boolean |
isInner()
Returns true , if this node is an inner node (that
means that it has at least one child-node). |
boolean |
isLeaf()
Returns true if this node is a leaf (has no children). |
boolean |
isRoot()
Returns true , if this node is a root (that means that
it has no parent-node). |
java.lang.Object |
key()
Returns the stored key of this object. |
int |
level()
Returns the level of the tree in wich this TreeItem is positioned.
|
int |
maxRank()
Returns the maximal rank of this TreeItem . |
int |
nextChildPos(int pos)
Returns the position of the first child-node after position pos ,
which is not null . |
TreeItem |
parent()
Returns the father-node within the tree structure. |
int |
pos(TreeItem child)
Returns the position of the node child in this node.
|
int |
prevChildPos(int pos)
Returns the position of the last child-node before or at position pos ,
which is not null . |
int |
rank()
Returns the rank of this node, which is the number of children connected to this node (each node except for the root has only one parent, so the parent does not increase the rank). |
boolean |
remove()
Removes the node from the tree. |
protected boolean |
requestTreeAccess(int accesstype,
java.lang.Object argument)
Asks the Owner for permission to perform an operation of
type accesstype with the argument argument . |
boolean |
setBalance(byte b)
Sets the balance value, if the Owner permits it. |
boolean |
setKey(java.lang.Object key)
Sets the key of this TreeItem . |
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 the Owner for this TreeItem . |
boolean |
setValue(java.lang.Object object)
Stores the object object into this node. |
TreeItem |
sibling()
Returns the brother-node. |
java.lang.String |
toString()
Overrides Object.toString() . |
java.lang.Object |
value()
Returns the stored value. |
Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public BasicTreeItem(int maxrank)
TreeItem
that is able to own up to maxrank
children.maxrank
- maximal rank, that means the maximal number of children-nodesMethod Detail |
public boolean equals(java.lang.Object object)
TreeItems
. They are only equal, if their
keys are equal in the sense of the java.lang.Object.equals(Object)
-method.
equals(Object)
returns true
, if this
and object
are references to the same object, if object.equals(key())
returns
true
or if object
is a TreeItem
and is equal to
this TreeItem
.
This method overrides java.lang.Object.equals(Object)
.equals
in class java.lang.Object
object
- object to compare with this
object's keytrue
, if both are equalpublic java.lang.String toString()
Object.toString()
.toString
in class java.lang.Object
public java.lang.Object clone()
TreeItem
is not connected
and has no owner. The attached keys and values will be cloned
as well.clone
in interface TreeItem
clone
in class java.lang.Object
TreeItem
InternalError
- - if the Object could not be cloned properlyCloneable
public java.lang.Object clone(java.util.Hashtable h, int level)
ControlledCloneable
. The new
TreeItem
is not connected.clone
in interface TreeItem
h
- Hashtable to indicate which objects are already clonedlevel
- indicates how deep the objects should be clonedInternalError
- - if the Object could not be cloned properlyControlledCloneable
public boolean setOwningTree(Owner owner)
Owner
for this TreeItem
. If it is already owned, the
old Owner
is asked for permission. Additionally, the new owner will be
asked for permission. The change takes place if both agree.
If the old and the new Owner
are the same, true
will be returned.setOwningTree
in interface TreeItem
owner
- new Owner
true
, if the owner
was set as new Owner
successfullypublic Owner getOwningTree()
Owner
of this ListItem
getOwningTree
in interface TreeItem
Owner
protected boolean requestTreeAccess(int accesstype, java.lang.Object argument)
Owner
for permission to perform an operation of
type accesstype
with the argument argument
.accesstype
- type of operation (that means type of access)argument
- argument of the requested operationtrue
, if the Owner
allows the operation, false
otherwisepublic byte balance()
balance
in interface TreeItem
public boolean setBalance(byte b)
Owner
permits it.setBalance
in interface TreeItem
b
- new balance valuetrue
, if the operation has been successful, false
, if the
Owner
denied access to the balance valuepublic TreeItem parent()
parent
in interface TreeItem
public TreeItem child(int pos)
pos
within the
tree structure. If pos==PARENT
, the father-node will be
returned.child
in interface TreeItem
pos
- position of the child-node to be returnedpublic TreeItem sibling()
maxRank()-1-_parent.pos(this)
) is returned.
Liefert den Bruder des aktuellen Knotens. Das macht vor allem Sinnsibling
in interface TreeItem
public int pos(TreeItem child)
child
in this node.
If PARENT
is returned, child
is the father-node.
If child
was not found among the child-nodes of this
,
UNKNOWN
is returned, otherwise the position of child
.pos
in interface TreeItem
child
- TreeItem
whose position as child of this
node is requestedchild
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.nextChildPos
in interface TreeItem
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.prevChildPos
in interface TreeItem
pos
- position before and at which to search for a child-nodenull
, or UNKNOWN
public boolean isLeaf()
true
if this node is a leaf (has no children).isLeaf
in interface TreeItem
true
, if this node is a leafpublic boolean isInner()
true
, if this node is an inner node (that
means that it has at least one child-node).isInner
in interface TreeItem
true
, if this node has at least one childpublic boolean isRoot()
true
, if this node is a root (that means that
it has no parent-node).isRoot
in interface TreeItem
true
, if this node is a rootpublic int rank()
rank
in interface TreeItem
public int maxRank()
TreeItem
.maxRank
in interface TreeItem
public int level()
TreeItem
is positioned.
The root is on level 0, their children on level 1 etc.level
in interface TreeItem
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.setMaxRank
in interface TreeItem
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.answerConnect
in interface TreeItem
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.connect
in interface TreeItem
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.cut
in interface TreeItem
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.remove
in interface TreeItem
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.clearConnections
in interface TreeItem
true
, if successfulpublic java.lang.Object key()
key
in interface KeyValueHolder
public boolean setKey(java.lang.Object key)
TreeItem
.setKey
in interface KeyValueHolder
key
- new keytrue
, if the action has been allowed and performed successfullypublic java.lang.Object value()
value
in interface KeyValueHolder
TreeItem
public boolean setValue(java.lang.Object object)
object
into this node.setValue
in interface KeyValueHolder
object
- object to become the new value.true
, if the action has been allowed and performed successfully
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |