public boolean organize ( ) { // First, find any simple tests that can be used to reduce residual components to // simple tests or pure truth values, either because the simple test is a NULL test or // because it is effectively an equality test. if ( tmpResidual . size ( ) > 0 ) { List [ ] equatedIds = findEquatedIdentifiers ( ) ; while ( equatedIds != null && tmpResidual . size ( ) > 0 ) { equatedIds = reduceResidual ( equatedIds ) ; if ( equatedIds != null && equatedIds . length == 0 ) // Special indicator for contradiction return false ; } } // We now have a reduced form Conjunction that is still capable of being true. We // call shedSubtests on each SimpleTest so that STRINGOTH tests can move their // "difficult" parts to the residual. We didn't do this earlier because we wanted to // give the STRINGOTH test an opportunity to be trumped by a EQ test on the // same identifier (or to be contradicted by a NULL test). A false return from // shedSubtests causes the entire SimpleTest to be removed. for ( int i = 0 ; i < tmpSimpleTests . size ( ) ; ) if ( ( ( SimpleTestImpl ) tmpSimpleTests . get ( i ) ) . shedSubtests ( tmpResidual ) ) i ++ ; else tmpSimpleTests . remove ( i ) ; // Sort the simple tests by ordinal position, looking for illegal position // assignments. for ( int i = 0 ; i < tmpSimpleTests . size ( ) - 1 ; i ++ ) for ( int j = i + 1 ; j < tmpSimpleTests . size ( ) ; j ++ ) { SimpleTest iTest = ( SimpleTest ) tmpSimpleTests . get ( i ) ; SimpleTest jTest = ( SimpleTest ) tmpSimpleTests . get ( j ) ; OrdinalPosition iPos = ( OrdinalPosition ) iTest . getIdentifier ( ) . getOrdinalPosition ( ) ; OrdinalPosition jPos = ( OrdinalPosition ) jTest . getIdentifier ( ) . getOrdinalPosition ( ) ; if ( jPos . compareTo ( iPos ) < 0 ) { tmpSimpleTests . set ( j , iTest ) ; tmpSimpleTests . set ( i , jTest ) ; } else if ( jTest . getIdentifier ( ) . getOrdinalPosition ( ) == iTest . getIdentifier ( ) . getOrdinalPosition ( ) ) throw new IllegalStateException ( ) ; } // We can now convert the Conjunction to its final form simpleTests = ( SimpleTest [ ] ) tmpSimpleTests . toArray ( new SimpleTest [ 0 ] ) ; tmpSimpleTests = null ; for ( int i = 0 ; i < tmpResidual . size ( ) ; i ++ ) if ( residual == null ) residual = ( Selector ) tmpResidual . get ( i ) ; else residual = new OperatorImpl ( Operator . AND , residual , ( Selector ) tmpResidual . get ( i ) ) ; tmpResidual = null ; alwaysTrue = simpleTests . length == 0 && residual == null ; return true ; }
Organize the Conjunction into its final useful form for MatchSpace .