private boolean isRedundant ( List < StorableIndex < S > > group , StorableIndex < S > candidate , Map < StorableIndex < S > , StorableIndex < S > > mergedReplacements ) { // All visited group members will have an equal or greater number of // properties. This is ensured by the ordering of the set. int count = candidate . getPropertyCount ( ) ; ListIterator < StorableIndex < S > > it = group . listIterator ( ) ; groupScan : while ( it . hasNext ( ) ) { StorableIndex < S > member = it . next ( ) ; boolean moreQualified = false ; boolean canReverse = true ; boolean reverse = false ; for ( int i = 0 ; i < count ; i ++ ) { Direction candidateOrder = candidate . getPropertyDirection ( i ) ; if ( candidateOrder == Direction . UNSPECIFIED ) { // Property direction is unspecified, so no need to compare // direction. Move on to next property. continue ; } Direction memberOrder = member . getPropertyDirection ( i ) ; if ( memberOrder == Direction . UNSPECIFIED ) { // Candidate index is more qualified because member // property under examination hasn't specified a // direction. Move on to next property to continue checking // if a merge is possible. moreQualified = true ; continue ; } if ( reverse ) { candidateOrder = candidateOrder . reverse ( ) ; } if ( candidateOrder == memberOrder ) { // Direction exactly matches, move on to next property. canReverse = false ; continue ; } // If this point is reached, then the direction would match if // one was reversed. For an index to fully match, all // properties must be reversed. if ( canReverse ) { // Switch to reverse mode and move on to next property. reverse = true ; canReverse = false ; continue ; } // Match failed and merge is not possible. continue groupScan ; } if ( moreQualified ) { // Candidate is more qualified than all members compared to so // far, but it can be merged. Once merged, it is redundant. Direction [ ] directions = member . getPropertyDirections ( ) ; for ( int i = 0 ; i < count ; i ++ ) { if ( directions [ i ] == Direction . UNSPECIFIED ) { Direction direction = candidate . getPropertyDirection ( i ) ; directions [ i ] = reverse ? direction . reverse ( ) : direction ; } } StorableIndex < S > merged = new StorableIndex < S > ( member . getProperties ( ) , directions ) . unique ( member . isUnique ( ) ) ; mergedReplacements . put ( member , merged ) ; it . set ( merged ) ; } // Candidate is redundant. return true ; } return false ; }
Returns true if candidate index is less qualified than an existing group member or if it was merged with another group member . If it was merged then an entry is placed in the merged map and the given group list is updated .