1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.commsen.apropos.core;
20
21 import org.apache.commons.lang.StringUtils;
22
23 /***
24 * This class represents property. In APropOS a property is a very simple object having name, value,
25 * description and group it belongs to.
26 *
27 * @author Milen Dyankov
28 *
29 */
30 public class Property implements Cloneable {
31
32 /***
33 * the name
34 */
35 private String name;
36
37 /***
38 * the value
39 */
40 private String value;
41
42 /***
43 * the description
44 */
45 private String description;
46
47 /***
48 * the group this property belongs to
49 */
50 private String group;
51
52
53 /***
54 * Creates new property with given <code>name</code>
55 *
56 * @param name the name of the property
57 * @throws PropertiesException if <code>name</code> is <code>null</code> or blank
58 */
59 public Property(String name) throws PropertiesException {
60 this(name, null, null, null);
61 }
62
63
64 /***
65 * Creates new property object and sets all fields with appropriate values
66 *
67 * @param name the property name
68 * @param value the property value
69 * @param description the property description
70 * @param group the group this property belongs to
71 * @throws PropertiesException if <code>name</code> is <code>null</code> or blank
72 */
73 public Property(String name, String value, String description, String group) throws PropertiesException {
74 setName(name);
75 setValue(value);
76 setDescription(description);
77 setGroup(group);
78 }
79
80
81 /***
82 * Checks if given <code>property</code> is the same as the one represented by this object.
83 * This method will return <code>true</code> if ALL fields have exactly the same values and
84 * <code>false</code> otherwise
85 *
86 * @param property the property to compare
87 * @return <code>true</code> if both object have exactly the same values in all fields and
88 * <code>false</code> otherwise
89 */
90 public boolean sameAs(Property property) {
91 return StringUtils.equals(group, property.getGroup()) && StringUtils.equals(name, property.getName()) && StringUtils.equals(value, property.getValue())
92 && StringUtils.equals(description, property.getDescription());
93 }
94
95
96 /***
97 * {@inheritDoc}
98 */
99 @Override
100 public Object clone() throws CloneNotSupportedException {
101 return super.clone();
102 }
103
104
105 /***
106 * Returns true if <code>obj.name.equals(name)</code>
107 *
108 * @see java.lang.Object#equals(java.lang.Object)
109 */
110 @Override
111 public boolean equals(Object obj) {
112 if (obj == null || !(obj.getClass().equals(this.getClass()))) return false;
113 return ((Property) obj).name.equals(name);
114 }
115
116
117 /***
118 * Returns hashCode based on {@link #name} to conform to modified {@link #equals(Object)}
119 * method.
120 *
121 * @see java.lang.Object#hashCode()
122 */
123 @Override
124 public int hashCode() {
125 int hash = 7;
126 hash = 31 * hash + (null == name ? 0 : name.hashCode());
127 return hash;
128 }
129
130
131 /***
132 * @return the name
133 */
134 public String getName() {
135 return this.name;
136 }
137
138
139 /***
140 * @param name the name of the property
141 * @throws PropertiesException if <code>name</code> is <code>null</code> or blank
142 */
143 public void setName(String name) throws PropertiesException {
144 if (StringUtils.isBlank(name)) throw new PropertiesException("Can not create property without name!");
145 this.name = name;
146 }
147
148
149 /***
150 * @return the value
151 */
152 public String getValue() {
153 return this.value;
154 }
155
156
157 /***
158 * @param value the value to set
159 */
160 public void setValue(String value) {
161 this.value = value;
162 }
163
164
165 /***
166 * @return the description
167 */
168 public String getDescription() {
169 return this.description;
170 }
171
172
173 /***
174 * @param description the description to set
175 */
176 public void setDescription(String description) {
177 this.description = description;
178 }
179
180
181 /***
182 * @return the group
183 */
184 public String getGroup() {
185 return this.group;
186 }
187
188
189 /***
190 * @param group the group to set
191 */
192 public void setGroup(String group) {
193 this.group = group;
194 }
195
196 }