gishur.core
Class SimpleList

java.lang.Object
  |
  +--gishur.core.BasicList
        |
        +--gishur.core.SimpleList
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, ControlledCloneable, Owner, java.io.Serializable
Direct Known Subclasses:
List

public class SimpleList
extends BasicList
implements ControlledCloneable

A SimpleList is doubly connected list based upon BasicList. SimpleList supplies a variety of methods to navigate lists, to search for elements, for conversion and for operations on partial lists.

0. General topics and basic work mechanisms.

SimpleLists (and all extended classes based upon it) are doubly connected lists, able to store ListItems. ListItem is an interface which is implemented by SimpleListItem and StdListItem and some more classes. SimpleList mostly uses SimpleListItems. But it is possible to add any object implementing ListItem. For working properly, it is essential that a ListItem implements the interface-methods correctly, this includes that it asks its Owner-structure for permission before performing an action.
As SimpleList implements ControlledCloneable, a clone()-method is also provided.

1. Construction of new lists.

An empty list is constructed by calling SimpleList(). SimpleList(BasicList) converts a structure based upon BasicList into a SimpleList. In this process, the old BasicList-structure will be deleted. On the other hand, SimpleList(ListItem,ListItem) only copies a part of another list-structure. This part is only inserted, if it is not owned by another structure or the old Owner allows it. With SimpleList(Object[],int,int), it is possible to construct a new SimpleList taking the given array-elements as values.

2. Access and navigation.

length() returns the number of stored elements, first() the first ListItem of this list and last() the last one. firstKey() returns the first ListItem's key and firstValue() its value. lastKey() and lastValue() work the same way with the last ListItem. If objects were added by the standard mathods (i.e. without creating ListItems before), key(gishur.core.ListItem) and value(gishur.core.ListItem) return the same object. empty() checks if the list contains no ListItems. contains(ListItem) checks in constant time, if the specified ListItem is owned by this list and contains(Object) searches for a ListItem in this list whose value is the argument object. Because of the search for the matching ListItem, this operation takes linar time. getIndex(ListItem) returns this ListItem's position index and vice versa at(int) returns the ListItem at the specified index in the list. With getValueAt(int) and getKeyAt(int) it is possible to get key and value of the ListItem at the given index position. getDistance(ListItem,ListItem) calculates the number of ListItems between the two arguments in the list. value(ListItem) and key(ListItem) return the argument's value or key object.
next(ListItem) returns the next ListItem in the list and next(ListItem, int count) the ListItem which is count steps forward in the list. prev(ListItem) and prev(ListItem, int) work the same way in backward direction. With relative(ListItem,int) it is possible to access ListItems in a certain distance and the same does cyclicRelative(ListItem,int), but additionally it supposes the list to be connected cyclic (the last element connected to the first).

3. Search for objects.

find(Object) respectively find(Object,ListItem) searches the list for a ListItem which equals the argument. This method uses the ListItems' equals(Object)-method and should compare key-objects. Besides, with findBigger(Object key,Comparitor) and findSmaller(Object,Comparitor) it is possible to search for ListItems whose key objects are most 'similar' (due to the specified Comparitor) to the argument object. min(Comparitor) and max(Comparitor) return the smallest / biggest object (due to the specified Comparitor) in the list. Therefore, the Comparitor should be able to compare ListItems or even KeyValueHolders.

4. Insertion and deletion of single elements.

Objects can be inserted at the end of the list by add(Object) or before any other position in the list by insert(ListItem,Object). These methods impicitely create a SimpleListItem which contains the given object as its key. Additional methods are implemented to make the easy insertion of Java primitive type values possible. In these methods, an object of the wrapping class from java.lang is created and stored with add(Object). ListItems can be inserted by add(ListItem) and insert(ListItem,ListItem). Besides, methods for the use of a SimpleList as a Stack or a Queue are provided.

5. Operations on partial lists.

With copy(gishur.core.ListItem, gishur.core.ListItem) it is possible to copy intervals of the list, cut(gishur.core.ListItem, gishur.core.ListItem) cuts them and paste(gishur.core.ListItem, gishur.core.ListItem, gishur.core.ListItem) inserts intervals. paste(gishur.core.ListItem, gishur.core.ListItem, gishur.core.ListItem) directly inserts the interval, if its Owner permits it, otherwise the interval is copied. That means that it is not necessary to copy an interval from another list to be able to insert it into this one, it is possible to directly insert it, which implicitely means copying in the case that the insertion was denied by the interval's Owner.

6. Access to and conversion of the whole list.

Several methods are supplied to convert a SimpleList into another structure. convertKeysToArray() stores the key objects in an array, the same does convertValuesToArray() with the list's value objects. keys() and values() return a java.util.Enumeration-object which enumerates the list's keys / values.

7. Modification of the whole list.

reverse() inverses the lists order, cycle(int) and cycle(ListItem) rotate the list's order so that a specifiable ListItem becomes the first element. sort() sorts the list according to the order defined by the given Comparitor using a Sorter object. This Comparitor should be able to compare ListItems or even KeyValueHolders.

8. Serialization.

The BasicList implements the Serializable interface. If you want to avoid serializing, you can derive a list, which ensures, that it contains at least one object not implementing the Serializable interface. For example, this could be a ListItem.

Version:
1.0
Author:
Thomas Wolf
See Also:
BasicList, Stack, Queue, ListItem, SimpleListItem, ListView, Serialized Form

