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 import com.liferay.portal.kernel.util.StringUtil;
020
021
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 }