de.fuberlin.wiwiss.d2rq.helpers
Class ConjunctionIterator

java.lang.Object
  extended byde.fuberlin.wiwiss.d2rq.helpers.ConjunctionIterator
All Implemented Interfaces:
java.util.Iterator

public class ConjunctionIterator
extends java.lang.Object
implements java.util.Iterator

Iterates over the elements of a cross product of a set of sets. In logical terms: given a conjunction of disjunctiveTerms in disjunctive normal form (a_1_1 \/ ... \/ a_1_M1) /\ .... /\ (a_n_1 \/ ... \/ a_n_Mn) we want to multiplicate it out into conjunctive normal form (a_1_1 /\ ... /\ a_n_1) \/ .... \/ (a_1_M1 /\ ... /\ a_n_Mn). We can expect to get M1 * ... * Mn factors estimatedNumberOfResults.

Author:
jgarbers

Field Summary
protected static boolean createTypedArrays
          Flag to allow/disallow use of reflexion API.
protected  java.lang.Object[][] disjunctiveTerms
          the disjunctions.
protected  int estimatedNumberOfResults
           
protected  int n
          the number of disjunctions.
protected  IndexArray nextIndexArray
          the indices point to the terms in disjunctiveTerms that build the next conjunction in conjunctive normal form.
protected  java.lang.Object[] resultStore
          optionally a resultStore can be given.
protected  boolean resultStoreIsInitialized
           
protected  java.lang.Class termType
          Java type of a single Term a_i_j.
 
Constructor Summary
ConjunctionIterator(java.lang.Object[][] disjunctiveTerms, java.lang.Object[] resultStore)
           
 
Method Summary
static java.lang.Object[][] allConjunctions(java.lang.Object[][] disjunctiveTerms, java.lang.Object[][] resultStore)
          Get all conjunctions.
 int getEstimatedNumberOfResults()
           
 IndexArray getNextIndexArray()
           
 java.lang.Object[] getResultStore()
           
 java.lang.Class getTermType()
           
 boolean hasNext()
           
static boolean isCreateTypedArrays()
           
 java.lang.Object next()
           
 java.lang.Object[] nextArray()
           
 void remove()
           
static void setCreateTypedArrays(boolean createTypedArrays)
           
 void setNextIndexArray(IndexArray nextIndexArray)
           
 void setResultStore(java.lang.Object[] resultStore)
           
 void setTermType(java.lang.Class termType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

n

protected final int n
the number of disjunctions.


disjunctiveTerms

protected final java.lang.Object[][] disjunctiveTerms
the disjunctions. Type: Object [n][].


createTypedArrays

protected static boolean createTypedArrays
Flag to allow/disallow use of reflexion API. true is more convenient but may in some cases violate the security constraints of the code.


termType

protected java.lang.Class termType
Java type of a single Term a_i_j.


nextIndexArray

protected IndexArray nextIndexArray
the indices point to the terms in disjunctiveTerms that build the next conjunction in conjunctive normal form.


resultStore

protected java.lang.Object[] resultStore
optionally a resultStore can be given. This has two advantages: 1) it avoids the allocation of a new array in each iteration 2) it can have the correct array type used for later processing and this way avoids casting. Disadvantage: the array is overridden each time next() is called. So be very careful with 'storing' iterator results!


resultStoreIsInitialized

protected boolean resultStoreIsInitialized

estimatedNumberOfResults

protected int estimatedNumberOfResults
Constructor Detail

ConjunctionIterator

public ConjunctionIterator(java.lang.Object[][] disjunctiveTerms,
                           java.lang.Object[] resultStore)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

remove

public void remove()
            throws java.lang.UnsupportedOperationException
Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException

nextArray

public java.lang.Object[] nextArray()

isCreateTypedArrays

public static boolean isCreateTypedArrays()

setCreateTypedArrays

public static void setCreateTypedArrays(boolean createTypedArrays)

getNextIndexArray

public IndexArray getNextIndexArray()

setNextIndexArray

public void setNextIndexArray(IndexArray nextIndexArray)

getResultStore

public java.lang.Object[] getResultStore()

setResultStore

public void setResultStore(java.lang.Object[] resultStore)

getTermType

public java.lang.Class getTermType()

setTermType

public void setTermType(java.lang.Class termType)

getEstimatedNumberOfResults

public int getEstimatedNumberOfResults()

allConjunctions

public static java.lang.Object[][] allConjunctions(java.lang.Object[][] disjunctiveTerms,
                                                   java.lang.Object[][] resultStore)
Get all conjunctions.

Parameters:
disjunctiveTerms - see above
resultStore - optional, of size [estimatedNumberOfResults][n]
Returns:
array of size [estimatedNumberOfResults][n]