Fields inherited from class gishur.core.BasicList
ANY_ACCESS, KEY, LISTITEM, NO_ACCESS, VALUE
 
Fields inherited from interface gishur.core.ControlledCloneable
DEEP, FLAT
 
Constructor Summary
SimpleList()
          Empty constructor.
SimpleList(BasicList L)
          Conversion constructor.
SimpleList(ListItem start, int count)
          Copy-constructor.
SimpleList(ListItem start, ListItem end)
          Copy-constructor.
SimpleList(java.lang.Object[] array, int startindex, int length)
          Array-constructor.
 
Method Summary
 ListItem add(boolean w)
          The add(gishur.core.ListItem)-method for boolean-values.
 ListItem add(double w)
          The add(gishur.core.ListItem)-method for double-values.
 ListItem add(float w)
          The add(gishur.core.ListItem)-method for float-values.
 ListItem add(int w)
          The add(gishur.core.ListItem)-method for int-values.
 ListItem add(ListItem item)
          Inserts the ListItem item at the end of the list.
 ListItem add(long w)
          The add(gishur.core.ListItem)-method for long-values.
 ListItem add(java.lang.Object object)
          Adds the object object to the end of the list.
 ListItem at(int index)
          Returns the ListItem with index index.
 java.lang.Object bottom()
          Returns the first element of the stack.
 void clear()
          Clears the whole list.
 java.lang.Object clone()
          Implementation of Cloneable
clones the entire list by cloning the contained data-/keyobjects, if possible.
 java.lang.Object clone(java.util.Hashtable h, int level)
          Implementation of ControlledCloneable
