001    /**
002     * Copyright (c) 2000-2011 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    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class State {
024    
025            public State(String id, String name) {
026                    _id = id;
027                    _name = name;
028            }
029    
030            public String getId() {
031                    return _id;
032            }
033    
034            public String getName() {
035                    return _name;
036            }
037    
038            public int compareTo(Object obj) {
039                    State state = (State)obj;
040    
041                    if (getId() != null && state.getId() != null) {
042                            return getId().toLowerCase().compareTo(state.getId().toLowerCase());
043                    }
044                    else if (getName() != null && state.getName() != null) {
045                            return getName().toLowerCase().compareTo(
046                                    state.getName().toLowerCase());
047                    }
048                    else {
049                            return -1;
050                    }
051            }
052    
053            @Override
054            public boolean equals(Object obj) {
055                    State state = (State)obj;
056    
057                    if ((getId() != null) && (state.getId() != null)) {
058                            return getId().equalsIgnoreCase(state.getId());
059                    }
060                    else if ((getName() != null) && (state.getName() != null)) {
061                            return getName().equalsIgnoreCase(state.getName());
062                    }
063                    else {
064                            return false;
065                    }
066            }
067    
068            @Override
069            public int hashCode() {
070                    HashCode hashCode = HashCodeFactoryUtil.getHashCode();
071    
072                    hashCode.append(_id);
073                    hashCode.append(_name);
074    
075                    return hashCode.toHashCode();
076            }
077    
078            private String _id;
079            private String _name;
080    
081    }