1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties.extract;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.commons.lang.builder.EqualsBuilder;
26 import org.apache.commons.lang.builder.HashCodeBuilder;
27 import org.apache.commons.lang.builder.ToStringBuilder;
28
29 /***
30 * A class (type) of entities to recognize. Instances of this class are
31 * immutable and thus thread-safe.
32 *
33 * @author Christian Siefkes
34 * @version $Revision: 1.2 $, $Date: 2004/02/03 13:16:42 $, $Author: siefkes $
35 */
36 public class TargetClass {
37
38 /***
39 * The name of this class.
40 */
41 private final String name;
42
43 /***
44 * Non-public constructor -- should only be used by subclasses and related
45 * classes. Other classes should go thru {@link TargetStructure} to access
46 * target classes.
47 *
48 * @param className the name of this class (outer whitespace will be
49 * {@linkplain String#trim() trimmed})
50 * @throws IllegalArgumentException if <code>className</code> is null or
51 * empty (after trimming)
52 */
53 protected TargetClass(final String className)
54 throws IllegalArgumentException {
55 super();
56 final String trimmedName = StringUtils.trimToEmpty(className);
57
58 if (StringUtils.isEmpty(trimmedName)) {
59 throw new IllegalArgumentException(
60 "Target class name must not be null or empty");
61 }
62 name = trimmedName;
63 }
64
65 /***
66 * Indicates whether some other object is "equal to" this one, fulfulling
67 * the {@link Object#equals(java.lang.Object)} contract.
68 *
69 * @param obj the reference object with which to compare
70 * @return <code>true</code> iff the specified object is a
71 * {@link TargetClass} equal to this instance
72 */
73 public boolean equals(final Object obj) {
74 if (obj == this) {
75 return true;
76 } else if ((obj != null) && (getClass().equals(obj.getClass()))) {
77
78
79 final TargetClass other = (TargetClass) obj;
80 return new EqualsBuilder()
81 .append(getName(), other.getName())
82 .isEquals();
83 } else {
84 return false;
85 }
86 }
87
88 /***
89 * Returns the name of this class.
90 * @return the value of the attribute
91 */
92 public String getName() {
93 return name;
94 }
95
96 /***
97 * Returns a hash code value for this object, fulfulling the
98 * {@link Object#hashCode()} contract.
99 *
100 * @return a hash code value for this object
101 */
102 public int hashCode() {
103
104
105 return new HashCodeBuilder(13, 17)
106 .append(getName())
107 .toHashCode();
108 }
109
110 /***
111 * Returns a string representation of this object.
112 * @return a textual representation
113 */
114 public String toString() {
115 return new ToStringBuilder(this)
116 .append("name", name)
117 .toString();
118 }
119
120 }