clones the entire list.
 int concat(BasicList L)
          Appends BasicList L to this list.
 boolean contains(ListItem item)
          Returns true, if ListItem item is part of this list.
 boolean contains(java.lang.Object object)
          Returns true, if this list contains the object object.
 java.lang.Object[] convertKeysToArray()
          Returns the keys of this list in an array.
 java.lang.Object[] convertValuesToArray()
          Returns the values of this list in an array.
 ListItem copy(ListItem start, int count)
          Copies a contiguous part of the list.
 ListItem copy(ListItem start, ListItem end)
          Copies a contiguous part of the list.
 int cut(ListItem start, int count)
          Cuts a contiguous part out of this list.
 int cut(ListItem start, ListItem end)
          Cuts a contiguous part out of this list.
 void cycle(int dist)
          Rotates the list in cyclic manner for dist positions
 void cycle(ListItem item)
          Rotates the list in cyclic manner to make item the first element.
 ListItem cyclicRelative(ListItem base, int count)
          Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list).
 java.lang.Object cyclicRelativeValue(ListItem base, int count)
          Returns the value of the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list).
 boolean empty()
          Checks if this list is empty.
 ListItem find(ListItem item)
          Searches for ListItem item in the list and returns it, or null, if it could not be found.
 ListItem find(java.lang.Object O)
          Returns the first ListItem in this list for which equals(Object)} returned true or null if no such ListItem has been found.
 ListItem find(java.lang.Object O, ListItem start)
          Returns the first ListItem after start in this list for which equals(Object) returned true or null if no such ListItem has been found.
 ListItem findBigger(java.lang.Object key, Comparitor comparitor)
          Searches in the list for the ListItem which is the 'smallest' among those, which are 'bigger' than key.
 ListItem findBigger(java.lang.Object key, Comparitor comparitor, ListItem start)
          Searches in the list for the ListItem which is the 'smallest' among those, which are 'bigger' than key.
 ListItem findClass(java.lang.Class C)
          Returns the first ListItem which stores an object of class C.
 ListItem findClass(java.lang.Class C, ListItem start)
          Returns the first ListItem after start which stores an object of class C.
 ListItem findClass(java.lang.Class C, ListItem start, int i)
          Returns the i-th ListItem after start which stores an object of class C.
 ListItem findSmaller(java.lang.Object key, Comparitor comparitor)
          Searches in the list for the ListItem which is the 'biggest' among those, which are 'smaller' than key.
 ListItem findSmaller(java.lang.Object key, Comparitor comparitor, ListItem start)
          Searches in the list for the ListItem which is the 'biggest' among those, which are 'smaller' than key.
 ListItem first()
          Returns the first ListItem of this list.
 java.lang.Object firstKey()
          Returns the first ListItem's key object.
 java.lang.Object firstValue()
          Returns the first ListItem's value object.
 int getDistance(ListItem i, ListItem j)
          Returns the distance between the ListItems i and j.
 int getIndex(ListItem i)
          Computes ListItem i's index in the list, starting with the first stored item.
 java.lang.Object getKeyAt(int index)
          Returns the key of the ListItem with index index.
 ListView getListView()
          Creates and returns a ListView-object which enables complete reading-access to the list without knowing the explicite type.
 java.lang.Object getValueAt(int index)
          Returns the value of the ListItem with index index.
 ListItem insert(ListItem base, boolean w)
          The insert(gishur.core.ListItem, gishur.core.ListItem)-method for boolean-values.
 ListItem insert(ListItem base, double w)
          The insert(gishur.core.ListItem, gishur.core.ListItem)-method for double-values.
 ListItem insert(ListItem base, float w)
          The insert(gishur.core.ListItem, gishur.core.ListItem)-method for float-values.
 ListItem insert(ListItem base, int w)
          The insert(gishur.core.ListItem, gishur.core.ListItem)-method for int-values.
 ListItem insert(ListItem base, ListItem item)
          Inserts the ListItem item before base into the list.
 ListItem insert(ListItem base, long w)
          The insert(gishur.core.ListItem, gishur.core.ListItem)-method for long-values.
 ListItem insert(ListItem base, java.lang.Object object)
          Creates a new ListItem containing object and inserts it before base into the list.
 ListItem insert(ListItem base, java.lang.Object[] array, int startindex, int length)
          Inserts length objects stored in array-elements with indices higher than startindex into the list before ListItem base.
 java.lang.Object key(ListItem item)
          Returns ListItem item's key.
 java.util.Enumeration keys()
          Returns an java.util.Enumerator-object enumerating the keys of this list.
 ListItem last()
          Returns the last ListItem of this list.
 java.lang.Object lastKey()
          Returns the last ListItem's key object.
 java.lang.Object lastValue()
          Returns the last ListItem's value object.
 int length()
          Returns the number of stored elements in the list.
 ListItem max(Comparitor comparitor)
          Searches for the maximal ListItem (due to comparitor) in the list.
 ListItem min(Comparitor comparitor)
          Searches for the minimal ListItem (due to comparitor) in the list.
 void move(ListItem start, int count, ListItem base)
          Moves the specified chain of this list to another position; e.g. after the list element base.
 void move(ListItem start, ListItem base)
          Moves a single ListItem from its current position to the successor of the given base element.
 void move(ListItem start, ListItem end, ListItem base)
          Moves the specified chain of this list to another position; e.g. after the list element base.
 ListItem next(ListItem i)
          Returns the next ListItem after i of this list.
 ListItem next(ListItem base, int count)
          Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list).
 int paste(ListItem base, ListItem start, int count)
          Inserts a chain of ListItems of maximal length count before base into the list.
 int paste(ListItem base, ListItem start, ListItem end)
          Inserts a chain of ListItems before base into the list.
 java.lang.Object peek()
          A stack-peek, works the same way like top().
 java.lang.Object Peek()
          A queue-peek, works the same way like firstValue().
 java.lang.Object pop()
          A stack-pop.
 java.lang.Object Pop()
          Queue-pop.
 boolean popBoolean()
          Pop for boolean-values.
 boolean PopBoolean()
          Pop for boolean-values.
 double popDouble()
          Pop for double-values.
 double PopDouble()
          Pop for double-values.
 float popFloat()
          Pop for float-values.
 float PopFloat()
          Pop for float-values.
 int popInt()
          Pop for int-values.
 int PopInt()
          Pop for int-values.
 long popLong()
          Pop for long-values.
 long PopLong()
          Pop for long-values.
 ListItem prev(ListItem i)
          Returns the previous ListItem to i.
 ListItem prev(ListItem base, int count)
          Returns the ListItem which is situated count steps in backward direction from base (or null, if base is not part of this list).
 ListItem push(boolean b)
          Push for boolean-values.
 ListItem push(double d)
          Push for double-values.
 ListItem push(float f)
          Push for float-values.
 ListItem push(int i)
          Push for int-values.
 ListItem push(long l)
          Push for long-values.
 ListItem push(java.lang.Object object)
          Puts an object on the top of the stack, i.e. appends it to the queue.
 ListItem Push(java.lang.Object object)
          Puts an object onto the bottom of the stack, i.e. inserts it before the first element of the list.
 ListItem relative(ListItem base, int count)
          Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list).
 ListItem remove(ListItem item)
          Removes the ListItem item from the list.
 ListItem remove(java.lang.Object key)
          Removes the ListItem whose key is equal to key from the list.
 void reverse()
          Inverts the order in the list.
 void sort(Comparitor comparitor)
          Sorts the list in ascending order using the Comparitor comparitor.
 void sort(Comparitor comparitor, short order)
          Sorts the list in the order defined by the comparitor-object either in ascending or in descending order (specified by order).
 java.lang.Object top()
          Returns the last element of the stack.
 java.lang.String toString()
          Overrides java.lang.Object.toString().
 java.lang.Object value(ListItem item)
          Returns ListItem item's value.
 java.util.Enumeration values()
          Returns an java.util.Enumerator-object enumerating the values of this list.
 
Methods inherited from class gishur.core.BasicList
add, add, allowAccess, copy, copy, copy, cut, enumerate, equals, find, findClass, findClosest, getIndex, getListItem, getListItemArray, getListString, move, reconnect, reconnect, remove, requestAccess, reverse, storeInArray, toString, unconnect
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleList

public SimpleList()
Empty constructor.

SimpleList

public SimpleList(BasicList L)
Conversion constructor. Takes all elements of L into the created SimpleList.
Parameters:
L - BasicList to be converted

SimpleList

public SimpleList(ListItem start,
                  ListItem end)
Copy-constructor. Copies a partial list into this list. If the sequence starting with start is owned by another structure, normally a copy of it will be inserted and the source structure remains unchanged.
Parameters:
start - starting element of the sequence to insert
end - last element

SimpleList

public SimpleList(ListItem start,
                  int count)
Copy-constructor. Copies a partial list into this list. If the sequence starting with start is owned by another structure, normally a copy of it will be inserted and the source structure remains unchanged.
Parameters:
start - starting element of the sequence to insert
count - the length of the sequence to be inserted

SimpleList

public SimpleList(java.lang.Object[] array,
                  int startindex,
                  int length)
