1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gov.nasa.pds.tools.label;
17
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.ArrayList;
21 import java.util.Map;
22 import java.util.HashMap;
23
24 /***
25 * @author pramirez
26 * @version $Revision: 2915 $
27 *
28 */
29 public class GroupStatement extends Statement {
30 private Map statements;
31 private List comments;
32
33 /***
34 * @param lineNumber
35 * @param identifier
36 */
37 public GroupStatement(int lineNumber, String identifier) {
38 super(lineNumber, identifier);
39 statements = new HashMap();
40 comments = new ArrayList();
41 }
42
43 /***
44 * Retrieves the named attribute.
45 * @param identifier
46 * @return The named AttributeStatement or null if not found.
47 */
48 public AttributeStatement getAttribute(String identifier) {
49 AttributeStatement attribute = null;
50 if (statements.get(identifier) != null) {
51 for (Iterator i = ((List) statements.get(identifier)).iterator(); i.hasNext() && attribute == null;) {
52 Statement statement = (Statement) i.next();
53 if (statement instanceof AttributeStatement)
54 attribute = (AttributeStatement) statement;
55 }
56 }
57 return attribute;
58 }
59
60 /***
61 * Retrieves the attributes of this group.
62 * @return The list of AttributeStatment.
63 */
64 public List getAttributes() {
65 List attributes = new ArrayList();
66 for (Iterator i = statements.values().iterator(); i.hasNext();) {
67 for (Iterator s = ((List) i.next()).iterator(); s.hasNext();) {
68 Statement statement = (Statement) s.next();
69 if (statement instanceof AttributeStatement)
70 attributes.add(statement);
71 }
72 }
73 return attributes;
74 }
75
76 public void addStatement(Statement statement) {
77 List stmnts = (List) statements.get(statement.getIdentifier());
78 if (stmnts == null) {
79 stmnts = new ArrayList();
80 statements.put(statement.getIdentifier(), stmnts);
81 }
82 if (statement instanceof IncludePointer) {
83 stmnts.add(statement);
84 for (Iterator i = ((IncludePointer) statement).getStatements().iterator(); i.hasNext();)
85 addStatement((Statement) i.next());
86 }
87 else if (statement instanceof PointerStatement || statement instanceof AttributeStatement)
88 stmnts.add(statement);
89
90 }
91
92 public boolean hasAttribute(String identifier) {
93 if (getAttribute(identifier) == null)
94 return false;
95 return true;
96 }
97
98 public void attachComment(CommentStatement comment) {
99 comments.add(comment);
100 }
101
102 public List getStatements() {
103 List statementList = new ArrayList();
104 for (Iterator i = statements.values().iterator(); i.hasNext();) {
105 statementList.addAll((List) i.next());
106 }
107 return statementList;
108 }
109 }