gishur.core
Class BasicListItem

java.lang.Object
  |
  +--gishur.core.BasicListItem
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, ControlledCloneable, KeyValueHolder, ListItem, java.io.Serializable
Direct Known Subclasses:
SimpleListItem, StdListItem

public class BasicListItem
extends java.lang.Object
implements ListItem, ControlledCloneable, java.io.Serializable

Basic ListItem, which only contains connections and an owner, but no object or key.

Version:
1.1
Author:
Thomas Wolf
See Also:
Serialized Form

Fields inherited from interface gishur.core.ListItem
CLEAR_CONNECTIONS, CONNECT_BACKWARD, CONNECT_FORWARD, REMOVE, SET_OWNER
 
Fields inherited from interface gishur.core.KeyValueHolder
SET_KEY, SET_VALUE
 
Fields inherited from interface gishur.core.ControlledCloneable
DEEP, FLAT
 
Constructor Summary
BasicListItem()
           
 
Method Summary
 boolean answerConnect(ListItem link, boolean forward)
          Completes the connection and should therefore only be called by connect(link,forward).
 boolean clearConnections()
          Deletes all connections originating from this ListItem.
 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(ListItem link, boolean forward)
          Connects this ListItem to the ListItem link.
 boolean equals(java.lang.Object object)
          Compares two ListItems.
 ListItem find(java.lang.Object O)
          Searches for object O in the chain.
 ListItem findFirst()
          Searches for the first ListItem of the chain and returns that ListItem.
 ListItem findLast()
          Searches for the last ListItem of the chain and returns that ListItem.
 int getIndex(boolean fromStart)
          Calculates the index of this ListItem within the chain, beginning from the first or the last element.
 Owner getOwningList()
          Returns the owner of the ListItem.
 boolean isFirst()
          Tests if the ListItem is the first element of a chain.
 boolean isLast()
          Tests if the ListItem is the last element of a chain.
 java.lang.Object key()
          Returns the stored key of the object.
 ListItem next()
          Returns the next connected ListItem.
 ListItem prev()
          Returns the previous ListItem.
 boolean remove()
          Deletes the connections to other ListItems. {
protected  boolean requestListAccess(int accesstype, java.lang.Object argument)
          Asks the owner for permission to perform an action of the type accesstype with the argument argument.
 boolean setKey(java.lang.Object key)
          Sets the key
 boolean setOwningList(Owner owner)
          Sets the owner of the ListItem.
 boolean setValue(java.lang.Object object)
          Stores the object object.
 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

BasicListItem

public BasicListItem()
Method Detail

equals

public boolean equals(java.lang.Object object)
Compares two ListItems. Two ListItems are equal, if their keys are equal (according to their equals-function). true is returned, if object refers to this, object.equals(key()) returns true, or object is a ListItem which is identical to this ListItem Overrides Object.equals()
Overrides:
equals in class java.lang.Object
Parameters:
object - to be compared to
Returns:
true, if successful

toString

public java.lang.String toString()
Overrides Object.toString().
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Clones the object flat. The following result should be achieved: The new ListItem is not connected and has no owner. The attached keys and values will be cloned as well.
Specified by:
clone in interface ListItem
Overrides:
clone in class java.lang.Object
Returns:
cloned object
See Also:
Cloneable

clone

public java.lang.Object clone(java.util.Hashtable h,
                              int level)
Clones the object according to ControlledCloneable. The new ListItem is not connected. If level==ControlledCloneable.FLAT, the key and value of this BasicListItem are not cloned, but their original references are given as key and value to the new BasicListItem.
Specified by:
clone in interface ListItem
Parameters:
h - Hashtable to indicate which objects are already cloned
level - indicates how deep the objects should be cloned
Returns:
cloned object
Throws:
InternalError - if the Object could not be cloned properly
java.lang.IllegalAccessException - if an element was encountered, which implemented the java.lang.Cloneable-interface, but whose clone-method was not public
See Also:
ControlledCloneable

setOwningList

public boolean setOwningList(Owner owner)
Sets the owner of the ListItem. If an owner already exists, he is asked for permission. The new owner is also asked for permission. A change only occurs, if both agree. If the old and the new owner is the same object, no one is asked for permission and true is returned. Connections remain untouched by the change.
Specified by:
setOwningList in interface ListItem
Parameters:
owner - new owner
Returns:
true, if the change is successful

getOwningList

public Owner getOwningList()
Returns the owner of the ListItem.
Specified by:
getOwningList in interface ListItem
Returns:
the owner

requestListAccess

protected boolean requestListAccess(int accesstype,
                                    java.lang.Object argument)
Asks the owner for permission to perform an action of the type accesstype with the argument argument.
Parameters:
accesstype - specifies the action
argument - argument of the action
Returns:
true, if the owner permits the action, else false

next

public ListItem next()
Returns the next connected ListItem.
Specified by:
next in interface ListItem
Returns:
next ListItem

prev

public ListItem prev()
Returns the previous ListItem.
Specified by:
prev in interface ListItem
Returns:
previous ListItem

findFirst

public ListItem findFirst()
Searches for the first ListItem of the chain and returns that ListItem.
Specified by:
findFirst in interface ListItem
Returns:
first ListItem of the chain

findLast

public ListItem findLast()
Searches for the last ListItem of the chain and returns that ListItem.
Specified by:
findLast in interface ListItem
Returns:
last ListItem of the chain

isFirst

public boolean isFirst()
Tests if the ListItem is the first element of a chain.
Specified by:
isFirst in interface ListItem
Returns:
true, if the ListItem is the first object of the chain

isLast

public boolean isLast()
Tests if the ListItem is the last element of a chain.
Specified by:
isLast in interface ListItem
Returns:
true, if the ListItem is the last ListItem of the chain

find

public ListItem find(java.lang.Object O)
Searches for object O in the chain.
Specified by:
find in interface ListItem
Parameters:
O - object to be found
Returns:
found ListItem object or null, if search not successful.

getIndex

public int getIndex(boolean fromStart)
Calculates the index of this ListItem within the chain, beginning from the first or the last element.
Specified by:
getIndex in interface ListItem
Parameters:
fromStart - if true then the first element has index 0, else the last element has index 0

answerConnect

public boolean answerConnect(ListItem link,
                             boolean forward)
Completes the connection and should therefore only be called by connect(link,forward). Here the owner may not again be asked for permission (all the necessary tests were already conducted by connect(link,forward)), but answerConnect must make sure that it can only be called by connect. This can be achieved for example, by testing if a 'half connection' is already established.
Specified by:
answerConnect in interface ListItem
Parameters:
link - ListItem, with which a connection should be established
forward, - direction of the connection (forward, if true)
Returns:
true, if connection successful

connect

public boolean connect(ListItem link,
                       boolean forward)
Connects this ListItem to the ListItem link. This is a forward connection, if forward==true, otherwise it is a backward connection. To achieve a double connection, the method answerConnect(link,forward) of the ListItem link is called (if link!=null). The owner is asked for permission before the connection takes place. For two ListItems to be connected, they must both have the same owner.
Specified by:
connect in interface ListItem
Parameters:
link - ListItem with which this is to be connected
forward, - direction of the connection (forward, if true)
Returns:
true, if connection is permitted and successful.

remove

public boolean remove()
Deletes the connections to other ListItems. prev() is directly connected to next(). After the operation this will be ownerless.
Specified by:
remove in interface ListItem
Returns:
true, if remove() is permitted and successful.

clearConnections

public boolean clearConnections()
Deletes all connections originating from this ListItem. The connections are not removed completely (in both directions). In contrast to remove() the owner is asked only once for permission! The owner remains unchanged.
Specified by:
clearConnections in interface ListItem
Returns:
true, if successful

key

public java.lang.Object key()
Returns the stored key of the object.
Specified by:
key in interface KeyValueHolder
Returns:
key

setKey

public boolean setKey(java.lang.Object key)
Sets the key
Specified by:
setKey in interface KeyValueHolder
Parameters:
key - new key

value

public java.lang.Object value()
Returns the stored value.
Specified by:
value in interface KeyValueHolder
Returns:
stored object

setValue

public boolean setValue(java.lang.Object object)
Stores the object object.
Specified by:
setValue in interface KeyValueHolder
Parameters:
object - object to be stored