Array-constructor. The new list will contain the objects stored in array, beginning with element startindex and ending with element startindex+length-1.
Parameters:
array - an array of objects to store in the new list
startindex - the index of the first element in the array to be stored in the list
length - number of elements to store
Method Detail

toString

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

clone

public java.lang.Object clone()
Implementation of Cloneable
clones the entire list by cloning the contained data-/keyobjects, if possible. If not possible, the references to the data-/keyobjects are maintained.
Specified by:
clone in interface Cloneable
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object.
Throws:
InternalError - - if the Object could not be cloned properly

clone

public java.lang.Object clone(java.util.Hashtable h,
                              int level)
Implementation of ControlledCloneable
clones the entire list. That means, all ListItems are cloned and connected proper.
Specified by:
clone in interface ControlledCloneable
Overrides:
clone in class BasicList
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
See Also:
ControlledCloneable

length

public int length()
Returns the number of stored elements in the list.
Overrides:
length in class BasicList
Returns:
number of elements

empty

public boolean empty()
Checks if this list is empty.
Overrides:
empty in class BasicList
Returns:
true, if this list contains no ListItems

first

public ListItem first()
Returns the first ListItem of this list.
Overrides:
first in class BasicList
Returns:
first ListItem

last

public ListItem last()
Returns the last ListItem of this list.
Overrides:
last in class BasicList
Returns:
last ListItem

firstKey

public java.lang.Object firstKey()
Returns the first ListItem's key object. If the list is empty, a ListException will be thrown.
Returns:
first key of this list

lastKey

public java.lang.Object lastKey()
Returns the last ListItem's key object. If the list is empty, a ListException will be thrown.
Returns:
last key of this list

firstValue

public java.lang.Object firstValue()
Returns the first ListItem's value object. If the list is empty, a ListException will be thrown.
Returns:
first value of this list

lastValue

public java.lang.Object lastValue()
Returns the last ListItem's value object. If the list is empty, a ListException will be thrown.
Returns:
last value of this list

contains

public boolean contains(ListItem item)
Returns true, if ListItem item is part of this list. The check takes constant time.
Overrides:
contains in class BasicList
Parameters:
item - ListItem to search for in the list
Returns:
true if item is part of this list

contains

public boolean contains(java.lang.Object object)
Returns true, if this list contains the object object.
Parameters:
object - the object to search for in the list
Returns:
true if object was found in the list

getIndex

public int getIndex(ListItem i)
Computes ListItem i's index in the list, starting with the first stored item. If i is not part of this list, -1 will be returned.
Parameters:
i - ListItem, whose index is requested

getDistance

public int getDistance(ListItem i,
                       ListItem j)
Returns the distance between the ListItems i and j. A positive result means that j can be reached from i by going forward, a negative result means the opposite (go backward to reach j from i). If i or j are not members of this list or one of them cannot be reached from the other (?!), Integer.MAX_VALUE will be returned.
Overrides:
getDistance in class BasicList
Parameters:
i,j - ListItems, whose distance shall be computed

key

public java.lang.Object key(ListItem item)
Returns ListItem item's key. If item is contained by this list, a ListException will be thrown.
Returns:
the key of item

value

public java.lang.Object value(ListItem item)
Returns ListItem item's value. If item is contained by this list, a ListException will be thrown.
Returns:
the key of item

next

public ListItem next(ListItem i)
Returns the next ListItem after i of this list. If i==null, the first ListItem will be returned. If i is not part of this list, null will be returned.
Parameters:
i - ListItem of this list
Returns:
the following ListItem

next

public ListItem next(ListItem base,
                     int count)
Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list). If base==null, the search starts at the first ListItem in the list.
Parameters:
base - a ListItem contained by this list
count - number of steps to go forward
Returns:
the ListItem with a getDistance()-value of +count from base

relative

public ListItem relative(ListItem base,
                         int count)
Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list). If base==null, the search starts at the first ListItem in the list.
Parameters:
base - a ListItem contained by this list
count - number of steps to go forward
Returns:
the ListItem with a getDistance()-value of +count from base

cyclicRelative

public ListItem cyclicRelative(ListItem base,
                               int count)
Returns the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list). This method supposes the list to be cyclic (the last ListItem to be connected with the first). If base==null, the search starts at the first ListItem in the list.
Parameters:
base - a ListItem contained by this list
count - number of steps to go forward
Returns:
the ListItem with a getDistance()-value of +count from base (in a cyclic traversal!)

cyclicRelativeValue

public java.lang.Object cyclicRelativeValue(ListItem base,
                                            int count)
Returns the value of the ListItem which is situated count steps in forward direction from base (or null, if base is not part of this list). This method supposes the list to be cyclic (the last ListItem to be connected with the first). If base==null, the search starts at the first ListItem in the list.
Parameters:
base - a ListItem contained by this list
count - number of steps to go forward
Returns:
the value of the ListItem with a getDistance()-value of +count from base (in a cyclic traversal!)

prev

public ListItem prev(ListItem base,
                     int count)
Returns the ListItem which is situated count steps in backward direction from base (or null, if base is not part of this list). If base==null, the search starts at the first ListItem in the list.
Parameters:
base - a ListItem contained by this list
count - number of steps to go backward
Returns:
the ListItem with a getDistance()-value of -count from base

prev

public ListItem prev(ListItem i)
Returns the previous ListItem to i. If i==null, the last ListItem will be returned. If i is not part of this list, null will be returned.
Parameters:
i - ListItem of this list
Returns:
the previous ListItem

