1 package org.appfuse.model; 2 3 import java.io.Serializable ; 4 import java.util.Comparator ; 5 6 18 public class LabelValue implements Comparable , Serializable { 19 private static final long serialVersionUID = 3689355407466181430L; 20 21 25 public static final Comparator CASE_INSENSITIVE_ORDER = new Comparator () { 26 public int compare(Object o1, Object o2) { 27 String label1 = ((LabelValue) o1).getLabel(); 28 String label2 = ((LabelValue) o2).getLabel(); 29 return label1.compareToIgnoreCase(label2); 30 } 31 }; 32 33 34 36 37 40 public LabelValue() { 41 super(); 42 } 43 44 50 public LabelValue(String label, String value) { 51 this.label = label; 52 this.value = value; 53 } 54 55 56 58 59 62 private String label = null; 63 64 public String getLabel() { 65 return this.label; 66 } 67 68 public void setLabel(String label) { 69 this.label = label; 70 } 71 72 73 76 private String value = null; 77 78 public String getValue() { 79 return this.value; 80 } 81 82 public void setValue(String value) { 83 this.value = value; 84 } 85 86 87 89 95 public int compareTo(Object o) { 96 String otherLabel = ((LabelValue) o).getLabel(); 99 100 return this.getLabel().compareTo(otherLabel); 101 } 102 103 106 public String toString() { 107 StringBuffer sb = new StringBuffer ("LabelValue["); 108 sb.append(this.label); 109 sb.append(", "); 110 sb.append(this.value); 111 sb.append("]"); 112 return (sb.toString()); 113 } 114 115 120 public boolean equals(Object obj) { 121 if (obj == this) { 122 return true; 123 } 124 125 if (!(obj instanceof LabelValue)) { 126 return false; 127 } 128 129 LabelValue bean = (LabelValue) obj; 130 int nil = (this.getValue() == null) ? 1 : 0; 131 nil += (bean.getValue() == null) ? 1 : 0; 132 133 if (nil == 2) { 134 return true; 135 } else if (nil == 1) { 136 return false; 137 } else { 138 return this.getValue().equals(bean.getValue()); 139 } 140 141 } 142 143 148 public int hashCode() { 149 return (this.getValue() == null) ? 17 : this.getValue().hashCode(); 150 } 151 } | Popular Tags |