View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.tokenizer;
12  
13  import java.util.Objects;
14  
15  /**
16   * The Class TokenizerSymbol.
17   */
18  public class TokenizerSymbol implements Comparable<Object> {
19  
20    /** The name. */
21    final String name;
22  
23    /** The start text. */
24    final String startText;
25  
26    /** The tail text. */
27    final String tailText;
28  
29    /** The hidden. */
30    final boolean hidden;
31  
32    /** The decode paired. */
33    final boolean decodePaired;
34  
35    /** The enabled. */
36    final boolean enabled;
37  
38    /** The can be nested. */
39    final boolean canBeNested;
40  
41    /**
42     * Instantiates a new tokenizer symbol.
43     *
44     * @param name the name
45     * @param startText the start text
46     * @param tailText the tail text
47     * @param hidden the hidden
48     * @param decodePaired the decode paired
49     * @param enabled the enabled
50     * @param canBeNested the can be nested
51     */
52    public TokenizerSymbol(String name, String startText, String tailText, boolean hidden,
53        boolean decodePaired, boolean enabled, boolean canBeNested) {
54  
55      this.name = name;
56      this.startText = startText;
57      this.tailText = tailText;
58      this.hidden = hidden;
59      this.decodePaired = decodePaired;
60      this.enabled = enabled;
61      this.canBeNested = canBeNested;
62    }
63  
64    @Override
65    public int compareTo(Object obj) {
66      if (obj instanceof Character) {
67        return compareTo((Character) obj);
68      }
69      return compareTo((TokenizerSymbol) obj);
70    }
71  
72    /**
73     * Compare to.
74     *
75     * @param chr the chr
76     *
77     * @return the int
78     */
79    public int compareTo(Character chr) {
80      return chr - startText.charAt(0);
81    }
82  
83    /**
84     * Compare to.
85     *
86     * @param symbol the symbol
87     *
88     * @return the int
89     */
90    public int compareTo(TokenizerSymbol symbol) {
91      return symbol.startText.compareTo(startText);
92    }
93  
94    @Override
95    public int hashCode() {
96      return Objects.hash(this.name, this.startText, this.tailText, this.hidden, this.decodePaired,
97          this.enabled, this.canBeNested);
98    }
99  
100   @Override
101   public boolean equals(Object obj) {
102     if (obj == null || getClass() != obj.getClass()) {
103       return false;
104     }
105     final TokenizerSymbol other = (TokenizerSymbol) obj;
106     return Objects.equals(this.name, other.name) && Objects.equals(this.startText, other.startText)
107         && Objects.equals(this.tailText, other.tailText) && this.hidden == other.hidden
108         && this.decodePaired == other.decodePaired && this.enabled == other.enabled
109         && this.canBeNested == other.canBeNested;
110   }
111 
112 }