at

public ListItem at(int index)
Returns the ListItem with index index.
Parameters:
index - the index of the requested ListItem
Returns:
the ListItem with index index

getValueAt

public java.lang.Object getValueAt(int index)
Returns the value of the ListItem with index index.
Parameters:
index - the index of the ListItem whose value is requested
Returns:
the value-object stored at index index

getKeyAt

public java.lang.Object getKeyAt(int index)
Returns the key of the ListItem with index index.
Parameters:
index - the index of the ListItem whose key is requested
Returns:
the key-object stored at index index

find

public ListItem find(ListItem item)
Searches for ListItem item in the list and returns it, or null, if it could not be found. The search takes constant time.
Parameters:
item - ListItem to search for
Returns:
item, it found, null otherwise

find

public ListItem find(java.lang.Object O)
Returns the first ListItem in this list for which equals(Object)} returned true or null if no such ListItem has been found. This search takes linear time.
Parameters:
O - object to search for in the list
Returns:
the found ListItem or null

find

public ListItem find(java.lang.Object O,
                     ListItem start)
Returns the first ListItem after start in this list for which equals(Object) returned true or null if no such ListItem has been found. If start==null, the search starts at the beginning of the list. This search takes linear time.
Parameters:
O - object to search for in the list
start - ListItem where the search starts
Returns:
the found ListItem or null

findClass

public ListItem findClass(java.lang.Class C)
Returns the first ListItem which stores an object of class C. The seach takes linear time.
Parameters:
C - a class type of which the first object in the list should be found
Returns:
the found ListItem or null, if no such object was found in a ListItem of this list

findClass

public ListItem findClass(java.lang.Class C,
                          ListItem start)
Returns the first ListItem after start which stores an object of class C. If start==null, the search starts at the beginning of the list. The search takes linear time.
Parameters:
C - a class type of which the first object in the list after start should be found
start - a ListItem in this list from which the search should start
Returns:
the found ListItem or null, if no such object was found in a ListItem of this list

findClass

public ListItem findClass(java.lang.Class C,
                          ListItem start,
                          int i)
Returns the i-th ListItem after start which stores an object of class C. If start==null, the search starts at the beginning of the list. The search takes linear time.
Parameters:
C - a class type of which the i-th object in the list after start should be found
i - the number+1 of objects of class C which shall be ignored before the next ListItem containing an object of class C shall be returned
start - a ListItem in this list from which the search should start
Returns:
the found ListItem or null, if no such object was found in a ListItem of this list

findBigger

public ListItem findBigger(java.lang.Object key,
                           Comparitor comparitor)
Searches in the list for the ListItem which is the 'smallest' among those, which are 'bigger' than key. 'Smaller' and 'bigger' are defined by comparitor. If key is a ListItem, the ListItems are compared directly, otherwise the key are compared. If key==null, this method returns the same result as max(Comparitor). If comparitor==null, a StdComparitor will be used.
Parameters:
key - object to compare to the ListItems in this list
comparitor - a Comparitor to compare this list's keys
Returns:
the 'smallest' ListItem which is 'smaller' or equal to key
See Also:
Comparitor

findBigger

public ListItem findBigger(java.lang.Object key,
                           Comparitor comparitor,
                           ListItem start)
Searches in the list for the ListItem which is the 'smallest' among those, which are 'bigger' than key. 'Smaller' and 'bigger' are defined by comparitor. The search starts at start or at the first ListItem, if start==null. If key is a ListItem, the ListItems are compared directly, otherwise the key are compared. If comparitor==null, a StdComparitor will be used.
Parameters:
key - object to compare to the ListItems in this list
comparitor - a Comparitor to compare this list's keys
Returns:
the 'smallest' ListItem which is 'bigger' or equal to key
See Also:
Comparitor, findBigger(Object, Comparitor)

findSmaller

public ListItem findSmaller(java.lang.Object key,
                            Comparitor comparitor)
Searches in the list for the ListItem which is the 'biggest' among those, which are 'smaller' than key. 'Smaller' and 'bigger' are defined by comparitor. If key is a ListItem, the ListItems are compared directly, otherwise the key are compared. If key==null, this method returns the same result as min(Comparitor). If comparitor==null, a StdComparitor will be used.
Parameters:
key - object to compare to the ListItems in this list
comparitor - a Comparitor to compare this list's keys
Returns:
the 'smallest' ListItem which is 'bigger' or equal to key
See Also:
Comparitor

findSmaller

public ListItem findSmaller(java.lang.Object key,
                            Comparitor comparitor,
                            ListItem start)
Searches in the list for the ListItem which is the 'biggest' among those, which are 'smaller' than key. 'Smaller' and 'bigger' are defined by comparitor. The search starts at start or at the first ListItem, if start==null. If key is a ListItem, the ListItems are compared directly, otherwise the key are compared. If comparitor==null, a StdComparitor will be used.
Parameters:
key - object to compare to the ListItems in this list
comparitor - a Comparitor to compare this list's keys
Returns:
the 'smallest' ListItem which is 'bigger' or equal to key
See Also:
Comparitor, findSmaller(Object, Comparitor)

min

public ListItem min(Comparitor comparitor)
Searches for the minimal ListItem (due to comparitor) in the list.
Parameters:
comparitor - a Comparitor to compare this list's keys
Returns:
the 'smallest' ListItem in this list

max

