View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: CodePointAndVariant.java,v 21bfa7b63ab2 2008/09/11 14:08:48 maxberger $ */
18  
19  package net.sourceforge.jeuclid.elements.support.text;
20  
21  import java.io.Serializable;
22  
23  import net.sourceforge.jeuclid.elements.support.attributes.MathVariant;
24  
25  /**
26   * @version $Revision: 21bfa7b63ab2 $
27   */
28  public class CodePointAndVariant implements Serializable {
29      /**
30       * 
31       */
32      private static final long serialVersionUID = 1L;
33  
34      private final int codePoint;
35  
36      private final MathVariant variant;
37  
38      /**
39       * Create a new CodePointAndVariant.
40       * 
41       * @param icodePoint
42       *            the codepoint to use
43       * @param ivariant
44       *            the MathVariant of the character.
45       */
46      public CodePointAndVariant(final int icodePoint,
47              final MathVariant ivariant) {
48          assert ivariant != null;
49          this.codePoint = icodePoint;
50          this.variant = ivariant;
51      }
52  
53      /**
54       * @return the codePoint
55       */
56      public final int getCodePoint() {
57          return this.codePoint;
58      }
59  
60      /**
61       * @return the variant
62       */
63      public final MathVariant getVariant() {
64          return this.variant;
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public int hashCode() {
70          final int prime = 31;
71          int result = 1;
72          result = prime * result + this.codePoint;
73          result = prime * result + this.variant.hashCode();
74          return result;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public boolean equals(final Object obj) {
80          if (this == obj) {
81              return true;
82          }
83          if (obj == null) {
84              return false;
85          }
86          if (this.getClass() != obj.getClass()) {
87              return false;
88          }
89          final CodePointAndVariant other = (CodePointAndVariant) obj;
90          if (this.codePoint != other.codePoint) {
91              return false;
92          }
93          if (this.variant == null) {
94              if (other.variant != null) {
95                  return false;
96              }
97          } else if (!this.variant.equals(other.variant)) {
98              return false;
99          }
100         return true;
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public String toString() {
106         final StringBuilder b = new StringBuilder();
107         b.append('[');
108         b.append("0x");
109         b.append(Integer.toHexString(this.codePoint));
110         b.append(' ');
111         b.append(this.variant.toString());
112         b.append(']');
113         return b.toString();
114     }
115 }