1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package sfutils.frs;
29
30 import sfutils.NamedObject;
31
32 /***
33 * A {@link NamedObject} that {@linkplain #setHidden(boolean) may be hidden from
34 * view}.
35 *
36 * @author <a href="mailto:ljnelson94@alumni.amherst.edu">Laird Nelson</a>
37 * @version $Revision: 1.5 $ $Date: 2003/07/12 16:13:24 $
38 * @since May 21, 2003
39 */
40 public abstract class HideableNamedObject extends NamedObject {
41
42 /***
43 * Whether or not this {@link HideableNamedObject} is currently hidden.
44 *
45 * @see #isHidden()
46 */
47 private boolean hidden;
48
49 /***
50 * Creates a new {@link HideableNamedObject}.
51 */
52 public HideableNamedObject() {
53 super();
54 }
55
56 /***
57 * Creates a new {@link HideableNamedObject} with the supplied name. This
58 * constructor calls its {@link NamedObject#NamedObject(String) superclass'
59 * implementation} with the supplied name.
60 *
61 * @param name
62 * the name for the new {@link HideableNamedObject}; may be
63 * <code>null</code>
64 */
65 public HideableNamedObject(final String name) {
66 super(name);
67 }
68
69 /***
70 * Returns <code>true</code> if and only if this {@link HideableNamedObject}
71 * is hidden from view.
72 *
73 * @return <code>true</code> if and only if this {@link
74 * HideableNamedObject} is hidden from view
75 * @see #setHidden(boolean)
76 */
77 public boolean isHidden() {
78 return this.hidden;
79 }
80
81 /***
82 * Sets whether this {@link HideableNamedObject} is hidden from view.
83 *
84 * @param hidden
85 * if <code>true</code>, this {@link HideableNamedObject} will
86 * be hidden from view
87 * @see #isHidden()
88 */
89 public void setHidden(final boolean hidden) {
90 this.hidden = hidden;
91 }
92
93 /***
94 * Returns a hashcode for this {@link HideableNamedObject} based off its
95 * {@linkplain #getName() name} and its {@linkplain #isHidden() hidden
96 * status}.
97 *
98 * @return a hashcode for this {@link HideableNamedObject}
99 */
100 public int hashCode() {
101 int hashCode = super.hashCode();
102 if (this.isHidden()) {
103 ++hashCode;
104 }
105 return hashCode;
106 }
107
108 /***
109 * Tests the supplied {@link Object} to see if it is equal to this {@link
110 * HideableNamedObject}. An {@link Object} is equal to this {@link
111 * HideableNamedObject} if it is an instance of the {@link
112 * HideableNamedObject} class and its {@linkplain #getName() name} is equal to
113 * this {@link HideableNamedObject}'s {@linkplain #getName() name}. {@link
114 * HideableNamedObject}s are, in other words, value objects.
115 *
116 * @param anObject
117 * the {@link Object} to test; may be <code>null</code>
118 * @return <code>true</code> if and only if the supplied {@link Object} is
119 * equal to this {@link HideableNamedObject}
120 */
121 public boolean equals(final Object anObject) {
122 if (anObject == this) {
123 return true;
124 } else if (anObject instanceof HideableNamedObject &&
125 super.equals(anObject)) {
126
127
128 return this.isHidden() == ((HideableNamedObject)anObject).isHidden();
129
130 } else {
131 return false;
132 }
133 }
134
135 /***
136 * Returns a {@link String} representation of this {@link
137 * HideableNamedObject}. This method never returns <code>null</code>.
138 *
139 * @return a {@link String} representation of this {@link
140 * HideableNamedObject}; never <code>null</code>
141 */
142 public String toString() {
143 final StringBuffer returnMe = new StringBuffer();
144 final String parentRep = super.toString();
145 if (parentRep == null) {
146 returnMe.append("Unnamed");
147 } else {
148 returnMe.append(parentRep);
149 }
150 if (this.isHidden()) {
151 returnMe.append(" (hidden)");
152 }
153 return returnMe.toString();
154 }
155
156 }