public ListItem max(Comparitor comparitor)
Searches for the maximal ListItem (due to comparitor) in the list.
Parameters:
comparitor - a Comparitor to compare this list's keys
Returns:
the 'biggest' ListItem in this list

add

public ListItem add(ListItem item)
Inserts the ListItem item at the end of the list. If item already belongs to the list, or if the owner can't be changed, a (flat) clone of the ListItem item will be inserted.
Parameters:
item - the new ListItem
Returns:
inserted ListItem

add

public ListItem add(java.lang.Object object)
Adds the object object to the end of the list. The newly created ListItem containing object will be returned.
Parameters:
object - the object to be inserted
Returns:
a ListItem storing object
See Also:
add(ListItem)

insert

public ListItem insert(ListItem base,
                       ListItem item)
Inserts the ListItem item before base into the list. If base==null, item will be added to the end of the list. If base is not part of this list, a ListException will occur. If item is already part of this list or its Owner cannot be changed, a (flat) clone will be inserted.
Parameters:
base - position in the list before which item will be inserted
item - new ListItem
Returns:
inserted ListItem

insert

public ListItem insert(ListItem base,
                       java.lang.Object object)
Creates a new ListItem containing object and inserts it before base into the list. If base==null, it will be added to the end of the list. If base is not part of this list, a ListException will occur.
Parameters:
base - position in the list before which the new ListItem will be inserted
object - object to insert into the list
Returns:
inserted ListItem
See Also:
insert(ListItem, ListItem)

insert

public ListItem insert(ListItem base,
                       java.lang.Object[] array,
                       int startindex,
                       int length)
Inserts length objects stored in array-elements with indices higher than startindex into the list before ListItem base. If base==null, the new ListItems will be added to the end of the list. If base is not part of this list, a ListException will occur.
Parameters:
base - position in the list before which the new ListItems will be inserted
array - an array containing the objects to be inserted
startindex - the index of the first element of array whih will be inserted
length - the number of elements of array to insert
Returns:
the first inserted ListItem

remove

public ListItem remove(ListItem item)
Removes the ListItem item from the list. If item==null or item is not part of the list, a ListException occurs.
Parameters:
item - the ListItem to remove
Returns:
removed ListItem

remove

public ListItem remove(java.lang.Object key)
Removes the ListItem whose key is equal to key from the list. If key==null, a ListException will be thrown.
Parameters:
key - the key-object to search for in the list
Returns:
removed ListItem

copy

public ListItem copy(ListItem start,
                     ListItem end)
Copies a contiguous part of the list. The interval from start to end will be copied and a reference to the first element of this chain (the copy of start) will be returned.
Parameters:
start - the first ListItem of the interval to copy
end - last ListItem of the interval to copy
Returns:
the first ListItem of the copy

copy

public ListItem copy(ListItem start,
                     int count)
Copies a contiguous part of the list. This part starts with start and its maximal length is count. The first element of the created copy (the copy of start) will be returned.
Parameters:
start - first ListItem of the interval to copy
count - (max.) number of elements in the copy
Returns:
the copy's fist ListItem

cut

public int cut(ListItem start,
               ListItem end)
Cuts a contiguous part out of this list. That means that the elements following start are still connected, but are no longer part of this list. The first removed element is start and the last one end. The return value is the total number of removed elements.
Parameters:
start - first ListItem to cut out of this list
end - last ListItem of the cut chain
Returns:
number of elements removed from the old list

cut

public int cut(ListItem start,
               int count)
Cuts a contiguous part out of this list. That means that the elements following start are still connected, but are no longer part of this list. The first removed element is start and the maximally removed number of elements is count. The return value is the total number of removed elements.
Parameters:
start - first ListItem to cut out of this list
count - maximal number of cutted elements
Returns:
number of cutted elements

paste

public int paste(ListItem base,
                 ListItem start,
                 ListItem end)
Inserts a chain of ListItems before base into the list. The interval from start to end will be inserted. If direct insertion is not possible, a copy is created and inserted. If base==null, the ListItems will be added to the end of the list. The number of inserted elements is returned.
Parameters:
base - position before which the new elements shall be inserted
start - the first element of the sequence to be inserted
end - the last element to be inserted
Returns:
number of inserted elements

paste

public int paste(ListItem base,
                 ListItem start,
                 int count)
Inserts a chain of ListItems of maximal length count before base into the list. The interval beginning with start will be inserted. If direct insertion is not possible, a copy is created and inserted. If base==null, the ListItems will be added to the end of the list. The number of inserted elements is returned.
Parameters:
base - position before which the new elements shall be inserted
start - the first element of the sequence to be inserted
count - the maximal number of elements to insert
Returns:
number of inserted elements

concat

public int concat(BasicList L)
Appends BasicList L to this list. After this operation, list L will be empty.
Parameters:
L - a BasicList to append to this list
Returns:
number of inserted ListItems

move

public void move(ListItem start,
                 ListItem base)
Moves a single ListItem from its current position to the successor of the given base element.
Parameters:
start - ListItem to move (must be !=null)
base - ListItem, after which it will be inserted

move

public void move(ListItem start,
                 ListItem end,
                 ListItem base)
Moves the specified chain of this list to another position; e.g. after the list element base.
Parameters:
start - the ListItem, where the chain starts (if start==null, the chain starts at the beginning of the list)
end - the ListItem, where the chain ends (if end==null, the chain ends with the list)
base - the element after which the chain will be inserted (if base==null, the chain will be inserted at the beginning of the list)

