|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--gishur.core.BasicList
A rudimentary and efficient doubly connected list. Its purpose is
to be used as the basis for the development of other List classes.
All the methods of BasicList are protected, which means
they are accessible from derived classes (and from classes of the same
package), but not from extern classes! The access on ListItems
is very restrictive: changes to the connections between the
ListItems and to their owners are prevented. To modify a
ListItem in a derived class allowAccess(ANY_ACCESS)
should be called first and after the modification
allowAccess(NO_ACCESS) should be executed.
To permit methods to read data from an object of a class, which is
derived from BasicList, the public method getListView() can be overrode, which then returns a ListView object.
The same security mechanisms, with which ListItems certify that they
can only be modified by the owning list, make sure that a ListView
object can only be created from the owning list - if getListView()
is overridden properly.
This makes controlled read access possible and data can be hidden and shown as
required.
As this class is only intended to be used as basis for other list classes, all
methods are protected and most of them receive a lot of parameters.
Often a list interval is handed over as argument, which is specified by a first
element and either the length, or the last element of the interval. If the
length is specified, the last element should be null, if a last
element is used to confine the interval, length should be a negative value.
add(base,start,end,-1) connects the
interval from start to end to the element
base of the list, add(base,start,null,3)
on the other side connects start and the next two elements, which
are connected to start, to base.
BasicList implements Serializable, ListItem
doesn't. If you want to derive a list which works correct with serialization, pay
attention to use ListItems which implement the Serializable interface.
ListItem, Serialized Form| Field Summary | |
static byte |
ANY_ACCESS
Allow any access. |
protected static byte |
KEY
Access to the key. |
protected static byte |
LISTITEM
Access to the ListItem object. |
static byte |
NO_ACCESS
Allows no access (default). |
protected static byte |
VALUE
Access to the value. |
| Constructor Summary | |
protected |
BasicList()
Protected constructor. |
| Method Summary | |
protected int |
add(ListItem base,
ListItem[] array,
int startindex,
int length)
Inserts length ListItems from the ListItem array
array beginning with the index startindex after the
ListItem base. |
protected int |
add(ListItem base,
ListItem item,
ListItem end,
int count)
Inserts an existing chain of the maximum length count beginning
with item after the element base into the list. |
protected void |
allowAccess(byte accesskonst)
Permits the (temporary) access to ListItems |
protected void |
clear()
Deletes the whole list. |
protected java.lang.Object |
clone(java.util.Hashtable h,
int level)
Clones the entire list according to ControlledCloneable. |
protected boolean |
contains(ListItem item)
Returns true, if the list contains the ListItem
item. |
protected ListItem |
copy(ListItem start,
ListItem end,
int count)
Returns a copy of the chain of ListItems beginning with start and ending with end or containing not more
than count elements altogether. |
protected ListItem |
copy(ListItem start,
ListItem end,
int count,
boolean cyclic)
Returns a copy of the chain of ListItems beginning with start and ending with end or containing not more
than count elements altogether. |
protected ListItem |
copy(ListItem start,
ListItem end,
int count,
boolean cyclic,
java.util.Hashtable h,
int level)
Returns a copy of the chain of ListItems beginning with start and ending with end or containing not more
than count elements altogether. |
protected int |
cut(ListItem start,
ListItem end,
int count)
Cuts the chain beginning with start and ending with
end or after count
steps (if count>0) from the list. |
protected void |
cycle(int dist)
A cyclic Left shift for dist ListItems. (if
dist<0, a right shift is performed) |
protected void |
cycle(ListItem item)
Performs a cyclic shift until item is the first element of the
list. |
protected boolean |
empty()
Returns true, if the list is empty. |
protected java.util.Enumeration |
enumerate(ListItem start,
ListItem end,
int count,
byte objecttype)
Returns an Enumeration object, which enumerates the specified interval. |
boolean |
equals(java.lang.Object O)
Compares two lists. |
protected ListItem |
find(java.lang.Object O,
ListItem start,
ListItem end,
int count,
boolean cyclic)
Returns the ListItem from the interval between start and
end with the maximum length count (if
count>0), for which equals(O) is
true. |
protected ListItem |
findClass(java.lang.Class C,
int app,
ListItem start,
ListItem end,
int count,
boolean cyclic)
Returns the app-th ListItem from the interval between
start and end with the maximum length
count (if count>0), which contains an object of
class C as key. |
protected ListItem |
findClosest(java.lang.Object key,
Comparitor comparitor,
short compare,
ListItem start,
ListItem end,
int count,
boolean cyclic)
Searches a certain part of the list for the ListItem which comes
'closest' to key by using the Comparitor
comparitor. |
protected ListItem |
first()
Returns the first ListItem of the list. |
protected int |
getDistance(ListItem i,
ListItem j)
Returns the distance of the ListItems i and
j in the list. |
protected int |
getIndex(ListItem i,
boolean fromStart)
Calculates the index of the ListItem i in the list,
counting from the first or the last element. |
protected ListItem |
getListItem(ListItem base,
int count,
boolean cyclic)
Returns the ListItem, which is count steps away from
base in the list. |
protected ListItem[] |
getListItemArray(ListItem start,
ListItem end,
int count,
boolean cyclic)
Returns an interval from the list as array. |
protected java.lang.String |
getListString(java.lang.String separator,
int width,
int itemmode,
int expandlevel,
boolean len,
boolean reverse)
Returns the string representation of all the elements in the list. the list elements are separated by a separator string and there is a
newline after roughly every width characters if
width>0. |
ListView |
getListView()
Creates a ListView object which allows read access to the list structure, even if the type is not explicitly known. |
protected ListItem |
last()
Returns the last ListItem of the list. |
protected int |
length()
Returns the number of elements stored in the list. |
protected void |
move(ListItem start,
ListItem end,
int count,
ListItem base)
Moves a given chain of the list to another position. |
protected int |
reconnect(ListItem base,
ListItem[] array,
int startindex,
int length)
Inserts an interval from an array of ListItems into the list. |
protected int |
reconnect(ListItem base,
ListItem start,
ListItem end,
int count)
Inserts the chain of ListItems connected (forwards) to start, which may not contain more than count
elements, after base into the list. |
protected int |
remove(ListItem start,
ListItem end,
int count)
Removes the chain beginning with start and ending with
end or after count steps (if
count>0) from the list. |
boolean |
requestAccess(int accesstype,
java.lang.Object who,
java.lang.Object argument)
The owned object who asks the owner for permission to perform
an action of the type accesstype with the parameter
argument. { |
protected void |
reverse(ListItem start,
ListItem end,
int count)
Reverses the order of the ListItems in the interval from start to end. |
protected int |
storeInArray(java.lang.Object[] array,
int startindex,
int length,
ListItem start,
byte objecttype,
boolean cyclic)
Stores a part of the list into an array. |
java.lang.String |
toString()
Returns a string representation of the object. |
java.lang.String |
toString(boolean len,
int itemmode,
int expandlevel)
Returns a string representation of this list. |
protected int |
unconnect(ListItem start,
ListItem end,
int count)
Unconnects the chain beginning with start and ending with
end or after count steps, if
count>0, from the list. |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
public static final byte NO_ACCESS
public static final byte ANY_ACCESS
protected static final byte LISTITEM
ListItem object.protected static final byte KEY
protected static final byte VALUE
| Constructor Detail |
protected BasicList()
| Method Detail |
protected java.lang.String getListString(java.lang.String separator,
int width,
int itemmode,
int expandlevel,
boolean len,
boolean reverse)
separator string and there is a
newline after roughly every width characters if
width>0. If width<0, then a newline is added
every abs(width) ListItems, if width==0,
then no newlines are inserted.separator - separator string between the ListItemswidth - width of a row in characters or number of ListItems per
line or no newlineitemmode - if ==1, only the keys are added to the string,==2 keys and values are added==3 the complete ListItems are addedexpandlevel - meaningless, if <0, else it describes
the depth of recursion for lists containing lists,==0 means no further list itemslen - determines if the length of the list should be returnedreverse - if true, the list will be read in the reverse
direction
public java.lang.String toString(boolean len,
int itemmode,
int expandlevel)
this list.len - if true include the lengthitemmode - if ==1, only the keys are added to the string,==2 keys and values are added==3 the complete ListItems are addedexpandlevel - meaningless, if <0, else it describes
the depth of recursion for lists containing lists,==0 means no further list itemspublic java.lang.String toString()
public boolean equals(java.lang.Object O)
i-th element of the first list equals
the i-th element of the second list.O - object to which this will be comparedtrue, if the objects are epualObject.equals(java.lang.Object)
protected java.lang.Object clone(java.util.Hashtable h,
int level)
ControlledCloneable. That means,
all ListItems are cloned and connected proper.BasicList does not implement the Interface ControlledCloneable,
but supports its methods!h - Hashtable to indicate which objects are already clonedlevel - indicates how deep the objects should be clonedControlledCloneableprotected int length()
protected boolean empty()
true, if the list is empty.true, if the list is empty.protected ListItem first()
ListItem of the list.ListItemprotected ListItem last()
ListItem of the list.ListItemprotected boolean contains(ListItem item)
true, if the list contains the ListItem
item. The test is performed in constant running time.item - to be testedtrue, if the item is contained in the list.
protected ListItem getListItem(ListItem base,
int count,
boolean cyclic)
ListItem, which is count steps away from
base in the list. If cyclic is true the
list is considered to be a cyclic list. If count is negative, the
search direction is backward, otherwise it is forward.
This method returns null, if base is not contained
in the list or the confines of the list are exceeded (only if
cyclic==false). If base==null and
count>=0 the starting point is the first ListElement. If
base==null and count<0 it is the last element.base - ListItem, to be started with.
protected int getIndex(ListItem i,
boolean fromStart)
ListItem i in the list,
counting from the first or the last element. If i is not
contained within the list, -1 is returned.i - ListItem, the index of which will be calculated.fromStart - if true, the first element has index 0,
otherwise the last element has index 0.
protected int getDistance(ListItem i,
ListItem j)
i and
j in the list. A positive return value means, that j
can be reached from i by stepping forwards through the list, a
negative value indicates, that j can be reached by stepping
backwards.
If i or j is not contained within the list (or
unreachable for any other reason) the integer Integer.MAX_VALUE
is returned.i,j - ListItems, whose distance will be calculated.
protected ListItem find(java.lang.Object O,
ListItem start,
ListItem end,
int count,
boolean cyclic)
ListItem from the interval between start and
end with the maximum length count (if
count>0), for which equals(O) is
true. If end==null then end is the last
list element. The list is considered to be a cyclic list, if
cyclic==true.O - object to be looked forstart - first ListItem of the interval.end - last ListItem of the interval (if !=null)count, - maximum number of ListItems in the interval, if
>0cyclic - if true, the list is considered to be cyclic.ListItem or null.
protected ListItem findClosest(java.lang.Object key,
Comparitor comparitor,
short compare,
ListItem start,
ListItem end,
int count,
boolean cyclic)
ListItem which comes
'closest' to key by using the Comparitor
comparitor. If compare==Comparitor.EQUAL,
only one ListItem is returned, whose comparison returned Comparitor.EQUAL. When using Comparitor.BIGGER the smallest ListItem which is bigger than key is returned, when using Comparitor.SMALLER the biggest smaller ListItem is returned. If
findClosest(java.lang.Object, gishur.core.Comparitor, short, gishur.core.ListItem, gishur.core.ListItem, int, boolean) is called with comparitor==null, then a
default comparitor is used.start, end, count and
cyclic describe the list interval. If key is a
ListItem, then ListItems are compared, otherwise keys are
compared. If key==null the maximum value is searched for when
compare==Comparitor.BIGGER and the minimum value is
searched for, when compare==Comparitor.SMALLER (Comparitor.EQUAL leads to no sensible result if key==null).key - object to be compared tocomparitor - comparitor objectcompare - the type of the comparison:
if Comparitor.EQUAL, equal objects are searched for,Comparitor.BIGGER or Comparitor.SMALLER
the smallest bigger or the biggest smaller object is searched
for respectively.start - first ListItem of the interval.end - last ListItem of the interval (if !=null)count, - maximum number of ListItems in the interval, if
>0cyclic - if true, the list is considered to be cyclic.ListItem or null.
protected ListItem findClass(java.lang.Class C,
int app,
ListItem start,
ListItem end,
int count,
boolean cyclic)
app-th ListItem from the interval between
start and end with the maximum length
count (if count>0), which contains an object of
class C as key. If end==null (and
count<0) then end is the last list element. The
list is considered to be a cyclic list, if cyclic==true.C - class of the object searched forapp - required number of occurrences of the searched for objectstart - first ListItem of the interval.end - last ListItem of the interval (if !=null)count, - maximum number of ListItems in the interval, if
>0cyclic - if true, the list is considered to be cyclic.ListItem or null.
protected ListItem[] getListItemArray(ListItem start,
ListItem end,
int count,
boolean cyclic)
cyclic==false, the
interval between start and end (or vice versa, if
end comes before start) is returned. If
cyclic==true, the list is treated as a cyclic list and the first
element of the array is always start. start and
end must both be elements of
the list and be reachable from each other, otherwise null is
returned. If start==null, then start is set to
first(), if end==null, count objects or (if
count<0) all the elements to the end of the list are copied
into the array.start - first ListItem of the interval.end - last ListItem of the interval (if !=null)count, - maximum number of ListItems in the interval, if
>0cyclic - if true, the list is considered cyclic
protected int storeInArray(java.lang.Object[] array,
int startindex,
int length,
ListItem start,
byte objecttype,
boolean cyclic)
storeInArray also works
with chains of ListItems, which do not belong to the list or are not
connected to the rest of the stored objects. But cyclic should
not be true in this case. If start==null, then
start is set to first().array - into which the objects will be storedstartindex - the starting index of the arraylength - number of objects to be storedstart - first ListItem to be storedobjecttype - indicates, which object type will de stored: objecttype==LISTITEM the whole ListItems are
stored objecttype==KEY the KeyValueHolder.key()
objects of the ListItems are stored objecttype==VALUE the KeyValueHolder.value() objects of the ListItems
are storedcyclic - if true, the list is considered cyclic
protected ListItem copy(ListItem start,
ListItem end,
int count)
start and ending with end or containing not more
than count elements altogether. If start==0,
start is set to {link#first()}. if count<0, the
interval ends with end (or {link#last()}, if
end==null). The new List has no owner. The objects contained
within the Listitems are not cloned.start - first element of the intervalend - last element of the interval, if end!=nullcount, - maximum number of ListItems in the interval, if
>=0
protected ListItem copy(ListItem start,
ListItem end,
int count,
boolean cyclic)
start and ending with end or containing not more
than count elements altogether. If start==0,
start is set to {link#first()}. if count<0, the
interval ends with end (or {link#last()}, if
end==null). The new List has no owner. The objects contained
within the Listitems are not cloned.start - first element of the intervalend - last element of the interval, if end!=nullcount, - maximum number of ListItems in the interval, if
>=0cyclic - if true, the list is considered to be cyclic
protected ListItem copy(ListItem start,
ListItem end,
int count,
boolean cyclic,
java.util.Hashtable h,
int level)
start and ending with end or containing not more
than count elements altogether. If start==null,
start is set to {link#first()}. if count<0, the
interval ends with end (or {link#last()}, if
end==null). The new List has no owner. The objects contained
within the ListItems are cloned according to level and h
in ControlledCloneable.start - first element of the intervalend - last element of the interval, if end!=nullcount, - maximum number of ListItems in the interval, if
>=0h - Hashtable to indicate which objects are already clonedlevel - indicates how deep the objects should be clonedcyclic - if true, the list is considered to be cyclicControlledCloneable
protected java.util.Enumeration enumerate(ListItem start,
ListItem end,
int count,
byte objecttype)
start - first element of the interval (if ==null, start is
set to first())end - last element of the intervalcount - maximum number of elements in the intervalobjecttype - constant to spicify the return value of
nextElement() (i.e. KEY, VALUE or LISTITEM).
protected int add(ListItem base,
ListItem item,
ListItem end,
int count)
count beginning
with item after the element base into the list. If
base==null, the chain is inserted at the beginning of the
list.ListItem.setOwningList(gishur.core.Owner)
could set the owner of the new ListItems successfully. If ListItem.setOwningList(gishur.core.Owner) was unsuccessful for an ListItem, this item is
cloned (flat) with ListItem.clone() and the copy is inserted instead, provided
ListItem.setOwningList(gishur.core.Owner) allows a change of the owner of this copy (this
should normally be no problem, otherwise the process is aborted).
The length of the list is increased by the number of objects inserted. The
number of inserted items is returned.base - ListItem, after which the new items will be
inserted or null, if the new interval is to be inserted at the beginning of
the listitem - ListItem or interval of ListItems, which should
be insertedend - end of the interval, which should be inserted if
end!=nullcount - maximum number of ListItems to be inserted. If
count<0, the whole interval is inserted.
protected int add(ListItem base,
ListItem[] array,
int startindex,
int length)
length ListItems from the ListItem array
array beginning with the index startindex after the
ListItem base. If base==0, the items are
inserted at the beginning of the list. The ListItems are inserted
directly, if ListItem.setOwningList(gishur.core.Owner) could set the owner of the new
ListItems successfully. If ListItem.setOwningList(gishur.core.Owner) was
unsuccessful for an ListItem, this item is cloned (flat) with clone() and the
copy is inserted instead, provided ListItem.setOwningList(gishur.core.Owner) allows a
change of the owner of this copy (this should normally be no problem,
otherwise this ListItem is ignored, but the other objects may still be
inserted). The length of the list is increased by the number of elements
inserted.base - ListItem, after which the new elements are insertedarray - array of ListItemsstartindex - the starting index in the arraylength - maximum number of elements from the array to be inserted
protected int reconnect(ListItem base,
ListItem start,
ListItem end,
int count)
start, which may not contain more than count
elements, after base into the list. All the elements of the chain
should already belong to the list! If this is not the case, a failure will
occur while connecting and a LinkException will be thrown. base
should also belong to the list. If base==null, the chain is
attached to the beginning of the list. This method does not change the number
of elements in the list!base - ListItem, after which should be insertedstart - ListItem or chain of ListItems to be insertedend - end of the interval, which should be inserted (if
end!=null)count - maximum number of ListItems to be inserted. If
count<0, the whole interval is inserted from
start to end (if end!=null) or to the
last element of the chain.
protected int reconnect(ListItem base,
ListItem[] array,
int startindex,
int length)
base should also belong
to the list. If base==null, the chain is attached to the
beginning of the list. This method does not change the number of elements in
the list!base - ListItem, after which should be insertedarray - array of ListItems to be insertedstartindex - the starting index in the arraylength - maximum number of elements from the array to be inserted
protected int cut(ListItem start,
ListItem end,
int count)
start and ending with
end or after count
steps (if count>0) from the list. The number of actually cut
away ListItems is returned.start - first ListItem to be cut awayend - last ListItem to be cut awaycount - maximum number of ListItems to be cut away, if
>0
protected int remove(ListItem start,
ListItem end,
int count)
start and ending with
end or after count steps (if
count>0) from the list. If references to the removed ListItems exist, these ListItems still contain their data, but are no
longer connected.start - first ListItem to be removedend - last ListItem to be removedcount - maximum number of ListItems to be removed, if
>0
protected int unconnect(ListItem start,
ListItem end,
int count)
start and ending with
end or after count steps, if
count>0, from the list. This does not change the
number of the list elements.start - first ListItem to be unconnectedend - last ListItem to be unconnectedcount - maximum number of ListItems to be unconnected, if
>0protected void clear()
ListItem
implementations), they are catched and the list is deleted anyway. (In this
case ListItems may remain that pretendedly belong to the list...).
protected void move(ListItem start,
ListItem end,
int count,
ListItem base)
start - the ListItem where the chain starts (if null the
chain starts at the beginning)end - the ListItem where the chain ends (if null the end is
specified through count (if count>=0) or through the end of
the list). end must lie after start, otherwise the chain
goes to the end of the list.count - if count>=0 this specifies the length of the chain (if
end!=null in addition, the shorter chain will be taken)base - the ListItem after that the chain will be inserted (if
base==null, the chain will be inserted at the beginning of the list)protected void cycle(ListItem item)
item is the first element of the
list. Constant runtime.item - ListItem, that will become the first list elementprotected void cycle(int dist)
dist ListItems. (if
dist<0, a right shift is performed)dist - number of steps to shifted
protected void reverse(ListItem start,
ListItem end,
int count)
start to end. If start==0,
start is set to the first item of the list. The interval contains
no more than count Listitems (if count>0). If
end==null and count<0, the list is reversed from
start to the last ListItem.start - first ListItemend - last ListItem (or ==null)count - length of the interval (if count>0)public ListView getListView()
public synchronized ListView getListView() {
allowAccess(ANY_ACCESS);
ListView view=new ListView(this,access_mode);
allowAccess(NO_ACCESS);
return view;
}
The calls to allowAccess(byte) are necessary for the list to return
true to requests from the ListView through requestAccess(int, java.lang.Object, java.lang.Object)
and that the ListView does not cause any errors during the construction. As
the method is synchronized, no other ListView can get access to the list at
the same time. Note, that synchronized may not be omitted when
overriding the method! The constant access_mode contains the rights of the
ListView.null
or a restrictive ListView.ListViewprotected void allowAccess(byte accesskonst)
public boolean requestAccess(int accesstype,
java.lang.Object who,
java.lang.Object argument)
who asks the owner for permission to perform
an action of the type accesstype with the parameter
argument. BasicList allows all actions if allowAccess(byte) has removed all restrictions - otherwise the following actions
are not permitted:ListItem.SET_OWNER, ListItem.REMOVE,
ListItem.CLEAR_CONNECTIONS, ListItem.CONNECT_FORWARD, ListItem.CONNECT_BACKWARD and ListView.LISTVIEW_ACCESS,accesstype - type of the actionwho - object, that asks for accessargument - argument of the actiontrue, if the owner permits the action, otherwise
false
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||