Author: ssmiweve Date: 2008-11-25 15:34:00 +0100 (Tue, 25 Nov 2008) New Revision: 6983
Modified: branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java Log: svn merge -c6981 http://sesat.no/svn/sesat-kernel/trunk Modified: branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java =================================================================== --- branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java 2008-11-25 14:09:35 UTC (rev 6982) +++ branches/2.18/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java 2008-11-25 14:34:00 UTC (rev 6983) @@ -23,11 +23,21 @@ import no.sesat.search.query.parser.*; -final class ChildFinder extends AbstractReflectionVisitor { +/** Used to find if a particular clause exists underneath another. + * + * @version $Id$ + */ +public final class ChildFinder extends AbstractReflectionVisitor { private boolean found; private Clause child = null; + /** Does the child clause exist any depth underneath the parent. + * + * @param parent the parent clause + * @param child the child clause. + * @return Does the child clause exist any depth underneath the parent. + */ public synchronized boolean childExists(final UnaryClause parent, final Clause child) { found = false; Modified: branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java =================================================================== --- branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java 2008-11-25 14:09:35 UTC (rev 6982) +++ branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java 2008-11-25 14:34:00 UTC (rev 6983) @@ -31,6 +31,7 @@ import no.sesat.search.query.UnaryClause; import no.sesat.search.query.OrClause; import no.sesat.search.query.XorClause; +import no.sesat.search.query.finder.ChildFinder; import org.apache.log4j.Logger; /** Base abstraction class for any Alternation implementation. @@ -150,13 +151,14 @@ } /** Build new DoubleOperatorClauses from newChild all the way back up to the root. - * XXX Only handles single splits, or one layer of variations, denoted by the childsParentBeforeRotation argument. - * This could be solved by using an array, specifying ancestry line, for the argument instead. - ** @param root - * @param newChild - * @param originalChild - * @param originalParent - * @return + * XXX Only handles single splits, or one layer of variations, denoted by the originalParent argument. + * This could be solved by using an array, specifying ancestry line, for the argument instead. <br/><br/> + * If, under root, originalParent cannot be found then root is returned unaltered. + * @param root the root clause. an altered version of this will be returned. + * @param newChild the new child. + * @param originalChild the original child. + * @param originalParent the original parent of the original child. expected to be found under root. + * @return the root clause where the originalChild has been replaced with the newChild. */ protected UnaryClause replaceDescendant( final BinaryOperatorClause root, @@ -164,24 +166,33 @@ final BinaryOperatorClause originalChild, final BinaryOperatorClause originalParent){ - UnaryClause nC = newChild; - UnaryClause rC = originalChild; - UnaryClause rCParent = originalParent; + // pre-condition check: originalParent must be found under root somewhere + if(new ChildFinder().childExists(root, originalParent)){ - do{ - nC = replaceOperatorClause(nC, rC, rCParent); - for(UnaryClause parent : context.getParentFinder().getParents(root, rC)){ - if(rCParent == parent){ - rC = parent; - rCParent = root == rCParent - ? rCParent - : context.getParentFinder().getParent(root, rCParent); - break; + UnaryClause nC = newChild; + UnaryClause rC = originalChild; + UnaryClause rCParent = originalParent; + + do{ + nC = replaceOperatorClause(nC, rC, rCParent); + for(UnaryClause parent : context.getParentFinder().getParents(root, rC)){ + if(rCParent == parent){ + rC = parent; + rCParent = root == rCParent + ? rCParent + : context.getParentFinder().getParent(root, rCParent); + break; + } } - } - }while(root != rC); + }while(root != rC); - return nC; + return nC; + + }else{ + LOG.error("originalParent does not live inside root\n" + originalParent + '\n' + root); + // return the unaltered root + return root; + } } /** Replace the originalChild that exists under the originalParent will the newChild. _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