move

public void move(ListItem start,
                 int count,
                 ListItem base)
Moves the specified chain of this list to another position; e.g. after the list element base.
Parameters:
start - the ListItem, where the chain starts (if start==null, the chain starts at the beginning of the list)
count - the length of the chain (if count<0 the chain ends with the list end)
base - the element after which the chain will be inserted (if base==null, the chain will be inserted at the beginning of the list)

convertKeysToArray

public java.lang.Object[] convertKeysToArray()
Returns the keys of this list in an array. If this SimpleList was constructed using the standard insertion-methods, convertKeysToArray() and convertValuesToArray() return the same array.
Returns:
an array of objects containing this list's keys
See Also:
convertValuesToArray()

convertValuesToArray

public java.lang.Object[] convertValuesToArray()
Returns the values of this list in an array. If this SimpleList was constructed using the standard insertion-methods, convertKeysToArray() and convertValuesToArray() return the same array.
Returns:
an array of objects containing this list's values
See Also:
convertKeysToArray()

keys

public java.util.Enumeration keys()
Returns an java.util.Enumerator-object enumerating the keys of this list. If this SimpleList was constructed using the standard insertion-methods, keys() and values() return the same Enumeration.
Returns:
an Enumeration enumerating the keys
See Also:
values()

values

public java.util.Enumeration values()
Returns an java.util.Enumerator-object enumerating the values of this list. If this SimpleList was constructed using the standard insertion-methods, keys() and values() return the same Enumeration.
Returns:
an Enumeration enumerating the values
See Also:
keys()

getListView

public ListView getListView()
Creates and returns a ListView-object which enables complete reading-access to the list without knowing the explicite type.
Overrides:
getListView in class BasicList
Returns:
a ListView for reading-access

clear

public void clear()
Clears the whole list.
Overrides:
clear in class BasicList

cycle

public void cycle(ListItem item)
Rotates the list in cyclic manner to make item the first element. The operation takes constant time
Overrides:
cycle in class BasicList
Parameters:
item - the ListItem to become the first element

cycle

public void cycle(int dist)
Rotates the list in cyclic manner for dist positions
Overrides:
cycle in class BasicList
Parameters:
dist - number of rotation steps to perform

reverse

public void reverse()
Inverts the order in the list.

sort

public void sort(Comparitor comparitor,
                 short order)
Sorts the list in the order defined by the comparitor-object either in ascending or in descending order (specified by order). If comparitor==null, a StdComparitor is used. The used Comparitor should be able to compare KeyValueHolder-objects.
Parameters:
comparitor - a Comparitor to compare the list's keys
order - the further order of the list: either Sorter.ASCENDING or Sorter.DESCENDING

sort

public void sort(Comparitor comparitor)
Sorts the list in ascending order using the Comparitor comparitor. If comparitor==null, a StdComparitor will be used.
Parameters:
comparitor - a Comparitor to compare the list's keys

bottom

public java.lang.Object bottom()
Returns the first element of the stack. If the stack is empty, a ListException will be thrown.
Returns:
the stack's first element

top

public java.lang.Object top()
Returns the last element of the stack. If the stack is empty, a ListException will be thrown.
Returns:
the stack's last element

peek

public java.lang.Object peek()
A stack-peek, works the same way like top().
Returns:
last Element
See Also:
top()

Peek

public java.lang.Object Peek()
A queue-peek, works the same way like firstValue().
Returns:
first Element
See Also:
peek()

push

public ListItem push(java.lang.Object object)
Puts an object on the top of the stack, i.e. appends it to the queue.
Parameters:
object - the object to store
Returns:
a ListItem storing object

Push

public ListItem Push(java.lang.Object object)
Puts an object onto the bottom of the stack, i.e. inserts it before the first element of the list.
Parameters:
object - object to store
Returns:
a ListItem storing object

pop

public java.lang.Object pop()
A stack-pop. Removes the last element from the stack and returns it.
Returns:
last element

Pop

public java.lang.Object Pop()
Queue-pop. Removes the first element from the queue and returns it.
Returns:
first element

push

public ListItem push(int i)
Push for int-values.
Parameters:
i - int-value to push
Returns:
a ListItem storing this value
See Also:
push(java.lang.Object)

push

public ListItem push(long l)
Push for long-values.
Parameters:
l - long-value to push
Returns:
a ListItem storing this value
See Also:
push(java.lang.Object)

push

public ListItem push(float f)
Push for float-values.
Parameters:
f - float-value to push
Returns:
a ListItem storing this value
See Also:
push(java.lang.Object)

push

public ListItem push(double d)
Push for double-values.
Parameters:
d - double-value to push
Returns:
a ListItem storing this value
See Also:
push(java.lang.Object)

push

public ListItem push(boolean b)
Push for boolean-values.
Parameters:
b - boolean-value to push return a ListItem storing this value
See Also:
push(java.lang.Object)

popInt

public int popInt()
Pop for int-values. If it is not possible to convert the object on the stack into an int, a ListException will be thrown.
Returns:
the last object on the stack as an int-value
See Also:
pop()

popLong

public long popLong()
Pop for long-values. If it is not possible to convert the object on the stack into a long, a ListException will be thrown.
Returns:
the last object on the stack as a long-value
See Also:
pop()

popFloat

public float popFloat()
Pop for float-values. If it is not possible to convert the object on the stack into a float, a ListException will be thrown.
Returns:
the last object on the stack as a float-value
See Also:
pop()

