org.trippi.impl.kowari
Class CollapsedAnswer

java.lang.Object
  extended by org.trippi.impl.kowari.CollapsedAnswer
All Implemented Interfaces:
java.lang.Cloneable, org.kowari.query.Answer, org.kowari.query.Cursor

public class CollapsedAnswer
extends java.lang.Object
implements org.kowari.query.Answer

An Answer wrapper that collapses any inner-Answers into JRDF Nodes. This is useful for converting a given kowari Answer to a simple iterator of tuples.

 Example input:

 Answer { 
   Row {
     prop1 = value1
     prop2 = value2
     k0    = Answer {
                Row { prop3 = value3a }
                Row { prop3 = value3b }
             }
     k1    = Answer {
                Row { prop4 = value4 }
             }
   }
 }

 Example output:

 Answer {
   Row {
     prop1 = value1
     prop2 = value2
     prop3 = value3a
     prop4 = value4
   }
   Row {
     prop1 = value1
     prop2 = value2
     prop3 = value3b
     prop4 = null
   }
 }
 


Field Summary
 
Fields inherited from interface org.kowari.query.Cursor
MANY, ONE, ZERO
 
Constructor Summary
CollapsedAnswer(org.kowari.query.Answer wrappedAnswer)
           
 
Method Summary
 void beforeFirst()
          Reset to iterate through every single element.
 java.lang.Object clone()
           
 void close()
          Free resources associated with this instance.
 int getColumnIndex(org.kowari.query.Variable column)
          Find the index of a variable.
 int getNumberOfVariables()
          Return the number of variables (columns).
 java.lang.Object getObject(int column)
           
 java.lang.Object getObject(java.lang.String columnName)
           
 int getRowCardinality()
          Return cardinality of the number of rows which this instance contains.
 long getRowCount()
          Return the exact number of rows this instance contains.
 long getRowUpperBound()
          Return an upper bound on the number of rows this instance contains.
 org.kowari.query.Variable[] getVariables()
          Get the variables bound and their default collation order.
 boolean isUnconstrained()
          Test whether this is a unit-valued answer.
 boolean next()
          Move to the next row.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollapsedAnswer

public CollapsedAnswer(org.kowari.query.Answer wrappedAnswer)
                throws org.kowari.query.TuplesException
Throws:
org.kowari.query.TuplesException
Method Detail

getObject

public java.lang.Object getObject(int column)
                           throws org.kowari.query.TuplesException
Specified by:
getObject in interface org.kowari.query.Answer
Throws:
org.kowari.query.TuplesException

getObject

public java.lang.Object getObject(java.lang.String columnName)
                           throws org.kowari.query.TuplesException
Specified by:
getObject in interface org.kowari.query.Answer
Throws:
org.kowari.query.TuplesException

beforeFirst

public void beforeFirst()
                 throws org.kowari.query.TuplesException
Reset to iterate through every single element.

Specified by:
beforeFirst in interface org.kowari.query.Cursor
Throws:
org.kowari.query.TuplesException

close

public void close()
           throws org.kowari.query.TuplesException
Free resources associated with this instance.

Specified by:
close in interface org.kowari.query.Cursor
Throws:
org.kowari.query.TuplesException

getColumnIndex

public int getColumnIndex(org.kowari.query.Variable column)
                   throws org.kowari.query.TuplesException
Find the index of a variable.

Specified by:
getColumnIndex in interface org.kowari.query.Cursor
Returns:
the ColumnIndex value
Throws:
org.kowari.query.TuplesException

getNumberOfVariables

public int getNumberOfVariables()
Return the number of variables (columns).

Specified by:
getNumberOfVariables in interface org.kowari.query.Cursor

getVariables

public org.kowari.query.Variable[] getVariables()
Get the variables bound and their default collation order. The array returned by this method should be treated as if its contents were immutable, even though Java won't enforce this. If the elements of the array are modified, there may be side effects on the past and future clones of the tuples it was obtained from.

Specified by:
getVariables in interface org.kowari.query.Cursor
Returns:
the Variables bound within this answer

isUnconstrained

public boolean isUnconstrained()
                        throws org.kowari.query.TuplesException
Test whether this is a unit-valued answer. A unit answer appended to something yields the unit answer. A unit answer joined to something yields the same something. Notionally, the unit answer has zero columns and one row.

Specified by:
isUnconstrained in interface org.kowari.query.Cursor
Returns:
true if the answer is unconstrained
Throws:
org.kowari.query.TuplesException

getRowCount

public long getRowCount()
                 throws org.kowari.query.TuplesException
Return the exact number of rows this instance contains.

Specified by:
getRowCount in interface org.kowari.query.Cursor
Throws:
org.kowari.query.TuplesException

getRowUpperBound

public long getRowUpperBound()
                      throws org.kowari.query.TuplesException
Return an upper bound on the number of rows this instance contains.

Specified by:
getRowUpperBound in interface org.kowari.query.Cursor
Throws:
org.kowari.query.TuplesException

getRowCardinality

public int getRowCardinality()
                      throws org.kowari.query.TuplesException
Return cardinality of the number of rows which this instance contains.

Specified by:
getRowCardinality in interface org.kowari.query.Cursor
Returns:
the cardinality of this tuples. {0,1,N} rows.
Throws:
org.kowari.query.TuplesException

next

public boolean next()
             throws org.kowari.query.TuplesException
Move to the next row. If no such row exists, return false and the current row becomes unspecified. The current row is unspecified when an instance is created. To specify the current row, the beforeFirst() method must be invoked.

Specified by:
next in interface org.kowari.query.Cursor
Returns:
whether a subsequent row exists.
Throws:
org.kowari.query.TuplesException

clone

public java.lang.Object clone()
Specified by:
clone in interface org.kowari.query.Answer
Overrides:
clone in class java.lang.Object