BetaConstraints betaConstraints = null;
betaConstraints = new SingleBetaConstraints(constraints, config);
BetaMemory betaMemory = betaConstraints.createBetaMemory( config, NodeTypeEnums.JoinNode );
RuleBase rb = RuleBaseFactory.newRuleBase();
StatefulSession ss = rb.newStatefulSession();
InternalFactHandle fh1 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
InternalFactHandle fh2 = (InternalFactHandle) ss.insert( new Foo( "brie", 1) );
InternalFactHandle fh3 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
InternalFactHandle fh4 = (InternalFactHandle) ss.insert( new Foo( "soda", 1) );
InternalFactHandle fh5 = (InternalFactHandle) ss.insert( new Foo( "bread", 3) );
InternalFactHandle fh6 = (InternalFactHandle) ss.insert( new Foo( "bread", 3) );
InternalFactHandle fh7 = (InternalFactHandle) ss.insert( new Foo( "cream", 3) );
InternalFactHandle fh8 = (InternalFactHandle) ss.insert( new Foo( "gorda", 15) );
InternalFactHandle fh9 = (InternalFactHandle) ss.insert( new Foo( "beer", 16) );
InternalFactHandle fh10 = (InternalFactHandle) ss.insert( new Foo( "mars", 0) );
InternalFactHandle fh11 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
InternalFactHandle fh12 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
InternalFactHandle fh13 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh1, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh2, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh3, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh4, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh5, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh6, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh7, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh8, null ) );
betaMemory.getRightTupleMemory().add( new RightTuple( fh9, null ) );
RightTupleIndexHashTable hashTable = (RightTupleIndexHashTable) betaMemory.getRightTupleMemory();
// can't create a 0 hashCode, so forcing
RightTupleList rightTupleList = new RightTupleList();
rightTupleList.add( new RightTuple( fh10, null) );
hashTable.getTable()[0] = rightTupleList;
rightTupleList = new RightTupleList();
rightTupleList.add( new RightTuple( fh11, null ) );
rightTupleList.add( new RightTuple( fh12, null ) );
rightTupleList.add( new RightTuple( fh13, null ) );
((RightTupleList)hashTable.getTable()[0]).setNext( rightTupleList );
Entry[] table = hashTable.getTable();
List list = new ArrayList();
for ( int i = 0; i < table.length; i++ ) {
if ( table[i] != null ) {
List entries = new ArrayList();
entries.add( i );
Entry entry = table[i];
while ( entry != null ) {
entries.add( entry );
entry = entry.getNext();
}
list.add( entries.toArray() );
}
}
assertEquals( 5, list.size() );
Object[] entries = (Object[]) list.get( 0 );
assertEquals( 0, entries[0]);
assertEquals( 3, entries.length );
entries = (Object[]) list.get( 1 );
assertEquals( 102, entries[0]);
assertEquals( 2, entries.length );
entries = (Object[]) list.get( 2 );
assertEquals( 103, entries[0]);
assertEquals( 2, entries.length );
entries = (Object[]) list.get( 3 );
assertEquals( 115, entries[0]);
assertEquals( 3, entries.length );
entries = (Object[]) list.get( 4 );
assertEquals( 117, entries[0]);
assertEquals( 3, entries.length );
//System.out.println( entries );
list = new ArrayList<LeftTupleImpl>();
Iterator it = betaMemory.getRightTupleMemory().iterator();
for ( RightTuple rightTuple = ( RightTuple ) it.next(); rightTuple != null; rightTuple = ( RightTuple ) it.next() ) {
list.add( rightTuple );
}
assertEquals( 13, list.size() );