popDouble

public double popDouble()
Pop for double-values. If it is not possible to convert the object on the stack into a double, a ListException will be thrown.
Returns:
the last object on the stack as a double-value
See Also:
pop()

popBoolean

public boolean popBoolean()
Pop for boolean-values. If it is not possible to convert the object on the stack into a boolean, a ListException will be thrown.
Returns:
the last object on the stack as a boolean-value
See Also:
pop()

PopInt

public int PopInt()
Pop for int-values. If it is not possible to convert the object on the stack into an int, a ListException will be thrown. In difference to the popInt()-method, this method uses peek() and not top() to get the stack's last element, but this won't cause any difference in the result.
Returns:
the last object on the stack as an int-value
See Also:
pop(), popInt()

PopLong

public long PopLong()
Pop for long-values. If it is not possible to convert the object on the stack into a long, a ListException will be thrown. In difference to the popLong()-method, this method uses peek() and not top() to get the stack's last element, but this won't cause any difference in the result.
Returns:
the last object on the stack as a long-value
See Also:
pop(), popLong()

PopFloat

public float PopFloat()
Pop for float-values. If it is not possible to convert the object on the stack into a float, a ListException will be thrown. In difference to the popFloat()-method, this method uses peek() and not top() to get the stack's last element, but this won't cause any difference in the result.
Returns:
the last object on the stack as a float-value
See Also:
pop(), popFloat()

PopDouble

public double PopDouble()
Pop for double-values. If it is not possible to convert the object on the stack into a double, a ListException will be thrown. In difference to the popDouble()-method, this method uses peek() and not top() to get the stack's last element, but this won't cause any difference in the result.
Returns:
the last object on the stack as a double-value
See Also:
pop(), popDouble()

PopBoolean

public boolean PopBoolean()
Pop for boolean-values. If it is not possible to convert the object on the stack into a boolean, a ListException will be thrown. In difference to the popBoolean()-method, this method uses peek() and not top() to get the stack's last element, but this won't cause any difference in the result.
Returns:
the last object on the stack as a boolean-value
See Also:
pop(), popBoolean()

add

public ListItem add(int w)
The add(gishur.core.ListItem)-method for int-values. Creates a new ListItem which contains w, adds it to the list's end and finally returns it.
Parameters:
w - int-value to add to the list
Returns:
the added ListItem containing w
See Also:
add(Object)

add

public ListItem add(long w)
The add(gishur.core.ListItem)-method for long-values. Creates a new ListItem which contains w, adds it to the list's end and finally returns it.
Parameters:
w - long-value to add to the list
Returns:
the added ListItem containing w
See Also:
add(Object)

add

public ListItem add(float w)
The add(gishur.core.ListItem)-method for float-values. Creates a new ListItem which contains w, adds it to the list's end and finally returns it.
Parameters:
w - float-value to add to the list
Returns:
the added ListItem containing w
See Also:
add(Object)

add

public ListItem add(double w)
The add(gishur.core.ListItem)-method for double-values. Creates a new ListItem which contains w, adds it to the list's end and finally returns it.
Parameters:
w - double-value to add to the list
Returns:
the added ListItem containing w
See Also:
add(Object)

add

public ListItem add(boolean w)
The add(gishur.core.ListItem)-method for boolean-values. Creates a new ListItem which contains w, adds it to the list's end and finally returns it.
Parameters:
w - boolean-value to add to the list
Returns:
the added ListItem containing w
See Also:
add(Object)

insert

public ListItem insert(ListItem base,
                       int w)
The insert(gishur.core.ListItem, gishur.core.ListItem)-method for int-values. Creates a new ListItem containing w, inserts it before item base and finally returns it.
Parameters:
base - the position before which the new ListItem will be inserted
w - int-value to insert
Returns:
a newly created ListItem containing w
See Also:
insert(ListItem, Object)

insert

public ListItem insert(ListItem base,
                       long w)
The insert(gishur.core.ListItem, gishur.core.ListItem)-method for long-values. Creates a new ListItem containing w, inserts it before item base and finally returns it.
Parameters:
base - the position before which the new ListItem will be inserted
w - long-value to insert
Returns:
a newly created ListItem containing w
See Also:
insert(ListItem, Object)

insert

public ListItem insert(ListItem base,
                       float w)
The insert(gishur.core.ListItem, gishur.core.ListItem)-method for float-values. Creates a new ListItem containing w, inserts it before item base and finally returns it.
Parameters:
base - the position before which the new ListItem will be inserted
w - float-value to insert
Returns:
a newly created ListItem containing w
See Also:
insert(ListItem, Object)

insert

public ListItem insert(ListItem base,
                       double w)
The insert(gishur.core.ListItem, gishur.core.ListItem)-method for double-values. Creates a new ListItem containing w, inserts it before item base and finally returns it.
Parameters:
base - the position before which the new ListItem will be inserted
w - double-value to insert
Returns:
a newly created ListItem containing w
See Also:
insert(ListItem, Object)

insert

public ListItem insert(ListItem base,
                       boolean w)
The insert(gishur.core.ListItem, gishur.core.ListItem)-method for boolean-values. Creates a new ListItem containing w, inserts it before item base and finally returns it.
Parameters:
base - the position before which the new ListItem will be inserted
w - boolean-value to insert
Returns:
a newly created ListItem containing w
See Also:
insert(ListItem, Object)