structure
Class OrderedList

java.lang.Object
  extended by structure.AbstractStructure
      extended by structure.OrderedList
All Implemented Interfaces:
OrderedStructure, Structure

public class OrderedList
extends AbstractStructure
implements OrderedStructure

A class that implements a collection of values that are kept in order. Base values must be comparable. Unlike Lists there is no notion of head or tail.


Constructor Summary
OrderedList()
          Construct an empty ordered list
OrderedList(Comparator ordering)
          Construct an empty ordered list with alternative ordering
 
Method Summary
 void add(Object value)
          Add a value to the ordered list, keeping values in order
 void clear()
          Remove all the elements from the ordered list
 boolean contains(Object value)
          Determine if the ordered list contains a value
 boolean isEmpty()
          Determine if the list is empty
 Iterator iterator()
          Construct an iterator for traversing elements of ordered list in ascending order
 Object remove(Object value)
          Remove a value from the ordered list.
 int size()
          Determine the number of elements in the list
 String toString()
          Generate string representation of the ordered list
 
Methods inherited from class structure.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Structure
elements, values
 

Constructor Detail

OrderedList

public OrderedList()
Construct an empty ordered list


OrderedList

public OrderedList(Comparator ordering)
Construct an empty ordered list with alternative ordering

Parameters:
ordering - the Comparator to be used in comparison
Method Detail

clear

public void clear()
Remove all the elements from the ordered list

Specified by:
clear in interface Structure

add

public void add(Object value)
Add a value to the ordered list, keeping values in order

Specified by:
add in interface Structure
Parameters:
value - The value to be added to the list

contains

public boolean contains(Object value)
Determine if the ordered list contains a value

Specified by:
contains in interface Structure
Overrides:
contains in class AbstractStructure
Parameters:
value - The value sought in the list
Returns:
The actual value found, or null, if not

remove

public Object remove(Object value)
Remove a value from the ordered list. At most one value is removed.

Specified by:
remove in interface Structure
Parameters:
value - The value to be removed
Returns:
The actual value removed from the list

size

public int size()
Determine the number of elements in the list

Specified by:
size in interface Structure
Returns:
The number of elements in the list

isEmpty

public boolean isEmpty()
Determine if the list is empty

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True if the ordered list is empty

iterator

public Iterator iterator()
Construct an iterator for traversing elements of ordered list in ascending order

Specified by:
iterator in interface Structure
Returns:
An iterator traversing elements in ascending order
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()

toString

public String toString()
Generate string representation of the ordered list

Overrides:
toString in class Object
Returns:
String representing ordered list