© 1998-2002 McGraw-Hill

structure
Interface Structure

All Known Subinterfaces:
Graph, Linear, List, OrderedStructure, Queue, Set, Stack
All Known Implementing Classes:
AbstractStructure

public interface Structure

The interface of a basic, mutable data structure.

This interface is the basis for most mutable structures in the structure package. While most methods are easy implement, it is often sufficient to simply extend a basic, abstract implementation of this class, the AbstractStructure. The AbstractStructure implements the isEmpty, contains and collection methods. They may be overridden if a particularly efficient technique is to be preferred.

Since:
Java Structures, 2nd edition

Method Summary
 void add(Object value)
          Inserts value in some structure-specific location.
 void clear()
          Removes all elements from the structure.
 boolean contains(Object value)
          Determines if the structure contains a value.
 Enumeration elements()
          Returns an enumeration for traversing the structure.
 boolean isEmpty()
          Determine if there are elements within the structure.
 Iterator iterator()
          Returns an iterator for traversing the structure.
 Object remove(Object value)
          Removes value from the structure.
 int size()
          Determine the size of the structure.
 Collection values()
          Returns a java.util.Collection wrapping this structure.
 

Method Detail

size

public int size()
Determine the size of the structure.
Postcondition:
computes number of elements contained in structure
Returns:
the size of the structure

isEmpty

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

clear

public void clear()
Removes all elements from the structure.
Postcondition:
the structure is empty

contains

public boolean contains(Object value)
Determines if the structure contains a value.
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

add

public void add(Object value)
Inserts value in some structure-specific location.
Parameters:
value - the value to be added to the structure; non-null
Precondition:
value is non-null
Postcondition:
value has been added to the structure replacement policy is not specified

remove

public Object remove(Object value)
Removes value from the structure.
Parameters:
value - value matching the value to be removed
Precondition:
value is non-null
Postcondition:
value is removed from structure, if it was there
Returns:
returns the value that was replaced, or null if none.

elements

public Enumeration elements()
Returns an enumeration for traversing the structure.
Postcondition:
returns an enumeration for traversing structure; all structure package implementations return an AbstractIterator
Returns:
an enumeration for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration, iterator()

iterator

public Iterator iterator()
Returns an iterator for traversing the structure.
Postcondition:
returns an iterator for traversing structure; all structure package implementations return an AbstractIterator
Returns:
an iterator for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration, elements()

values

public Collection values()
Returns a java.util.Collection wrapping this structure.
Postcondition:
returns a Collection that may be used with Java's Collection Framework
Returns:
a Collection that is equivalent to this structure

© 1998-2002 McGraw-Hill