View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.services.fieldquery;
20  
21  import org.jdom2.Element;
22  import org.mycore.parsers.bool.MCRCondition;
23  
24  /**
25   * Represents a simple query condition, which consists of a search field,
26   * a value and a comparison operator.
27   * 
28   * @author Frank Lützenkirchen
29   */
30  public class MCRQueryCondition extends MCRFieldBaseValue implements MCRCondition<Void> {
31  
32      /** The comparison operator used in this condition */
33      private String operator;
34  
35      public MCRQueryCondition(String fieldName, String operator, String value) {
36          super(fieldName, value);
37          this.operator = operator;
38      }
39  
40      public void setOperator(String operator) {
41          this.operator = operator;
42      }
43  
44      /** Returns the comparison operator used in this condition */
45      public String getOperator() {
46          return this.operator;
47      }
48  
49      @Override
50      public String toString() {
51          return getFieldName() + " " + getOperator() + " \"" + getValue() + "\"";
52      }
53  
54      public Element toXML() {
55          Element condition = new Element("condition");
56          condition.setAttribute("field", getFieldName());
57          condition.setAttribute("operator", operator);
58          condition.setAttribute("value", getValue());
59  
60          return condition;
61      }
62  
63      public boolean evaluate(Void o) {
64          //there is no 'void' instance
65          throw new UnsupportedOperationException();
66      }
67  }