001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util;
016    
017    import com.liferay.portal.kernel.util.HashCode;
018    import com.liferay.portal.kernel.util.HashCodeFactoryUtil;
019    import com.liferay.portal.kernel.util.StringUtil;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class State {
025    
026            public State(String id, String name) {
027                    _id = id;
028                    _name = name;
029            }
030    
031            public int compareTo(Object obj) {
032                    State state = (State)obj;
033    
034                    if ((getId() != null) && (state.getId() != null)) {
035                            return StringUtil.toLowerCase(getId()).compareTo(
036                                    StringUtil.toLowerCase(state.getId()));
037                    }
038                    else if ((getName() != null) && (state.getName() != null)) {
039                            return StringUtil.toLowerCase(getName()).compareTo(
040                                    StringUtil.toLowerCase(state.getName()));
041                    }
042                    else {
043                            return -1;
044                    }
045            }
046    
047            @Override
048            public boolean equals(Object obj) {
049                    if (this == obj) {
050                            return true;
051                    }
052    
053                    if (!(obj instanceof State)) {
054                            return false;
055                    }
056    
057                    State state = (State)obj;
058    
059                    if ((getId() != null) && (state.getId() != null)) {
060                            return StringUtil.equalsIgnoreCase(getId(), state.getId());
061                    }
062                    else if ((getName() != null) && (state.getName() != null)) {
063                            return StringUtil.equalsIgnoreCase(getName(), state.getName());
064                    }
065                    else {
066                            return false;
067                    }
068            }
069    
070            public String getId() {
071                    return _id;
072            }
073    
074            public String getName() {
075                    return _name;
076            }
077    
078            @Override
079            public int hashCode() {
080                    HashCode hashCode = HashCodeFactoryUtil.getHashCode();
081    
082                    hashCode.append(_id);
083                    hashCode.append(_name);
084    
085                    return hashCode.toHashCode();
086            }
087    
088            private String _id;
089            private String _name;
090    
091    }