001    /*
002     * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: CodePointAndVariant.java,v 21bfa7b63ab2 2008/09/11 14:08:48 maxberger $ */
018    
019    package net.sourceforge.jeuclid.elements.support.text;
020    
021    import java.io.Serializable;
022    
023    import net.sourceforge.jeuclid.elements.support.attributes.MathVariant;
024    
025    /**
026     * @version $Revision: 21bfa7b63ab2 $
027     */
028    public class CodePointAndVariant implements Serializable {
029        /**
030         * 
031         */
032        private static final long serialVersionUID = 1L;
033    
034        private final int codePoint;
035    
036        private final MathVariant variant;
037    
038        /**
039         * Create a new CodePointAndVariant.
040         * 
041         * @param icodePoint
042         *            the codepoint to use
043         * @param ivariant
044         *            the MathVariant of the character.
045         */
046        public CodePointAndVariant(final int icodePoint,
047                final MathVariant ivariant) {
048            assert ivariant != null;
049            this.codePoint = icodePoint;
050            this.variant = ivariant;
051        }
052    
053        /**
054         * @return the codePoint
055         */
056        public final int getCodePoint() {
057            return this.codePoint;
058        }
059    
060        /**
061         * @return the variant
062         */
063        public final MathVariant getVariant() {
064            return this.variant;
065        }
066    
067        /** {@inheritDoc} */
068        @Override
069        public int hashCode() {
070            final int prime = 31;
071            int result = 1;
072            result = prime * result + this.codePoint;
073            result = prime * result + this.variant.hashCode();
074            return result;
075        }
076    
077        /** {@inheritDoc} */
078        @Override
079        public boolean equals(final Object obj) {
080            if (this == obj) {
081                return true;
082            }
083            if (obj == null) {
084                return false;
085            }
086            if (this.getClass() != obj.getClass()) {
087                return false;
088            }
089            final CodePointAndVariant other = (CodePointAndVariant) obj;
090            if (this.codePoint != other.codePoint) {
091                return false;
092            }
093            if (this.variant == null) {
094                if (other.variant != null) {
095                    return false;
096                }
097            } else if (!this.variant.equals(other.variant)) {
098                return false;
099            }
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    }