structure
Class StructCollection

java.lang.Object
  extended by structure.StructCollection
All Implemented Interfaces:
Iterable, Collection

public class StructCollection
extends Object
implements Collection

This utility class converts a Structure to a Collection. Users are advised to make use of the values method that is part of every Structure that returns a Collection.

This class is necessary because there are certain basic differences in the interfaces of the two classes.

This class works provides a facade: methods of the Collection interface are directly referred to the base Structure, or simple code supports the interface.

Since:
Java Structures, 2nd edition

Constructor Summary
StructCollection(Structure s)
          Constructs a Collection, based on the contents of the subordinate Structure object.
 
Method Summary
 boolean add(Object o)
          Add an object to the subordinate Structure, and return boolean indicating success.
 boolean addAll(Collection c)
          Adds all the elements of another collection (c) into this Structure.
 void clear()
          Remove all elements from the Structure.
 boolean contains(Object o)
          Returns true iff object o is contained within the subordinate structure.
 boolean containsAll(Collection c)
          Returns true if all of the elements of c are contained within the subordinate structure.
 boolean equals(Object o)
          Compare one StructCollection with another.
 int hashCode()
          Return hash code.
 boolean isEmpty()
          Detect an empty structure.
 Iterator iterator()
          Return an iterator to traverse the subordinate structure.
 boolean remove(Object o)
          Removes an instance of object o, if it appears within structure.
 boolean removeAll(Collection c)
          Removes all objects found within collection c from this collection.
 boolean retainAll(Collection c)
          Retains elements of this Collection that are also in c.
 int size()
          Determine the number of elements in this collection.
 Object[] toArray()
          Construct an array of values found in the subordinate Structure.
 Object[] toArray(Object[] target)
          Copy elements of this structure into target array.
 String toString()
          Construct a string representation of this class.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StructCollection

public StructCollection(Structure s)
Constructs a Collection, based on the contents of the subordinate Structure object.

Method Detail

add

public boolean add(Object o)
Add an object to the subordinate Structure, and return boolean indicating success.

Specified by:
add in interface Collection
Returns:
true.

addAll

public boolean addAll(Collection c)
Adds all the elements of another collection (c) into this Structure. A boolean value of true is returned.

Specified by:
addAll in interface Collection
Returns:
true if each of the adds returned true.

clear

public void clear()
Remove all elements from the Structure.

Specified by:
clear in interface Collection

contains

public boolean contains(Object o)
Returns true iff object o is contained within the subordinate structure.

Specified by:
contains in interface Collection

containsAll

public boolean containsAll(Collection c)
Returns true if all of the elements of c are contained within the subordinate structure.

Specified by:
containsAll in interface Collection
Returns:
true if c is a subset of this

equals

public boolean equals(Object o)
Compare one StructCollection with another.

Specified by:
equals in interface Collection
Overrides:
equals in class Object
Returns:
true iff Structures are equals

hashCode

public int hashCode()
Return hash code.

Specified by:
hashCode in interface Collection
Overrides:
hashCode in class Object
Returns:
hash code of subordinate structure.

isEmpty

public boolean isEmpty()
Detect an empty structure.

Specified by:
isEmpty in interface Collection
Returns:
true iff subordinate structure is empty.

iterator

public Iterator iterator()
Return an iterator to traverse the subordinate structure.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Returns:
the iterator over the subordinate structure.

remove

public boolean remove(Object o)
Removes an instance of object o, if it appears within structure.

Specified by:
remove in interface Collection
Returns:
returns true if instance was found and removed.

removeAll

public boolean removeAll(Collection c)
Removes all objects found within collection c from this collection.

Specified by:
removeAll in interface Collection
Returns:
true if every element of c could be removed from this.

retainAll

public boolean retainAll(Collection c)
Retains elements of this Collection that are also in c.

Specified by:
retainAll in interface Collection
Returns:
true iff this Collection was changed by this operation

size

public int size()
Determine the number of elements in this collection.

Specified by:
size in interface Collection
Returns:
the number of elements in this collection.

toArray

public Object[] toArray()
Construct an array of values found in the subordinate Structure.

Specified by:
toArray in interface Collection
Returns:
array containing exactly the elements of this structure

toArray

public Object[] toArray(Object[] target)
Copy elements of this structure into target array.

Specified by:
toArray in interface Collection
Returns:
the array of values

toString

public String toString()
Construct a string representation of this class.

Overrides:
toString in class Object
Returns:
string representing this class