1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util;
16  
17  import com.liferay.portal.kernel.util.HashCode;
18  import com.liferay.portal.kernel.util.HashCodeFactoryUtil;
19  
20  /**
21   * <a href="State.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class State {
26  
27      public State(String id, String name) {
28          _id = id;
29          _name = name;
30      }
31  
32      public String getId() {
33          return _id;
34      }
35  
36      public String getName() {
37          return _name;
38      }
39  
40      public int compareTo(Object obj) {
41          State state = (State)obj;
42  
43          if (getId() != null && state.getId() != null) {
44              return getId().toLowerCase().compareTo(state.getId().toLowerCase());
45          }
46          else if (getName() != null && state.getName() != null) {
47              return getName().toLowerCase().compareTo(
48                  state.getName().toLowerCase());
49          }
50          else {
51              return -1;
52          }
53      }
54  
55      public boolean equals(Object obj) {
56          State state = (State)obj;
57  
58          if ((getId() != null) && (state.getId() != null)) {
59              return getId().equalsIgnoreCase(state.getId());
60          }
61          else if ((getName() != null) && (state.getName() != null)) {
62              return getName().equalsIgnoreCase(state.getName());
63          }
64          else {
65              return false;
66          }
67      }
68  
69      public int hashCode() {
70          HashCode hashCode = HashCodeFactoryUtil.getHashCode();
71  
72          hashCode.append(_id);
73          hashCode.append(_name);
74  
75          return hashCode.toHashCode();
76      }
77  
78      private String _id;
79      private String _name;
80  
81  }