1 package iotpolicy.tree;
3 import java.util.ArrayList;
7 /** Class StructDecl is a data structure for struct
8 * declaration section in the policy file.
10 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
14 public class StructDecl extends Declaration {
17 * A "struct" declaration:
24 * In this data structure we will record its struct name, i.e. Struct,
25 * and its member types and members.
31 private List<String> listStructs; // Struct types/names (more than one struct)
32 private List<List<String>> listMemberTypes; // Member types, e.g. string, float, int, etc.
33 private List<List<String>> listMembers; // Member names, e.g. name, value, year, etc.
41 listStructs = new ArrayList<String>();
42 listMemberTypes = new ArrayList<List<String>>();
43 listMembers = new ArrayList<List<String>>();
47 public StructDecl(String _origInt) {
50 listStructs = new ArrayList<String>();
51 listMemberTypes = new ArrayList<List<String>>();
52 listMembers = new ArrayList<List<String>>();
57 * addNewMember() adds a new member type and value into the list
59 public void addNewMember(String structType, String newMemberType, String newMember) {
61 if (listStructs.contains(structType)) {
62 // Existing enum declaration
63 int index = listStructs.indexOf(structType);
64 List<String> memberTypeList = listMemberTypes.get(index);
65 memberTypeList.add(newMemberType);
66 List<String> memberList = listMembers.get(index);
67 memberList.add(newMember);
70 List<String> newMemberTypeList = new ArrayList<String>();
71 newMemberTypeList.add(newMemberType);
72 listMemberTypes.add(newMemberTypeList);
73 List<String> newMemberList = new ArrayList<String>();
74 newMemberList.add(newMember);
75 listMembers.add(newMemberList);
81 * getStructTypes() gets list of recorded list structs
83 public List<String> getStructTypes() {
90 * getMemberTypes() gets list of member types
92 public List<String> getMemberTypes(String structType) {
94 int index = listStructs.indexOf(structType);
95 return listMemberTypes.get(index);
100 * getMembers() gets list of members
102 public List<String> getMembers(String structType) {
104 int index = listStructs.indexOf(structType);
105 return listMembers.get(index);