org.homeunix.thecave.moss.data
Class HeapSet<Type extends java.lang.Comparable<Type>>

java.lang.Object
  extended by org.homeunix.thecave.moss.data.HeapSet<Type>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Type>, java.util.Collection<Type>, java.util.Set<Type>

public class HeapSet<Type extends java.lang.Comparable<Type>>
extends java.lang.Object
implements java.util.Set<Type>, java.io.Serializable

A fairly robust Heap implementation using Java 5 generics. Allows for either Min or Max heap. Does not allow for duplicate entries (since it implements the Set interface).

Author:
wyatt
See Also:
Serialized Form

Nested Class Summary
static class HeapSet.HeapType
           
 
Field Summary
static long serialVersionUID
           
 
Constructor Summary
HeapSet()
          Creates a new min heap.
HeapSet(java.util.Collection<Type> arg0)
          Creates a new min heap containing the specified items
HeapSet(java.util.Collection<Type> arg0, HeapSet.HeapType arg1)
          Creates a new heap containing the specified items, with the specified heap type.
HeapSet(HeapSet.HeapType arg0)
          Creates a new heap of the specified heap type.
 
Method Summary
 boolean add(Type arg0)
          Adds an object to the heap
 boolean addAll(java.util.Collection<? extends Type> arg0)
          Add all the objects in the collection to the heap
 void clear()
           
 boolean contains(java.lang.Object arg0)
           
 boolean containsAll(java.util.Collection<?> arg0)
           
 Type dequeue()
          Removes and returns the top element in the heap
 boolean enqueue(Type arg0)
          Adds the specified element to the heap.
 Type get(int i)
          Allows for random access of the heap data.
 java.util.Collection<Type> getAll()
          Get all of the items in the set.
 Type getTop()
          Returns the top element in the heap without removing it.
 boolean isEmpty()
           
 java.util.Iterator<Type> iterator()
           
 boolean remove(java.lang.Object arg0)
           
 boolean removeAll(java.util.Collection<?> arg0)
           
 boolean retainAll(java.util.Collection<?> arg0)
           
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] arg0)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

HeapSet

public HeapSet()
Creates a new min heap.


HeapSet

public HeapSet(java.util.Collection<Type> arg0)
Creates a new min heap containing the specified items

Parameters:
arg0 -

HeapSet

public HeapSet(HeapSet.HeapType arg0)
Creates a new heap of the specified heap type.

Parameters:
arg0 -

HeapSet

public HeapSet(java.util.Collection<Type> arg0,
               HeapSet.HeapType arg1)
Creates a new heap containing the specified items, with the specified heap type.

Parameters:
arg0 -
arg1 -
Method Detail

add

public boolean add(Type arg0)
Adds an object to the heap

Specified by:
add in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
add in interface java.util.Set<Type extends java.lang.Comparable<Type>>
Parameters:
arg0 -
Returns:

addAll

public boolean addAll(java.util.Collection<? extends Type> arg0)
Add all the objects in the collection to the heap

Specified by:
addAll in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
addAll in interface java.util.Set<Type extends java.lang.Comparable<Type>>
Parameters:
arg0 -
Returns:

clear

public void clear()
Specified by:
clear in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
clear in interface java.util.Set<Type extends java.lang.Comparable<Type>>

contains

public boolean contains(java.lang.Object arg0)
Specified by:
contains in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
contains in interface java.util.Set<Type extends java.lang.Comparable<Type>>

containsAll

public boolean containsAll(java.util.Collection<?> arg0)
Specified by:
containsAll in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
containsAll in interface java.util.Set<Type extends java.lang.Comparable<Type>>

dequeue

public Type dequeue()
Removes and returns the top element in the heap

Returns:
The top element in the heap

enqueue

public boolean enqueue(Type arg0)
Adds the specified element to the heap.

Parameters:
arg0 - The element to add.
Returns:
true if the heap changed as a result of this add.

getTop

public Type getTop()
Returns the top element in the heap without removing it.

Returns:
The top element in the heap, or null if there are no elements.

get

public Type get(int i)
Allows for random access of the heap data. Used for GA's fSelect() fucntions.

Parameters:
i -
Returns:

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
isEmpty in interface java.util.Set<Type extends java.lang.Comparable<Type>>

iterator

public java.util.Iterator<Type> iterator()
Specified by:
iterator in interface java.lang.Iterable<Type extends java.lang.Comparable<Type>>
Specified by:
iterator in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
iterator in interface java.util.Set<Type extends java.lang.Comparable<Type>>

remove

public boolean remove(java.lang.Object arg0)
Specified by:
remove in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
remove in interface java.util.Set<Type extends java.lang.Comparable<Type>>

removeAll

public boolean removeAll(java.util.Collection<?> arg0)
Specified by:
removeAll in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
removeAll in interface java.util.Set<Type extends java.lang.Comparable<Type>>

retainAll

public boolean retainAll(java.util.Collection<?> arg0)
Specified by:
retainAll in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
retainAll in interface java.util.Set<Type extends java.lang.Comparable<Type>>

size

public int size()
Specified by:
size in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
size in interface java.util.Set<Type extends java.lang.Comparable<Type>>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
toArray in interface java.util.Set<Type extends java.lang.Comparable<Type>>

toArray

public <T> T[] toArray(T[] arg0)
Specified by:
toArray in interface java.util.Collection<Type extends java.lang.Comparable<Type>>
Specified by:
toArray in interface java.util.Set<Type extends java.lang.Comparable<Type>>

getAll

public java.util.Collection<Type> getAll()
Get all of the items in the set.

Returns: