public DefaultBetaConstraints(final BetaNodeFieldConstraint[] constraints,
final RuleBaseConfiguration conf,
final boolean disableIndexing ) {
this.indexed = -1;
this.constraints = new LinkedList();
ContextEntry current = null;
final int depth = conf.getCompositeKeyDepth();
// First create a LinkedList of constraints, with the indexed constraints first.
for ( int i = 0, length = constraints.length; i < length; i++ ) {
// Determine if this constraint is indexable
if ( (!disableIndexing) && conf.isIndexLeftBetaMemory() && conf.isIndexRightBetaMemory() && isIndexable( constraints[i] ) && ( this.indexed < depth-1 ) ) {
if ( depth >= 1 && this.indexed == -1 ) {
// first index, so just add to the front
this.constraints.insertAfter( null,
new LinkedListEntry( constraints[i] ) );
this.indexed++;
} else {
// insert this index after the previous index
this.constraints.insertAfter( findNode( this.indexed++ ),
new LinkedListEntry( constraints[i] ) );
}
} else {
// not indexed, so just add to the end
this.constraints.add( new LinkedListEntry( constraints[i] ) );
}
}
// Now create the ContextEntries in the same order the constraints
for ( LinkedListEntry entry = (LinkedListEntry) this.constraints.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
final BetaNodeFieldConstraint constraint = (BetaNodeFieldConstraint) entry.getObject();
final ContextEntry context = constraint.getContextEntry();
if ( current == null ) {
current = context;
this.contexts = context;
} else {
current.setNext( context );