Copyright (C) 2001, Geert Vernaeve. All Rights Reserved.
package gve.calc.logic; import gve.calc.formula.*; public class MultipleMatched implements Matched { private Part []tomatch; private Part []pattern; private Matched action; private Matcher matcher; private int count = 0; public MultipleMatched(Part []tomatch,Part []pattern,Matched action,Matcher m) { if (tomatch.length != pattern.length) throw new Error("tomatch[] and pattern[] have different lengths"); //System.out.println("MultipleMatched with "+pattern.length+" matches"); this.tomatch = tomatch; this.pattern = pattern; this.action = action; matcher = m; }
Match tomatch[i] to pattern[i]. When all of them match, call action.foundMatch().
public boolean match() { return foundMatch(matcher); } public boolean foundMatch(Matcher m) { // Try to match tomatch[count] with pattern[count] if (count == tomatch.length) // found a match! return action.foundMatch(m); count++; //System.out.println("multiplematch: match "+(count-1)); boolean result = m.match(tomatch[count-1],pattern[count-1],this); //System.out.println("multiplematch: match "+(count-1)+" is "+result); count--; return result; } }