001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }