001    /*
002     * 
003     * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
004     *
005     * This file is part of ***  M y C o R e  ***
006     * See http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, in a file called gpl.txt or license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     */
023    
024    package org.mycore.datamodel.classifications2;
025    
026    import java.io.Serializable;
027    
028    /**
029     * This class represents a label of a MCRCategory.
030     * 
031     * @author Thomas Scheffler (yagee)
032     * 
033     * @version $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
034     * @since 2.0
035     */
036    public class MCRLabel implements Cloneable, Serializable {
037    
038        private static final long serialVersionUID = -843799854929361194L;
039    
040        String lang, text, description;
041    
042        public MCRLabel() {
043    
044        }
045    
046        public MCRLabel(String lang, String text, String description) {
047            super();
048            this.lang = lang;
049            this.text = text;
050            this.description = description;
051        }
052    
053        public String getLang() {
054            return lang;
055        }
056    
057        public void setLang(String lang) {
058            this.lang = lang;
059        }
060    
061        public String getText() {
062            return text;
063        }
064    
065        public void setText(String text) {
066            this.text = text;
067        }
068    
069        public String getDescription() {
070            if (description == null)
071                return "";
072            return description;
073        }
074    
075        public void setDescription(String description) {
076            this.description = description;
077        }
078    
079        @Override
080        public MCRLabel clone() {
081            MCRLabel clone = null;
082            try {
083                clone = (MCRLabel) super.clone();
084            } catch (CloneNotSupportedException ce) {
085                // Can not happen
086            }
087            return clone;
088        }
089    
090        @Override
091        public String toString() {
092            StringBuilder sb = new StringBuilder();
093            sb.append(getLang());
094            sb.append('(');
095            sb.append(getText());
096            sb.append(')');
097            return sb.toString();
098        }
099    
100        /*
101         * (non-Javadoc)
102         * 
103         * @see java.lang.Object#hashCode()
104         */
105        @Override
106        public int hashCode() {
107            final int PRIME = 31;
108            int result = 1;
109            result = PRIME * result + getDescription().hashCode();
110            result = PRIME * result + ((lang == null) ? 0 : lang.hashCode());
111            result = PRIME * result + ((text == null) ? 0 : text.hashCode());
112            return result;
113        }
114    
115        /*
116         * (non-Javadoc)
117         * 
118         * @see java.lang.Object#equals(java.lang.Object)
119         */
120        @Override
121        public boolean equals(Object obj) {
122            if (this == obj)
123                return true;
124            if (obj == null)
125                return false;
126            if (getClass() != obj.getClass())
127                return false;
128            final MCRLabel other = (MCRLabel) obj;
129            if (lang == null) {
130                if (other.lang != null)
131                    return false;
132            } else if (!lang.equals(other.lang))
133                return false;
134            if (text == null) {
135                if (other.text != null)
136                    return false;
137            } else if (!text.equals(other.text))
138                return false;
139            if (!getDescription().equals(other.getDescription()))
140                return false;
141            return true;
142        }
143    
144    }