Version: 1.1.1

org.biomoby.shared.data
Class MobyDataObjectSet

java.lang.Object
  extended by org.biomoby.shared.MobyData
      extended by org.biomoby.shared.MobyPrimaryData
          extended by org.biomoby.shared.MobyPrimaryDataSet
              extended by org.biomoby.shared.data.MobyDataObjectSet
All Implemented Interfaces:
Cloneable, Iterable<MobyDataObject>, Collection<MobyDataObject>, MobyDataInstance
Direct Known Subclasses:
MobyDataObjectSetDeferred, MobyDataObjectSetSAI

public class MobyDataObjectSet
extends MobyPrimaryDataSet
implements MobyDataInstance, Collection<MobyDataObject>

This class adds to MobyPrimaryDataSet the ability to get and set instantiated MOBY objects. The MOBY Collection concept that this class embodies is a mathematical bag, i.e. it can contain the same value more than once. This class implements java.util.Collection to facilitate the manipulation of the bag, enforcing that all members of the bag be non-null, MobyDataObject objects. The collection can be empty, but never null. NOTE: The order of members of the collection is meaningless, and may change throughout the life of this object. Do not rely on the order of the items at any time! This class uses a Vector to hold the bag elements and implement most Collection functions.


Field Summary
 
Fields inherited from interface org.biomoby.shared.data.MobyDataInstance
CENTRAL_XML_MODE, SERVICE_XML_MODE
 
Constructor Summary
MobyDataObjectSet(Element e)
           
MobyDataObjectSet(Element e, Registry registry)
           
MobyDataObjectSet(String name)
          Creates an empty collection bag with a name.
MobyDataObjectSet(String name, Collection<? extends MobyDataObject> c)
          Creates a collection with a name, initializing the members with the members of the given collection.
MobyDataObjectSet(String name, MobyDataObject[] values)
          Creates a collection with a name, initializing the members with the given array.
MobyDataObjectSet(String name, Registry reg)
           
 
Method Summary
 boolean add(MobyDataObject mdo)
          Add a single MobyDataObject to the collection.
 boolean addAll(Collection<? extends MobyDataObject> c)
          Convenient way to add the input collection of MobyDataObjects (usually a MobyDataObjectSet, or a Vector of MobyDataObjects) to this collection.
 void addNamespace(MobyNamespace value)
          Add given namespace of all elements of this collection.
 void clear()
          Removes all of the MobyDataObject elements from this collection.
 MobyDataObjectSet clone()
          Must be overwritten by a subclass.
 boolean contains(Object mdsi)
           
 boolean containsAll(Collection c)
           
 boolean equals(Object set)
          Compare two MobyDataObject collections.
static Collection<? extends MobyDataObject> getChildren(Element e, Registry registry)
           
 MobyDataType getDataType()
          Return the least upper bound parent class of all items in the collection.
 MobyDataObject[] getElementInstances()
           
 MobyPrimaryDataSimple[] getElements()
           
 MobyNamespace[] getNamespaces()
          Return namespaces that occur in all items of the collection.
 Object getObject()
          Each implementer will return the underlying Java object used to store the MOBY value.
 int getXmlMode()
          Report whether toXML will produce Central template or service call instance XML.
 int hashCode()
          Implemented solely because of the general contract that c1.equals(c2) implies that c1.hashCode()==c2.hashCode()
 boolean isEmpty()
          Logically equivalent to size() == 0.
 Iterator<MobyDataObject> iterator()
           
 boolean remove(Object mdsi)
          Removes a single instance of an element from this collection, if it satisfies mdsi.equals().
 boolean removeAll(Collection c)
          Set theory subtraction operator implementation.
 void removeNamespace(MobyNamespace value)
          Remove given namespace from all elements of this collection.
 void removeNamespace(String namespaceName)
          Remove given namespace (defined by its name) from all elements of this collection.
 boolean retainAll(Collection c)
          Set theory intersection operator implementation.
 void setElements(MobyDataObject[] values)
          Replace whatever is in the collection right now with the values in the input array.
 void setNamespaces(MobyNamespace[] values)
          Set given namespaces of all elements of this collection.
 void setXmlMode(int mode)
          Determined whether toXML will return a Central template value or a service call instance value.
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] classArray)
          Don't use this method if at all possible.
 String toXML()
          Wraps the simple instances' XML in a MOBY Collection tag
 
Methods inherited from class org.biomoby.shared.MobyPrimaryDataSet
addElement, format, setDataType, setElements, toString
 
Methods inherited from class org.biomoby.shared.MobyPrimaryData
isPrimary
 
