structure
Class AbstractStructure

java.lang.Object
  extended by structure.AbstractStructure
All Implemented Interfaces:
Structure
Direct Known Subclasses:
AbstractLinear, AbstractList, AbstractSet, BinarySearchTree, GraphList, GraphMatrix, OrderedList, OrderedVector

public abstract class AbstractStructure
extends java.lang.Object
implements Structure

An abstract implementation of a basic, mutable data structure.

This abstract implementation of the Structure interface provides a good starting point for the implementation of a basic, mutable data structure. This implementation provides a workable implementation of isEmpty, contains, and values.

Where more efficient implementations are possible, the user may wish to override these methods. For example, an implementor may have a structure directly implement the java.util.Collection interface and have the value method simply return this. Because of peculiarities of both systems of designing data structures, it is often best to avoid direct implementation java.util.Collection and Structure in one class.

Since:
Java Structures, 2nd edition

Constructor Summary
AbstractStructure()
          The default constructor.
 
Method Summary
 boolean contains(java.lang.Object value)
          Determines if the structure contains a value.
 java.util.Enumeration elements()
          Return an enumeration associated with this structure.
 int hashCode()
           
 boolean isEmpty()
          Determine if there are elements within the structure.
 java.util.Collection values()
          Returns a java.util.Collection wrapping this structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface structure.Structure
add, clear, iterator, remove, size
 

Constructor Detail

AbstractStructure

public AbstractStructure()
The default constructor. Initializes any internal variables.

Postcondition:
initializes internal variables
Method Detail

isEmpty

public boolean isEmpty()
Determine if there are elements within the structure.

Specified by:
isEmpty in interface Structure
Returns:
true if the structure is empty; false otherwise
Postcondition:
return true iff the structure is empty

elements

public java.util.Enumeration elements()
Return an enumeration associated with this structure. This implementation returns an AbstractIterator which supports both enumeration at iterator techniques.

Specified by:
elements in interface Structure
Returns:
a Enumeration for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration
Precondition:
this implementation assumes the structure returns an AbstractIterator, which may then be used for generating the Enumeration.
Postcondition:
return an enumeration for traversing the struture; all structure package implementations return an AbstractIterator

contains

public boolean contains(java.lang.Object value)
Determines if the structure contains a value.

Specified by:
contains in interface Structure
Parameters:
value - non-null value to be found within structure
Returns:
true when some value equals value
Precondition:
value is non-null
Postcondition:
returns true iff value.equals some value in structure

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Postcondition:
generate a hashcode for the structure: sum of all the hash codes of elements

values

public java.util.Collection values()
Returns a java.util.Collection wrapping this structure. This particular implementation returns a StructCollection whose methods may not provide the most efficent implementations of non-Structure Collection methods.

Specified by:
values in interface Structure
Returns:
a Collection that is equivalent to this structure
See Also:
StructCollection, Collection
Postcondition:
returns a Collection that may be used with Java's Collection Framework