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.Project;
31
32 /***
33 * A {@link HideableNamedObject} that represents a <a
34 * href="http://sourceforge.net/">SourceForge</a> package.
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 June 19, 2003
39 */
40 public class Package extends HideableNamedObject {
41
42 /***
43 * The identifier for this {@link Package}. {@link Package} identifiers are
44 * assigned by <a href="http://sourceforge.net/">SourceForge</a>. This field
45 * may be <code>null</code>.
46 */
47 private String id;
48
49 /***
50 * The {@link Project} to which this {@link Package} belongs. This field may
51 * be <code>null</code>.
52 */
53 private Project project;
54
55 /***
56 * Creates a new {@link Package}.
57 */
58 public Package() {
59 this(null, null);
60 }
61
62 /***
63 * Creates a new {@link Package} with the supplied name. This constructor
64 * calls the {@link #Package(Project, String)} constructor with
65 * <code>null</code> and the supplied name as its argument values.
66 *
67 * @param name
68 * the name for the new {@link Package}; may be
69 * <code>null</code>
70 */
71 public Package(final String name) {
72 this(null, name);
73 }
74
75 /***
76 * Creates a new {@link Package} with the supplied {@link Project} as its
77 * parent. This constructor calls the {@link #Package(Project, String)}
78 * constructor with the supplied {@link Project} and <code>null</code> as its
79 * argument values.
80 *
81 * @param parent
82 * the {@link Project} to which this new {@link Package} will
83 * belong; may be <code>null</code>
84 */
85 public Package(final Project parent) {
86 this(parent, null);
87 }
88
89 /***
90 * Creates a new {@link Package} with the supplied name and that will belong
91 * to the supplied {@link Project}. This constructor calls its {@linkplain
92 * HideableNamedObject#HideableNamedObject(String) superclass' implementation}
93 * with the supplied name, and then calls the {@link #setProject(Project)}
94 * method with the supplied {@link Project}.
95 *
96 * @param parent
97 * the {@link Project} to which this {@link Package} will
98 * belong; may be <code>null</code>
99 * @param name
100 * the name of this new {@link Package}; may be
101 * <code>null</code>
102 */
103 public Package(final Project parent,
104 final String name) {
105 super(name);
106 this.setProject(parent);
107 }
108
109 /***
110 * Sets the identifier of this {@link Package}. Identifiers are normally
111 * assigned by <a href="http://sourceforge.net/">SourceForge</a>.
112 *
113 * @param id
114 * the new identifier; may be <code>null</code>
115 * @see #getID()
116 */
117 public void setID(final String id) {
118 this.id = id;
119 }
120
121 /***
122 * Returns the identifier of this {@link Package}. Identifiers are normally
123 * assigned by <a href="http://sourceforge.net/">SourceForge</a>. This method
124 * may return <code>null</code>.
125 *
126 * @return the identifier of this {@link Package}, or <code>null</code>
127 * @see #setID(String)
128 */
129 public String getID() {
130 return this.id;
131 }
132
133 /***
134 * Returns the {@link Project} to which this {@link Package} belongs. This
135 * method may return <code>null</code>.
136 *
137 * @return the {@link Project} to which this {@link Package} belongs, or
138 * <code>null</code>
139 * @see #setProject(Project)
140 */
141 public Project getProject() {
142 return this.project;
143 }
144
145 /***
146 * Sets the {@link Project} to which this {@link Package} belongs.
147 *
148 * @param project
149 * the {@link Project} to which this {@link Package} will
150 * belong; may be <code>null</code>
151 * @see #getProject()
152 */
153 public void setProject(final Project project) {
154 this.project = project;
155 }
156
157 /***
158 * Returns a hashcode for this {@link Package} based on all of its attributes.
159 *
160 * @return a hashcode for this {@link Package}
161 */
162 public int hashCode() {
163 final String id = this.getID();
164 final Project project = this.getProject();
165 int hashCode = super.hashCode();
166 if (id != null) {
167 hashCode += id.hashCode();
168 }
169 if (project != null) {
170 hashCode += project.hashCode();
171 }
172 return hashCode;
173 }
174
175 /***
176 * Tests the supplied {@link Object} to see if it is equal to this {@link
177 * Package}. An {@link Object} is equal to this {@link Package} if it is an
178 * instance of the {@link Package} class and all of its {@link Package}
179 * attributes are equal to this {@link Package}'s attributes. {@link
180 * Package}s are, in other words, value objects.
181 *
182 * @param anObject
183 * the {@link Object} to test; may be <code>null</code>
184 * @return <code>true</code> if and only if the supplied {@link Object} is
185 * equal to this {@link Package}
186 */
187 public boolean equals(final Object anObject) {
188 if (anObject == this) {
189 return true;
190 } else if (anObject instanceof Package &&
191 super.equals(anObject)) {
192 final Package other = (Package)anObject;
193
194
195 final String id = this.getID();
196 final String otherID = other.getID();
197 if (id == null) {
198 if (otherID != null) {
199 return false;
200 }
201 } else if (!id.equals(otherID)) {
202 return false;
203 }
204
205
206 final Project project = this.getProject();
207 final Project otherProject = other.getProject();
208 if (project == null) {
209 return otherProject == null;
210 }
211 return project.equals(otherProject);
212
213 } else {
214 return false;
215 }
216 }
217
218 }