planet.symphony
Class SortedKList

java.lang.Object
  extended byplanet.symphony.SortedKList

public class SortedKList
extends java.lang.Object

A SortedKList is a list of objects kept in sorted order. A Comparer object is needed to compare objects in the list, as there is no standard compare operation for objects. Comparer class for standard types are found in the package planet.symphony. Moreover, the SortedKList needs from a referee object and bound k. These two modifiers are used to filter elements on the SortedKList. The others are removed. This data structure is useful to maintain neighbour's set of nodes. The nodes befores the referee are its predecessors, the nodes after the referee are its successors.

Author:
Marc Sanchez (marc.sanchez@estudiants.urv.es)
See Also:
Also the SortedKList deletes duplicates.

Constructor Summary
SortedKList(Comparer listOrder, java.lang.Object referee, int k)
          Create a new SortedKList using the Comparer interface to define the order on elements.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds a object to the sortedKList.
 boolean addAll(java.util.Collection c)
          Adds a collection of elements inside the SortedKList.
 boolean contains(java.lang.Object o)
          Tests if the specified object is a component in this sortedList.
 java.lang.Object get(int index)
          Returns the element at the specified position in this sorted list.
 Comparer getComparer()
          Returns the comparer object used to order list.
 java.lang.Object getFirstPred()
          Returns the first predecessor.
 java.lang.Object getFirstSucc()
          Returns the first successor.
 java.util.Collection getNeighbourSet()
           
 java.util.Vector getPredList(int max)
          Returns the predecessor list.
 java.lang.Object getReferee()
          Returns the referee's object.
 java.util.Collection getSortedSet()
           
 java.util.Vector getSuccList(int max)
          Returns the successor list.
 boolean hasNeighbour()
           
 boolean isEmpty()
          Tests if this vector has no components.
 java.util.Iterator iterator()
           
 boolean remove(java.lang.Object o)
          Removes an object from neighbour's Set.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortedKList

public SortedKList(Comparer listOrder,
                   java.lang.Object referee,
                   int k)
Create a new SortedKList using the Comparer interface to define the order on elements.

Parameters:
listOrder - Comparer used to sort the list.
referee - The referee used to filter objects.
k - The bound used to filter objects.
See Also:
Comparer
Method Detail

getComparer

public Comparer getComparer()
Returns the comparer object used to order list.


add

public boolean add(java.lang.Object o)
Adds a object to the sortedKList.

Parameters:
o - Object to add.
Returns:
Returns true if Object o has added to SortedKList.

getReferee

public java.lang.Object getReferee()
Returns the referee's object. Normally, if enough objects are on the list, i.e, k + 1 objects then k/2 objects may be before referee and k/2 objectes may be after referee.

Returns:
The referee's object on the list.

addAll

public boolean addAll(java.util.Collection c)
Adds a collection of elements inside the SortedKList.

Parameters:
c - Collection of elements to add.
Returns:
Returns true if some object has added to SortedKList.

getNeighbourSet

public java.util.Collection getNeighbourSet()
Returns:
Returns the neighbourSet.

iterator

public java.util.Iterator iterator()
Returns:
Returns an iterator over the elements in this list in proper sequence.

getSortedSet

public java.util.Collection getSortedSet()
Returns:
Returns the whole sorted set including referee.

contains

public boolean contains(java.lang.Object o)
Tests if the specified object is a component in this sortedList.

Parameters:
o - An object.
Returns:
Returns true if and only if the specified object is the same as a component on this SortedKList, as determined by the compare method; false otherwise.

hasNeighbour

public boolean hasNeighbour()
Returns:
Returns true when sorted list has immediate neighbours; false otherwise.

remove

public boolean remove(java.lang.Object o)
Removes an object from neighbour's Set.

Parameters:
o - The object to remove.
Returns:
Returns true if the object has been removed; false otherwise.

isEmpty

public boolean isEmpty()
Tests if this vector has no components.

Returns:
True if and only if this vector has no components, that is, its size is zero; false otherwise.

get

public java.lang.Object get(int index)
Returns the element at the specified position in this sorted list.

Parameters:
index - Index of element to return.
Returns:
Returns object at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - - index is out of range (index < 0 || index >= size()).

getFirstSucc

public java.lang.Object getFirstSucc()
Returns the first successor.

Returns:
Returns the first successor or null if no such successor is available.

getFirstPred

public java.lang.Object getFirstPred()
Returns the first predecessor.

Returns:
Returns the first predecessor or null if no such predecessor is available.

getSuccList

public java.util.Vector getSuccList(int max)
Returns the successor list.

Parameters:
max - Maximum number of successors.
Returns:
Successor list

getPredList

public java.util.Vector getPredList(int max)
Returns the predecessor list.

Parameters:
max - Maximum number of predecessor.
Returns:
Predecessor list

toString

public java.lang.String toString()