1 18 19 package org.apache.struts.util; 20 21 import java.io.Serializable ; 22 import java.util.Comparator ; 23 24 36 public class LabelValueBean implements Comparable , Serializable { 37 38 42 public static final Comparator CASE_INSENSITIVE_ORDER = new Comparator () { 43 public int compare(Object o1, Object o2) { 44 String label1 = ((LabelValueBean) o1).getLabel(); 45 String label2 = ((LabelValueBean) o2).getLabel(); 46 return label1.compareToIgnoreCase(label2); 47 } 48 }; 49 50 51 53 54 57 public LabelValueBean() { 58 super(); 59 } 60 61 67 public LabelValueBean(String label, String value) { 68 this.label = label; 69 this.value = value; 70 } 71 72 73 75 76 79 private String label = null; 80 81 public String getLabel() { 82 return this.label; 83 } 84 85 public void setLabel(String label) { 86 this.label = label; 87 } 88 89 90 93 private String value = null; 94 95 public String getValue() { 96 return this.value; 97 } 98 99 public void setValue(String value) { 100 this.value = value; 101 } 102 103 104 106 111 public int compareTo(Object o) { 112 String otherLabel = ((LabelValueBean) o).getLabel(); 115 116 return this.getLabel().compareTo(otherLabel); 117 } 118 119 122 public String toString() { 123 StringBuffer sb = new StringBuffer ("LabelValueBean["); 124 sb.append(this.label); 125 sb.append(", "); 126 sb.append(this.value); 127 sb.append("]"); 128 return (sb.toString()); 129 } 130 131 135 public boolean equals(Object obj) { 136 if (obj == this) { 137 return true; 138 } 139 140 if (!(obj instanceof LabelValueBean)) { 141 return false; 142 } 143 144 LabelValueBean bean = (LabelValueBean) obj; 145 int nil = (this.getValue() == null) ? 1 : 0; 146 nil += (bean.getValue() == null) ? 1 : 0; 147 148 if (nil == 2) { 149 return true; 150 } else if (nil == 1) { 151 return false; 152 } else { 153 return this.getValue().equals(bean.getValue()); 154 } 155 156 } 157 158 162 public int hashCode() { 163 return (this.getValue() == null) ? 17 : this.getValue().hashCode(); 164 } 165 } 166 | Popular Tags |