1 /*
2 * This software was designed and created by Jason Carroll.
3 * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4 * The author can be reached at jcarroll@cowsultants.com
5 * ITracker website: http://www.cowsultants.com
6 * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it only under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19 package org.itracker.model;
20
21 import org.apache.commons.lang.builder.ToStringBuilder;
22
23 import java.io.Serializable;
24 import java.util.Comparator;
25
26 /**
27 * Class provides basic storage for name values pairs. The name is usually a key
28 * of some type, like a status number, and the value is a localized name for
29 * that key.
30 */
31 public class NameValuePair extends AbstractEntity {
32
33 /**
34 *
35 */
36 private static final long serialVersionUID = 1L;
37
38 private String name = "";
39
40 private String value = "";
41
42 private static final class NameComparator implements Comparator<NameValuePair>, Serializable {
43 /**
44 *
45 */
46 private static final long serialVersionUID = 1L;
47
48 public int compare(NameValuePair./../../org/itracker/model/NameValuePair.html#NameValuePair">NameValuePair o1, NameValuePair o2) {
49
50 return o1.name.compareTo(o2.name);
51 }
52
53 ;
54 }
55
56 private static final class ValueComparator implements Comparator<NameValuePair>, Serializable {
57 /**
58 *
59 */
60 private static final long serialVersionUID = 1L;
61
62 public int compare(NameValuePair./../../org/itracker/model/NameValuePair.html#NameValuePair">NameValuePair o1, NameValuePair o2) {
63 return o1.value.compareTo(o2.value);
64 }
65
66 ;
67 }
68
69 public static final Comparator<NameValuePair> KEY_COMPARATOR = new NameComparator();
70 public static final Comparator<NameValuePair> VALUE_COMPARATOR = new ValueComparator();
71
72 public NameValuePair(String name, String value) {
73 setName(name);
74 setValue(value);
75 }
76
77 /**
78 * Returns the name of the name/value pair.
79 */
80 public String getName() {
81 return name;
82 }
83
84 /**
85 * Sets the name of the name/value pair.
86 */
87 public void setName(String name) {
88 if (name == null) {
89 name = "";
90 }
91 this.name = name;
92 }
93
94 /**
95 * Returns the value of the name/value pair.
96 */
97 public String getValue() {
98 return value;
99 }
100
101 /**
102 * Sets the value of the name/value pair.
103 */
104 public void setValue(String value) {
105 this.value = value;
106 }
107
108 public int compareKeyTo(NameValuePair other) {
109 return KEY_COMPARATOR.compare(this, other);
110 }
111
112 public int compareValueTo(NameValuePair other) {
113 return VALUE_COMPARATOR.compare(this, other);
114 }
115
116
117 //
118 // @Override
119 // public boolean equals(Object obj) {
120 // if (this == obj) {
121 // return true;
122 // }
123 //
124 // if (obj instanceof NameValuePair) {
125 // final NameValuePair other = (NameValuePair) obj;
126 // return new EqualsBuilder().append(name, other.name).append(value,
127 // other.value).isEquals();
128 //
129 // }
130 // return false;
131 // }
132 //
133 // @Override
134 // public int hashCode() {
135 // return new HashCodeBuilder().append(this.name).append(this.value)
136 // .toHashCode();
137 // }
138
139 @Override
140 public String toString() {
141 return new ToStringBuilder(this).append("name", name).append("value",
142 value).toString();
143 }
144
145 }