edu.cornell.cs.cs2110
Class AbstractBag<T>

java.lang.Object
  extended by edu.cornell.cs.cs2110.AbstractBag<T>
Type Parameters:
T - the type of elements contained in this Bag.
All Implemented Interfaces:
Bag<T>, Iterable<T>
Direct Known Subclasses:
AdjustablePriorityQueue, PriorityQueue, Queue, RandomBag, Stack

public abstract class AbstractBag<T>
extends Object
implements Bag<T>

An adapter implementation of the Bag interface. Provides default implementations of iterator() and isEmpty(). Subclasses need only implement insert(Object), extract(), size(), and clear().


Constructor Summary
AbstractBag()
           
 
Method Summary
abstract  void clear()
          Removes all elements from the data structure.
abstract  T extract()
          Extracts an element from the data structure.
abstract  void insert(T item)
          Inserts an element into the data structure.
 boolean isEmpty()
          Tests whether the data structure is empty.
 Iterator<T> iterator()
          The Iterator, unless it is overridden in the concrete subclass, produces elements in the same order that repeated execution of extract() would.
abstract  int size()
          Returns the number of elements contained in the data structure.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBag

public AbstractBag()
Method Detail

insert

public abstract void insert(T item)
Inserts an element into the data structure.

Specified by:
insert in interface Bag<T>
Parameters:
item - the element to insert

extract

public abstract T extract()
                   throws NoSuchElementException
Extracts an element from the data structure. The element is deleted.

Specified by:
extract in interface Bag<T>
Returns:
the element extracted
Throws:
NoSuchElementException - if the data structure is empty

isEmpty

public boolean isEmpty()
Tests whether the data structure is empty.

Specified by:
isEmpty in interface Bag<T>
Returns:
true if the data structure contains no elements

size

public abstract int size()
Returns the number of elements contained in the data structure.

Specified by:
size in interface Bag<T>
Returns:
the number of elements

clear

public abstract void clear()
Removes all elements from the data structure.

Specified by:
clear in interface Bag<T>

iterator

public Iterator<T> iterator()
The Iterator, unless it is overridden in the concrete subclass, produces elements in the same order that repeated execution of extract() would. Note that this is not guaranteed by java.util.Stack, for example.

Specified by:
iterator in interface Iterable<T>