001 package org.hackystat.sensorbase.uripattern; 002 003 /** 004 * Compound pattern. 005 * 006 * @author (Cedric) Qin ZHANG 007 */ 008 class CompoundPattern implements Pattern { 009 010 private Operator operator; 011 private Pattern[] patterns; 012 013 /** 014 * Creates a new compound pattern. 015 * 016 * @param operator The logic operator. 017 * @param operands The operands. 018 */ 019 CompoundPattern(Operator operator, Pattern[] operands) { 020 if (operator.getArity() != operands.length) { 021 throw new RuntimeException("Operator arity does not match the number of operands."); 022 } 023 this.operator = operator; 024 this.patterns = operands; 025 } 026 027 /** 028 * Tests whether the pattern matches a file path. 029 * 030 * @param filePath The file path to match. 031 * @return True if there is a match. 032 */ 033 public boolean matches(String filePath) { 034 return this.operator.matches(this.patterns, filePath); 035 } 036 }