© 1998-2002 McGraw-Hill

structure
Class AbstractStructure

java.lang.Object
  |
  +--structure.AbstractStructure
All Implemented Interfaces:
Structure
Direct Known Subclasses:
AbstractLinear, AbstractList, AbstractSet, BinarySearchTree, GraphList, GraphMatrix, OrderedList, OrderedVector, RedBlackSearchTree

public abstract class AbstractStructure
extends 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(Object value)
          Determines if the structure contains a value.
 Enumeration elements()
          Return an enumeration associated with this structure.
 int hashCode()
           
 boolean isEmpty()
          Determine if there are elements within the structure.
 Collection values()
          Returns a java.util.Collection wrapping this structure.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, notify, notifyAll, registerNatives, 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.
Method Detail

isEmpty

public boolean isEmpty()
Determine if there are elements within the structure.
Specified by:
isEmpty in interface Structure
Postcondition:
return true iff the structure is empty
Returns:
true if the structure is empty; false otherwise

elements

public 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
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
Returns:
a Enumeration for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration

contains

public boolean contains(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
Precondition:
value is non-null
Postcondition:
returns true iff value.equals some value in structure
Returns:
true when some value equals value

hashCode

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

values

public 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
Postcondition:
returns a Collection that may be used with Java's Collection Framework
Returns:
a Collection that is equivalent to this structure
See Also:
StructCollection, Collection

© 1998-2002 McGraw-Hill