Methods inherited from class org.biomoby.shared.MobyData
getId, getName, getUserData, setId, setName, setUserData
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.biomoby.shared.data.MobyDataInstance
getName, getUserData, setName, setUserData
 

Constructor Detail

MobyDataObjectSet

public MobyDataObjectSet(Element e)
                  throws MobyException
Throws:
MobyException

MobyDataObjectSet

public MobyDataObjectSet(Element e,
                         Registry registry)
                  throws MobyException
Throws:
MobyException

MobyDataObjectSet

public MobyDataObjectSet(String name)
Creates an empty collection bag with a name.


MobyDataObjectSet

public MobyDataObjectSet(String name,
                         Registry reg)

MobyDataObjectSet

public MobyDataObjectSet(String name,
                         MobyDataObject[] values)
                  throws NullPointerException
Creates a collection with a name, initializing the members with the given array. The registry is inferred from the input values. If the values array is blank, the default registry is used. This can be avoided by using the (name, registry) c-tor instead, which created a blank array for you automatically.

Parameters:
values - a set of MobyDataObjects, all from the same registry
Throws:
NullPointerException - if the input array is null, or contains null elements

MobyDataObjectSet

public MobyDataObjectSet(String name,
                         Collection<? extends MobyDataObject> c)
                  throws ClassCastException,
                         NullPointerException
Creates a collection with a name, initializing the members with the members of the given collection.

Parameters:
c - usually another MobyDataObjectSet, or a Vector of MobyDataObjects, all in the same namespace
Throws:
ClassCastException - if a member of the input collection is not a MobyDataObject
NullPointerException - if the collection or one of its members is a null object
Method Detail

getChildren

public static Collection<? extends MobyDataObject> getChildren(Element e,
                                                               Registry registry)
                                                        throws MobyException
Throws:
MobyException

clone

public MobyDataObjectSet clone()
Description copied from class: MobyPrimaryData
Must be overwritten by a subclass.

Overrides:
clone in class MobyPrimaryDataSet

getDataType

public MobyDataType getDataType()
Return the least upper bound parent class of all items in the collection.

Overrides:
getDataType in class MobyPrimaryDataSet

getNamespaces

public MobyNamespace[] getNamespaces()
Return namespaces that occur in all items of the collection. This method relies on MobyNamespace's equals() method to be properly implemented for proper set intersection functionality.

Overrides:
getNamespaces in class MobyPrimaryDataSet

setNamespaces

public void setNamespaces(MobyNamespace[] values)
Set given namespaces of all elements of this collection.

Overrides:
setNamespaces in class MobyPrimaryDataSet

addNamespace

public void addNamespace(MobyNamespace value)
Add given namespace of all elements of this collection.

Overrides:
addNamespace in class MobyPrimaryDataSet

removeNamespace

public void removeNamespace(String namespaceName)
Remove given namespace (defined by its name) from all elements of this collection.

Overrides:
removeNamespace in class MobyPrimaryDataSet

removeNamespace

public void removeNamespace(MobyNamespace value)
Remove given namespace from all elements of this collection.

Overrides:
removeNamespace in class MobyPrimaryDataSet

setElements

public void setElements(MobyDataObject[] values)
                 throws NullPointerException
Replace whatever is in the collection right now with the values in the input array.

Throws:
NullPointerException - if the input array is null, or contains null elements

getObject

public Object getObject()
Description copied from interface: MobyDataInstance
Each implementer will return the underlying Java object used to store the MOBY value. For example, MOBY Floats are stored internally as BigDecimal objects.

Specified by:
getObject in interface MobyDataInstance
Returns:
a Vector with the MobyDataObjects

getElements

public MobyPrimaryDataSimple[] getElements()
Overrides:
getElements in class MobyPrimaryDataSet

getElementInstances

public MobyDataObject[] getElementInstances()
Returns:
the MobyDataObjects that comprise the collection

add

public boolean add(MobyDataObject mdo)
            throws NullPointerException
Add a single MobyDataObject to the collection.

Specified by:
add in interface Collection<MobyDataObject>
Throws:
NullPointerException - if the input is a null object

addAll

public boolean addAll(Collection<? extends MobyDataObject> c)
               throws NullPointerException
Convenient way to add the input collection of MobyDataObjects (usually a MobyDataObjectSet, or a Vector of MobyDataObjects) to this collection.

Specified by:
addAll in interface Collection<MobyDataObject>
Returns:
true if the collection changes as a result of the operation
Throws:
NullPointerException - if the collection or one of its members is a null object

clear

public void clear()
Removes all of the MobyDataObject elements from this collection.

Specified by:
clear in interface Collection<MobyDataObject>

contains

public boolean contains(Object mdsi)
                 throws ClassCastException,
                        NullPointerException
Specified by:
contains in interface Collection<MobyDataObject>
Returns:
true if this collection contains an element with the exact same value (equivalent in MOBY XML representation, including name)
Throws:
ClassCastException - if the input is not a MobyDataObject
NullPointerException - if the input is a null object

containsAll

public boolean containsAll(Collection c)
                    throws ClassCastException,
                           NullPointerException
Specified by:
containsAll in interface Collection<MobyDataObject>
Returns:
true if each element in the input collection returns true when contains(Object o) is called
Throws:
ClassCastException - if a member of the input collection is not a MobyDataObject
NullPointerException - if the collection or one of its members is a null object

equals

public boolean equals(Object set)
               throws ClassCastException,
                      NullPointerException
Compare two MobyDataObject collections. Note that this may be a very expensive operation if the lists are long, the equals() method is complicated, or collection is hard to convert into an array for sorting.

Specified by:
equals in interface Collection<MobyDataObject>
Overrides:
equals in class Object
Returns:
true if and only if the input object is a MobyDataObjectSet, and the two collections contain exactly equal elements from a MOBY XML perspective
Throws:
ClassCastException - if the input is not a Collection of MobyDataObjects
NullPointerException - if the input is a null object

hashCode

public int hashCode()
Implemented solely because of the general contract that c1.equals(c2) implies that c1.hashCode()==c2.hashCode()

Specified by:
hashCode in interface Collection<MobyDataObject>
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Logically equivalent to size() == 0.

Specified by:
isEmpty in interface Collection<MobyDataObject>

iterator

public Iterator<MobyDataObject> iterator()
Specified by:
iterator in interface Iterable<MobyDataObject>
Specified by:
iterator in interface Collection<MobyDataObject>
Returns:
an iterator over the non-null MobyDataObjects in this collection

remove

public boolean remove(Object mdsi)
               throws ClassCastException,
                      NullPointerException
Removes a single instance of an element from this collection, if it satisfies mdsi.equals().

Specified by:
remove in interface Collection<MobyDataObject>
Parameters:
mdsi - the MobyDataObject whose value equivalent (not object reference) is to be removed
Returns:
true if the element was found and removed
Throws:
ClassCastException - if the input is not a MobyDataObject
NullPointerException - if the input is a null object

removeAll

public boolean removeAll(Collection c)
                  throws ClassCastException,
                         NullPointerException
Set theory subtraction operator implementation.

Specified by:
removeAll in interface Collection<MobyDataObject>
Returns:
true if this collection changed as a result of the call
Throws:
ClassCastException - if a member of the input collection is not a MobyDataObject
NullPointerException - if the collection or one of its members is a null object

retainAll

public boolean retainAll(Collection c)
Set theory intersection operator implementation.

Specified by:
retainAll in interface Collection<MobyDataObject>
Returns:
true if this collection changed as a result of the call
Throws:
ClassCastException - if a member of the input collection is not a MobyDataObject
NullPointerException - if the collection or one of its members is a null object

size

public int size()
Specified by:
size in interface Collection<MobyDataObject>
Returns:
the number of elements in this collection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<MobyDataObject>
Returns:
a MobyDataObject[] with the collection members

toArray

public <T> T[] toArray(T[] classArray)
            throws ArrayStoreException,
                   NullPointerException
Don't use this method if at all possible. It is only defined because of the Collection interface requirement. Use toArray() instead. This method will only work if the input array is a MobyDataObject[], or MobyDataInt[], MobyDataFloat[], etc. if you know for sure that all of the collection elements are of a particular MOBY primitive subtype. Otherwise an ArrayStoreException will be thrown.

Specified by:
toArray in interface Collection<MobyDataObject>
Throws:
ArrayStoreException
NullPointerException

setXmlMode

public void setXmlMode(int mode)
                throws IllegalArgumentException
Determined whether toXML will return a Central template value or a service call instance value.

Specified by:
setXmlMode in interface MobyDataInstance
Parameters:
mode - one of MobyDataInstance.CENTRAL_XML_MODE or MobyDataInstance.SERVICE_XML_MODE
Throws:
IllegalArgumentException - if the mode is not one of the specified values

getXmlMode

public int getXmlMode()
Report whether toXML will produce Central template or service call instance XML.

Specified by:
getXmlMode in interface MobyDataInstance
Returns:
one of MobyDataInstance.CENTRAL_XML_MODE or MobyDataInstance.SERVICE_XML_MODE

toXML

public String toXML()
Wraps the simple instances' XML in a MOBY Collection tag

Specified by:
toXML in interface MobyDataInstance
Overrides:
toXML in class MobyPrimaryDataSet

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010