001
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
023 public class State {
024
025 public State(String id, String name) {
026 _id = id;
027 _name = name;
028 }
029
030 public int compareTo(Object obj) {
031 State state = (State)obj;
032
033 if ((getId() != null) && (state.getId() != null)) {
034 return getId().toLowerCase().compareTo(state.getId().toLowerCase());
035 }
036 else if ((getName() != null) && (state.getName() != null)) {
037 return getName().toLowerCase().compareTo(
038 state.getName().toLowerCase());
039 }
040 else {
041 return -1;
042 }
043 }
044
045 @Override
046 public boolean equals(Object obj) {
047 if (this == obj) {
048 return true;
049 }
050
051 if (!(obj instanceof State)) {
052 return false;
053 }
054
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 public String getId() {
069 return _id;
070 }
071
072 public String getName() {
073 return _name;
074 }
075
076 @Override
077 public int hashCode() {
078 HashCode hashCode = HashCodeFactoryUtil.getHashCode();
079
080 hashCode.append(_id);
081 hashCode.append(_name);
082
083 return hashCode.toHashCode();
084 }
085
086 private String _id;
087 private String _name;
088
089 }