001    package org.hackystat.sensorbase.uripattern;
002    
003    /**
004     * And logic operator for two patterns.
005     * 
006     * @author (Cedric) Qin ZHANG
007     */
008    class AndOperator implements Operator {
009      
010      /**
011       * Gets the arity of this operator.
012       * 
013       * @return The arity.
014       */
015      public int getArity() {
016        return 2;
017      }
018    
019      /**
020       * Perform operator operation.
021       * 
022       * @param patterns The operand.
023       * @param filePath The file path to match.
024       * 
025       * @return True if there is a match.
026       */
027      public boolean matches(Pattern[] patterns, String filePath) {
028        if (patterns.length != 2) {
029          throw new RuntimeException("AND operator expects exactly 1 operand.");
030        }
031        return patterns[0].matches(filePath) && patterns[1].matches(filePath);
032      }
033    }