001    /**
002     * Copyright (c) 2000-2010 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    
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            public boolean equals(Object obj) {
054                    State state = (State)obj;
055    
056                    if ((getId() != null) && (state.getId() != null)) {
057                            return getId().equalsIgnoreCase(state.getId());
058                    }
059                    else if ((getName() != null) && (state.getName() != null)) {
060                            return getName().equalsIgnoreCase(state.getName());
061                    }
062                    else {
063                            return false;
064                    }
065            }
066    
067            public int hashCode() {
068                    HashCode hashCode = HashCodeFactoryUtil.getHashCode();
069    
070                    hashCode.append(_id);
071                    hashCode.append(_name);
072    
073                    return hashCode.toHashCode();
074            }
075    
076            private String _id;
077            private String _name;
078    
079    }