be.SIRAPRISE.client
Class AbstractTupleContainer

java.lang.Object
  extended by be.SIRAPRISE.client.AbstractTupleContainer
All Implemented Interfaces:
TupleContainer, java.lang.Iterable<Tuple>
Direct Known Subclasses:
AbstractRelation, AbstractTupleBag

public abstract class AbstractTupleContainer
extends java.lang.Object
implements TupleContainer

Abstract implementation of the TupleContainer interface

Author:
Erwin Smout

Constructor Summary
AbstractTupleContainer(Heading heading)
          Creates the container, setting the intended heading for the tuples
 
Method Summary
 void addTuplesWithHeadingCheck(TupleContainer tupleContainer)
          Adds all tuples of the given TupleContainer to this one.
 void addTuplesWithoutHeadingCheck(TupleContainer tupleContainer)
          Adds all tuples of the given TupleContainer to this one.
 void addTupleWithHeadingCheck(Tuple tuple)
          Adds a Tuple to the container.
abstract  void addTupleWithoutHeadingCheck(Tuple tuple)
          Adds a Tuple to the container without checking the conformance of the tuple to the declared heading.
 Heading getHeading()
          Gets The heading for tuple container.
abstract  java.util.Iterator<Tuple> iterator()
          Gets an iterator over the tuples in the container
 java.lang.String printBodyEscapedWithBodyHeaderWithoutTypeNames()
          Gets the relation body in text
 java.lang.String printBodyEscapedWithBodyHeaderWithTypeNames()
          Gets the relation body in text
 java.lang.String printBodyEscapedWithoutBodyHeaderWithoutTypeNames()
          Gets the relation body in text EXCLUDING the BODY( ) container
 java.lang.String printBodyEscapedWithoutBodyHeaderWithTypeNames()
          Gets the relation body in text EXCLUDING the BODY( ) container
 java.lang.String printBodyWithBodyHeaderWithoutTypeNames()
          Gets a relation body in text
 java.lang.String printBodyWithBodyHeaderWithTypeNames()
          Gets a relation body in text
 java.lang.String printBodyWithoutBodyHeaderWithoutTypeNames()
          Gets the relation body in text EXCLUDING the BODY( ) container
 java.lang.String printBodyWithoutBodyHeaderWithTypeNames()
          Gets the relation body in text EXCLUDING the BODY( ) container
 java.lang.String printBodyXMLWithBodyHeader()
          Gets the relation body in XML-style text
 java.lang.String printBodyXMLWithoutBodyHeader()
          Gets the relation body in XML-style text EXCLUDING the container
 java.lang.String printValueEscapedWithoutTypeNames()
          Gets this relation value in SIRAPRISE syntactical format (i.e. including the SIRA_PRISE escape token preceding any appearance of the tokens '(', ')' and '\' in scalar attribute values in the relation.
 java.lang.String printValueEscapedWithTypeNames()
          Gets this relation value in SIRAPRISE syntactical format (i.e. including the SIRA_PRISE escape token preceding any appearance of the tokens '(', ')' and '\' in scalar attribute values in the relation.
 java.lang.String printValueWithoutTypeNames()
          Gets this relation value in 'plain text' format (i.e. if a scalar attribute value includes any of the tokens '(', ')' or '\', these will appear 'as is' in the string value and will not be replaced by the appropriate SIRA_PRISE escape sequence.
 java.lang.String printValueWithTypeNames()
          Gets this relation value in 'plain text' format (i.e. if a scalar attribute value includes any of the tokens '(', ')' or '\', these will appear 'as is' in the string value and will not be replaced by the appropriate SIRA_PRISE escape sequence.
 java.lang.String printValueXML()
          Gets this relation value in 'XML text' format.
abstract  boolean removeTuple(Tuple t)
          Removes the given tuple from this container if that tuple appears there
 int removeTuples(TupleContainer tupleContainer)
          Removes all tuples appearing in the given tupleContainer from this tupleContainer if that tuple appears there
abstract  int size()
          Gets The number of tuples that appear in the relation.
<C> C[]
toObjectArray(java.lang.Class<C> objectClass)
          Get an array of objects holding the same information as that which is held in this TupleContainer.
<C> C[]
toObjectArrayIgnoringMissingSetters(java.lang.Class<C> objectClass)
          Get an array of objects holding a (potentially proper) subset of the information held in this TupleContainer.
<C> java.util.Collection<C>
toObjectCollection(java.lang.Class<C> objectClass)
          Get a collection of objects holding the same information as that which is held in this TupleContainer.
<C> java.util.Collection<C>
toObjectCollectionIgnoringMissingSetters(java.lang.Class<C> objectClass)
          Get a collection of objects holding a (potentially proper) subset of the information held in this TupleContainer.
 java.util.Map<java.lang.Class<?>,java.lang.Object>[] toObjectsArray(java.lang.Class<?>[] objectClass)
          Get an array of Maps of objects holding the same information as that which is held in this TupleContainer.
 java.util.Collection<java.util.Map<java.lang.Class<?>,java.lang.Object>> toObjectsCollection(java.lang.Class<?>[] objectClass)
          Get a collection of Maps of objects holding the same information as that which is held in this TupleContainer.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface be.SIRAPRISE.client.TupleContainer
clear, containsTuple, containsTuples
 

Constructor Detail

AbstractTupleContainer

public AbstractTupleContainer(Heading heading)
Creates the container, setting the intended heading for the tuples

Parameters:
heading - The heading for tuple container.
Method Detail

addTuplesWithHeadingCheck

public final void addTuplesWithHeadingCheck(TupleContainer tupleContainer)
Adds all tuples of the given TupleContainer to this one.

Specified by:
addTuplesWithHeadingCheck in interface TupleContainer
Parameters:
tupleContainer - The TupleContainer whose tuples are all to be added to this one

addTuplesWithoutHeadingCheck

public final void addTuplesWithoutHeadingCheck(TupleContainer tupleContainer)
Adds all tuples of the given TupleContainer to this one.

Specified by:
addTuplesWithoutHeadingCheck in interface TupleContainer
Parameters:
tupleContainer - The TupleContainer whose tuples are all to be added to this one

addTupleWithHeadingCheck

public final void addTupleWithHeadingCheck(Tuple tuple)
Adds a Tuple to the container.

Specified by:
addTupleWithHeadingCheck in interface TupleContainer
Parameters:
tuple - The tuple to be added to the container

addTupleWithoutHeadingCheck

public abstract void addTupleWithoutHeadingCheck(Tuple tuple)
Adds a Tuple to the container without checking the conformance of the tuple to the declared heading. The conformance should be guaranteed externally to this method.

Specified by:
addTupleWithoutHeadingCheck in interface TupleContainer
Parameters:
tuple - The tuple to be added to the container

getHeading

public final Heading getHeading()
Gets The heading for tuple container.

Specified by:
getHeading in interface TupleContainer
Returns:
The heading for tuple container.

iterator

public abstract java.util.Iterator<Tuple> iterator()
Gets an iterator over the tuples in the container

Specified by:
iterator in interface TupleContainer
Specified by:
iterator in interface java.lang.Iterable<Tuple>
Returns:
an iterator over the tuples in the container

printBodyEscapedWithBodyHeaderWithoutTypeNames

public final java.lang.String printBodyEscapedWithBodyHeaderWithoutTypeNames()
Gets the relation body in text

Returns:
The relation body in text

printBodyEscapedWithBodyHeaderWithTypeNames

public final java.lang.String printBodyEscapedWithBodyHeaderWithTypeNames()
Gets the relation body in text

Returns:
The relation body in text

printBodyEscapedWithoutBodyHeaderWithoutTypeNames

public final java.lang.String printBodyEscapedWithoutBodyHeaderWithoutTypeNames()
Gets the relation body in text EXCLUDING the BODY( ) container

Returns:
The relation body in text EXCLUDING the BODY( ) container

printBodyEscapedWithoutBodyHeaderWithTypeNames

public final java.lang.String printBodyEscapedWithoutBodyHeaderWithTypeNames()
Gets the relation body in text EXCLUDING the BODY( ) container

Returns:
The relation body in text EXCLUDING the BODY( ) container

printBodyWithBodyHeaderWithoutTypeNames

public final java.lang.String printBodyWithBodyHeaderWithoutTypeNames()
Gets a relation body in text

Returns:
The relation body in text

printBodyWithBodyHeaderWithTypeNames

public final java.lang.String printBodyWithBodyHeaderWithTypeNames()
Gets a relation body in text

Returns:
The relation body in text

printBodyWithoutBodyHeaderWithoutTypeNames

public final java.lang.String printBodyWithoutBodyHeaderWithoutTypeNames()
Gets the relation body in text EXCLUDING the BODY( ) container

Returns:
The relation body in text EXCLUDING the BODY( ) container

printBodyWithoutBodyHeaderWithTypeNames

public final java.lang.String printBodyWithoutBodyHeaderWithTypeNames()
Gets the relation body in text EXCLUDING the BODY( ) container

Returns:
The relation body in text EXCLUDING the BODY( ) container

printBodyXMLWithBodyHeader

public final java.lang.String printBodyXMLWithBodyHeader()
Gets the relation body in XML-style text

Returns:
the relation body in XML-style text

printBodyXMLWithoutBodyHeader

public final java.lang.String printBodyXMLWithoutBodyHeader()
Gets the relation body in XML-style text EXCLUDING the container

Returns:
the relation body in XML-style text EXCLUDING the container

printValueEscapedWithoutTypeNames

public final java.lang.String printValueEscapedWithoutTypeNames()
Description copied from interface: TupleContainer
Gets this relation value in SIRAPRISE syntactical format (i.e. including the SIRA_PRISE escape token preceding any appearance of the tokens '(', ')' and '\' in scalar attribute values in the relation.

Specified by:
printValueEscapedWithoutTypeNames in interface TupleContainer
Returns:
this relation value in SIRAPRISE syntactical format

printValueEscapedWithTypeNames

public final java.lang.String printValueEscapedWithTypeNames()
Description copied from interface: TupleContainer
Gets this relation value in SIRAPRISE syntactical format (i.e. including the SIRA_PRISE escape token preceding any appearance of the tokens '(', ')' and '\' in scalar attribute values in the relation.

Specified by:
printValueEscapedWithTypeNames in interface TupleContainer
Returns:
this relation value in SIRAPRISE syntactical format

printValueWithoutTypeNames

public final java.lang.String printValueWithoutTypeNames()
Description copied from interface: TupleContainer
Gets this relation value in 'plain text' format (i.e. if a scalar attribute value includes any of the tokens '(', ')' or '\', these will appear 'as is' in the string value and will not be replaced by the appropriate SIRA_PRISE escape sequence.

Specified by:
printValueWithoutTypeNames in interface TupleContainer
Returns:
this relation value in 'plain text' format.

printValueWithTypeNames

public final java.lang.String printValueWithTypeNames()
Description copied from interface: TupleContainer
Gets this relation value in 'plain text' format (i.e. if a scalar attribute value includes any of the tokens '(', ')' or '\', these will appear 'as is' in the string value and will not be replaced by the appropriate SIRA_PRISE escape sequence.

Specified by:
printValueWithTypeNames in interface TupleContainer
Returns:
this relation value in 'plain text' format.

printValueXML

public final java.lang.String printValueXML()
Description copied from interface: TupleContainer
Gets this relation value in 'XML text' format.

Specified by:
printValueXML in interface TupleContainer
Returns:
this relation value in 'plain text' format.

removeTuple

public abstract boolean removeTuple(Tuple t)
Description copied from interface: TupleContainer
Removes the given tuple from this container if that tuple appears there

Specified by:
removeTuple in interface TupleContainer
Parameters:
t - The tuple to be removed from the container
Returns:
true if the tuple was removed, false if it was not found in this TupleContainer

removeTuples

public final int removeTuples(TupleContainer tupleContainer)
Description copied from interface: TupleContainer
Removes all tuples appearing in the given tupleContainer from this tupleContainer if that tuple appears there

Specified by:
removeTuples in interface TupleContainer
Parameters:
tupleContainer - The tupleContainer holding all the tuples to be removed from the container
Returns:
the number of tuples effectively removed

size

public abstract int size()
Description copied from interface: TupleContainer
Gets The number of tuples that appear in the relation.

Specified by:
size in interface TupleContainer
Returns:
The number of tuples that appear in the relation.

toObjectArray

public final <C> C[] toObjectArray(java.lang.Class<C> objectClass)
                        throws SettersMissingException,
                               ConstructorMissingException,
                               ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get an array of objects holding the same information as that which is held in this TupleContainer. One object is created for each tuple.

Specified by:
toObjectArray in interface TupleContainer
Type Parameters:
C - The name of the objectClass, also naming the class/object type of the objects making up the returned array
Parameters:
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
SettersMissingException - if a needed setter is missing in the class denoted by objectClass
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toObjectArrayIgnoringMissingSetters

public final <C> C[] toObjectArrayIgnoringMissingSetters(java.lang.Class<C> objectClass)
                                              throws ConstructorMissingException,
                                                     ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get an array of objects holding a (potentially proper) subset of the information held in this TupleContainer. One object is created for each tuple. Setters matching an attribute in the heading will be invoked, attributes for which no corresponding setter is found, are ignored.

Specified by:
toObjectArrayIgnoringMissingSetters in interface TupleContainer
Type Parameters:
C - The name of the objectClass, also naming the class/object type of the objects making up the returned array
Parameters:
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has at most one unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toObjectCollection

public final <C> java.util.Collection<C> toObjectCollection(java.lang.Class<C> objectClass)
                                                 throws SettersMissingException,
                                                        ConstructorMissingException,
                                                        ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get a collection of objects holding the same information as that which is held in this TupleContainer. One object is created for each tuple.

Specified by:
toObjectCollection in interface TupleContainer
Parameters:
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
SettersMissingException - if a needed setter is missing in the class denoted by objectClass
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toObjectCollectionIgnoringMissingSetters

public final <C> java.util.Collection<C> toObjectCollectionIgnoringMissingSetters(java.lang.Class<C> objectClass)
                                                                       throws ConstructorMissingException,
                                                                              ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get a collection of objects holding a (potentially proper) subset of the information held in this TupleContainer. One object is created for each tuple. Setters matching an attribute in the heading will be invoked, attributes for which no corresponding setter is found, are ignored.

Specified by:
toObjectCollectionIgnoringMissingSetters in interface TupleContainer
Parameters:
objectClass - A Class object denoting the class of the objects to be returned. objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has at most one unique setter method for each attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
An array of objects of the given object Class.
Throws:
ConstructorMissingException - if objectClass does not denote a public class, or it denotes an abstract class, or the class does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toObjectsArray

public final java.util.Map<java.lang.Class<?>,java.lang.Object>[] toObjectsArray(java.lang.Class<?>[] objectClass)
                                                                          throws SettersMissingException,
                                                                                 ConstructorMissingException,
                                                                                 ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get an array of Maps of objects holding the same information as that which is held in this TupleContainer. One Map is returned for each tuple in the container. The entries in the map have one of the objectClass[] objects as their key, and an object of that class as their value. The object of that class holds the attribute values of the tuple for which a corresponding setter method was found in the class.

Specified by:
toObjectsArray in interface TupleContainer
Parameters:
objectClass - An array of Class objects denoting the classes of the objects to be returned for each tuple. Each objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for some attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
The array of maps of objects holding the same information as this relation.
Throws:
SettersMissingException - if some attribute in the heading exists for which no corresponding setter could be found in any of the classes denoted by objectClass[]
ConstructorMissingException - if some objectClass does not denote a public class, or it denotes an abstract class, ordenotes a class that does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toObjectsCollection

public final java.util.Collection<java.util.Map<java.lang.Class<?>,java.lang.Object>> toObjectsCollection(java.lang.Class<?>[] objectClass)
                                                                                                   throws SettersMissingException,
                                                                                                          ConstructorMissingException,
                                                                                                          ClassDoesNotImplementDBObjectException
Description copied from interface: TupleContainer
Get a collection of Maps of objects holding the same information as that which is held in this TupleContainer. One Map is returned for each tuple in the container. The entries in the map have one of the objectClass[] objects as their key, and an object of that class as their value. The object of that class holds the attribute values of the tuple for which a corresponding setter method was found in the class.

Specified by:
toObjectsCollection in interface TupleContainer
Parameters:
objectClass - An array of Class objects denoting the classes of the objects to be returned for each tuple. Each objectClass must denote a public, non-abstract class that has a public no-arg constructor, and that has a unique setter method for some attribute in the heading. The name of this unique method must be the concatenation of the word "set" (all lowercase), followed by the uppercased attribute name (i.e. first character uppercase, all others lowercase), followed by "FromDB". The argument list of this setter method must consist of excatly one java.lang.String argument.
Returns:
The array of maps of objects holding the same information as this relation.
Throws:
SettersMissingException - if some attribute in the heading exists for which no corresponding setter could be found in any of the classes denoted by objectClass[]
ConstructorMissingException - if some objectClass does not denote a public class, or it denotes an abstract class, ordenotes a class that does not have a public no-arg constructor
ClassDoesNotImplementDBObjectException - if objectClass does not implement the required DBObject interface

toString

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