Class ListManager

java.lang.Object
  |
  +--ListManager

public class ListManager
extends java.lang.Object

This class is a very simple demo of searching and sorting.


Constructor Summary
ListManager()
          This class is a simple implementation of a sorted insertion and a binary search.
 
Method Summary
 void addItem(java.lang.Comparable obj)
          Add a Comparable object to the list.
 java.lang.Object findItem(java.lang.Comparable key)
          Searches the list for the specified object using the binary search algorithm.
 void printList()
          Print the contents of the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListManager

public ListManager()
This class is a simple implementation of a sorted insertion and a binary search. It is a thin wrapper for an ArrayList. Industrial strength implementations should use the classes and methods in java.util.

Method Detail

addItem

public void addItem(java.lang.Comparable obj)
Add a Comparable object to the list. The list is always maintained in sorted order.


printList

public void printList()
Print the contents of the list.


findItem

public java.lang.Object findItem(java.lang.Comparable key)
Searches the list for the specified object using the binary search algorithm. If the array contains multiple elements equal to the specified object, there is no guarantee which one will be found. This code is copied from the java.util.Collections class, modified to return the found object instead of an index.

Parameters:
key - the value to be searched for.
Returns:
the found object or null