View Javadoc
1   /*
2    * Copyright 2012-2019 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.dict.stemmeroverride;
17  
18  import org.codelibs.core.lang.StringUtil;
19  import org.codelibs.fess.dict.DictionaryItem;
20  
21  public class StemmerOverrideItem extends DictionaryItem {
22      private final String input;
23  
24      private final String output;
25  
26      private String newInput;
27  
28      private String newOutput;
29  
30      public StemmerOverrideItem(final long id, final String input, final String output) {
31          this.id = id;
32          this.input = input;
33          this.output = output;
34  
35          if (id == 0) {
36              // create
37              newInput = input;
38              newOutput = output;
39          }
40      }
41  
42      public String getNewInput() {
43          return newInput;
44      }
45  
46      public void setNewInput(final String newInput) {
47          this.newInput = newInput;
48      }
49  
50      public String getNewOutput() {
51          return newOutput;
52      }
53  
54      public void setNewOutput(final String newOutputs) {
55          this.newOutput = newOutputs;
56      }
57  
58      public String getInput() {
59          return input;
60      }
61  
62      public String getOutput() {
63          return output;
64      }
65  
66      public boolean isUpdated() {
67          return newInput != null && newOutput != null;
68      }
69  
70      public boolean isDeleted() {
71          return isUpdated() && StringUtil.isBlank(newInput);
72      }
73  
74      @Override
75      public int hashCode() {
76          final int prime = 31;
77          int result = 1;
78          result = prime * result + ((input == null) ? 0 : input.hashCode());
79          result = prime * result + ((output == null) ? 0 : output.hashCode());
80          return result;
81      }
82  
83      @Override
84      public boolean equals(final Object obj) {
85          if (this == obj) {
86              return true;
87          }
88          if (obj == null) {
89              return false;
90          }
91          if (getClass() != obj.getClass()) {
92              return false;
93          }
94          final StemmerOverrideItem../org/codelibs/fess/dict/stemmeroverride/StemmerOverrideItem.html#StemmerOverrideItem">StemmerOverrideItem other = (StemmerOverrideItem) obj;
95          if (input == null) {
96              if (other.input != null) {
97                  return false;
98              }
99          } else if (!input.equals(other.input)) {
100             return false;
101         }
102         if (output == null) {
103             if (other.output != null) {
104                 return false;
105             }
106         } else if (!output.equals(other.output)) {
107             return false;
108         }
109         return true;
110     }
111 
112     @Override
113     public String toString() {
114         return "StemmerOverrideItem [input=" + input + ", output=" + output + ", newInput=" + newInput + ", newOutput=" + newOutput + "]";
115     }
116 
117     public String toLineString() {
118         if (isUpdated()) {
119             return newInput + "=>" + newOutput;
120         } else {
121             return input + "=>" + output;
122         }
123     }
124 
125 }