1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gov.nasa.pds.tools.dict;
17
18 import java.util.List;
19 import java.util.ArrayList;
20
21 /***
22 * This class models a group definition. Groups can only contain optional
23 * and required elements. This class will only contain the identifiers of these
24 * elements.
25 * @author pramirez
26 * @version $Revision: 2601 $
27 *
28 */
29 public class GroupDefinition extends Definition {
30 private List requiredElements;
31 private List optionalElements;
32
33 public GroupDefinition(String identifier) {
34 super(identifier);
35 requiredElements = new ArrayList();
36 optionalElements = new ArrayList();
37 }
38
39 /***
40 * Lists the optional elements that can appear in this group
41 * @return Returns the names optional elements.
42 */
43 public List getOptionalElements() {
44 return optionalElements;
45 }
46
47 /***
48 * @param optionalElements The names of optional elements.
49 */
50 public void setOptionalElements(List optionalElements) {
51 this.optionalElements = optionalElements;
52 }
53
54 /***
55 * @return Returns the names of required elements.
56 */
57 public List getRequiredElements() {
58 return requiredElements;
59 }
60
61 /***
62 * @param requiredElements The names of required elements.
63 */
64 public void setRequiredElements(List requiredElements) {
65 this.requiredElements = requiredElements;
66 }
67
68 /***
69 *
70 * @param identifier
71 * @return Returns the required elements.
72 */
73 public boolean mustHaveElement(String identifier) {
74 return requiredElements.contains(identifier);
75 }
76
77 /***
78 *
79 * @param identifier
80 * @return Returns the possible elements.
81 */
82 public boolean canHaveElement(String identifier) {
83 boolean exists = false;
84 exists = requiredElements.contains(identifier);
85 if (exists)
86 return exists;
87 return optionalElements.contains(identifier);
88 }
89
90 public boolean hasElement(String identifier) {
91 if (requiredElements.contains(identifier) || optionalElements.contains(identifier))
92 return true;
93 return false;
94 }
95 }