View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.tika.mime;
18  
19  /**
20   * Defines a Boolean Binary Operator.
21   * 
22   * 
23   */
24  interface Operator {
25  
26      /** The OR Boolean operator */
27      final static Operator OR = new Or();
28  
29      /** The AND Boolean operator */
30      final static Operator AND = new And();
31  
32      /**
33       * Evaluates the specified bolean operands.
34       * 
35       * @param o1
36       *            is the first boolean operand.
37       * @param o2
38       *            is the second boolean operand.
39       * @return the value of this boolean operator applied on the specified
40       *         boolean operands.
41       */
42      boolean eval(boolean o1, boolean o2);
43  
44      /**
45       * Defines the Boolean Binary Operator AND.
46       */
47      final static class And implements Operator {
48          public boolean eval(boolean o1, boolean o2) {
49              return o1 && o2;
50          }
51  
52          public String toString() {
53              return "AND";
54          }
55      }
56  
57      /**
58       * Defines the Boolean Binary Operator OR.
59       */
60      final static class Or implements Operator {
61          public boolean eval(boolean o1, boolean o2) {
62              return o1 || o2;
63          }
64  
65          public String toString() {
66              return "OR";
67          }
68      }
69  }