org.ws4d.java.structures
Class DataStructure

java.lang.Object
  extended by org.ws4d.java.structures.DataStructure
Direct Known Subclasses:
List, LockedStructure, Set

public abstract class DataStructure
extends java.lang.Object


Constructor Summary
DataStructure()
           
 
Method Summary
 boolean add(java.lang.Object obj)
          Adds a new object to this data structure.
 boolean addAll(DataStructure data)
          Adds all objects contained within data to this instance.
 void clear()
          Clears this data structure by removing all content from it.
 boolean contains(java.lang.Object obj)
          Checks whether obj (or another instance equal to obj in terms of java.lang.Object.equals(Object) ) is already present within this data structure instance and returns true only if this is the case.
 boolean containsAll(DataStructure data)
          Checks whether all items within data are present within this data structure instance and returns true only if this is the case.
 java.lang.String getClassShortName()
          Returns the short name of the class of this DataStructure instance.
 int hashCode()
           
 boolean isEmpty()
          Checks whether this instance is empty or not.
abstract  Iterator iterator()
          Returns an iterator over all items stored within this data structure instance.
 boolean remove(java.lang.Object obj)
          Removes obj from this data structure.
abstract  int size()
          Returns the current size of the data structure.
 java.lang.Object[] toArray()
          Returns an array containing all items stored within this data structure.
 java.lang.Object[] toArray(java.lang.Object[] objects)
          Stores all contained items into the passed-in array objects.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataStructure

public DataStructure()
Method Detail

add

public boolean add(java.lang.Object obj)
Adds a new object to this data structure.

Parameters:
obj - the object to add
Returns:
true if the object was actually added, false in any other case (e.g. adding an object to a set which already contains the same object in terms of java.lang.Object.equals(Object))

addAll

public boolean addAll(DataStructure data)
Adds all objects contained within data to this instance.

Parameters:
data - the objects to add
Returns:
true if at least one object from data was actually added, i.e. a modification was made to this instance, false in any other case (e.g. adding objects to a set which already contains them in terms of java.lang.Object.equals(Object))

clear

public void clear()
Clears this data structure by removing all content from it.


contains

public boolean contains(java.lang.Object obj)
Checks whether obj (or another instance equal to obj in terms of java.lang.Object.equals(Object) ) is already present within this data structure instance and returns true only if this is the case.

Parameters:
obj - the object to check the presence of
Returns:
true if obj is contained by this instance, false if not

containsAll

public boolean containsAll(DataStructure data)
Checks whether all items within data are present within this data structure instance and returns true only if this is the case.

Parameters:
data - the items to check the presence of
Returns:
true if all objects within data are contained by this instance, false if at least one of them is not

getClassShortName

public java.lang.String getClassShortName()
Returns the short name of the class of this DataStructure instance.

Returns:
the short name of this data structure instance's class

isEmpty

public boolean isEmpty()
Checks whether this instance is empty or not.

Returns:
true if this data structure is empty, false otherwise

remove

public boolean remove(java.lang.Object obj)
Removes obj from this data structure. Returns true if obj was actually present and thus it was really removed (i.e. this instance was modified by the method call).

Parameters:
obj - the object to remove
Returns:
true only if obj was actually removed

toArray

public java.lang.Object[] toArray()
Returns an array containing all items stored within this data structure. The array will be of length size(), i.e. for an empty data structure an array of length zero is returned (rather than null).

Returns:
an array of all objects contained within this data structure instance; this method never returns null

toArray

public java.lang.Object[] toArray(java.lang.Object[] objects)
Stores all contained items into the passed-in array objects. Returns the same array.

The array is expected not to be null and to be of exactly size() length. Otherwise, either a java.lang.NullPointerException or an java.lang.IllegalArgumentException will be thrown.

Parameters:
objects - the array to store this data structure's content to
Returns:
the same array as the one passed in (objects), however after having been filled with all objects contained within this data structure instance

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

iterator

public abstract Iterator iterator()
Returns an iterator over all items stored within this data structure instance. The iterator will walk through the items in the natural order of this data structure; i.e. for a list-like structure this will be the same order as the one defined by the list.

Returns:
an iterator over all stored objects

size

public abstract int size()
Returns the current size of the data structure.

Returns:
the size of this data structure