View Javadoc
1   /*
2    * Copyright 2012-2021 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 java.util.Objects;
19  
20  import org.codelibs.core.lang.StringUtil;
21  import org.codelibs.fess.dict.DictionaryItem;
22  
23  public class StemmerOverrideItem extends DictionaryItem {
24      private final String input;
25  
26      private final String output;
27  
28      private String newInput;
29  
30      private String newOutput;
31  
32      public StemmerOverrideItem(final long id, final String input, final String output) {
33          this.id = id;
34          this.input = input;
35          this.output = output;
36  
37          if (id == 0) {
38              // create
39              newInput = input;
40              newOutput = output;
41          }
42      }
43  
44      public String getNewInput() {
45          return newInput;
46      }
47  
48      public void setNewInput(final String newInput) {
49          this.newInput = newInput;
50      }
51  
52      public String getNewOutput() {
53          return newOutput;
54      }
55  
56      public void setNewOutput(final String newOutputs) {
57          this.newOutput = newOutputs;
58      }
59  
60      public String getInput() {
61          return input;
62      }
63  
64      public String getOutput() {
65          return output;
66      }
67  
68      public boolean isUpdated() {
69          return newInput != null && newOutput != null;
70      }
71  
72      public boolean isDeleted() {
73          return isUpdated() && StringUtil.isBlank(newInput);
74      }
75  
76      @Override
77      public int hashCode() {
78          return Objects.hash(input, output);
79      }
80  
81      @Override
82      public boolean equals(final Object obj) {
83          if (this == obj) {
84              return true;
85          }
86          if (obj == null) {
87              return false;
88          }
89          if (getClass() != obj.getClass()) {
90              return false;
91          }
92          final StemmerOverrideItem other = (StemmerOverrideItem) obj;
93          if (!Objects.equals(input, other.input)) {
94              return false;
95          }
96          if (!Objects.equals(output, other.output)) {
97              return false;
98          }
99          return true;
100     }
101 
102     @Override
103     public String toString() {
104         return "StemmerOverrideItem [input=" + input + ", output=" + output + ", newInput=" + newInput + ", newOutput=" + newOutput + "]";
105     }
106 
107     public String toLineString() {
108         if (isUpdated()) {
109             return newInput + "=>" + newOutput;
110         }
111         return input + "=>" + output;
112     }
113 
114 }