View Javadoc

1   package net.sf.chainedoptions;
2   
3   import org.apache.commons.lang.builder.EqualsBuilder;
4   import org.apache.commons.lang.builder.HashCodeBuilder;
5   
6   /***
7    * Simple name/value pair bean for use in cases where an item has a value and a
8    * display label.
9    * 
10   * @author Mattias Arthursson
11   * @author Ulrik Sandberg
12   */
13  public class LabelValueBean implements Comparable {
14      private String value;
15  
16      private String label;
17  
18      public LabelValueBean(String label, String value) {
19          this.value = value;
20          this.label = label;
21      }
22  
23      /***
24       * @return Returns the label.
25       */
26      public String getLabel() {
27          return label;
28      }
29  
30      /***
31       * @param label
32       *            The label to set.
33       */
34      public void setLabel(String label) {
35          this.label = label;
36      }
37  
38      /***
39       * @return Returns the value.
40       */
41      public String getValue() {
42          return value;
43      }
44  
45      /***
46       * @param value
47       *            The value to set.
48       */
49      public void setValue(String value) {
50          this.value = value;
51      }
52  
53      public int compareTo(Object o) {
54          LabelValueBean that = (LabelValueBean) o;
55          return this.label.compareTo(that.label);
56      }
57  
58      /*
59       * @see java.lang.Object#equals(java.lang.Object)
60       */
61      public boolean equals(Object obj) {
62          if (obj == null || !obj.getClass().equals(getClass())) {
63              return false;
64          }
65          LabelValueBean that = (LabelValueBean) obj;
66          return new EqualsBuilder().append(value, that.value).append(label,
67                  that.label).isEquals();
68      }
69  
70      /*
71       * @see java.lang.Object#hashCode()
72       */
73      public int hashCode() {
74          return new HashCodeBuilder().append(value).append(label).toHashCode();
75      }
76  }