1 package iotpolicy.tree;
3 import java.util.ArrayList;
6 /** Class InterfaceDecl is a data structure for interface
7 * declaration section in the policy file.
9 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
13 public final class InterfaceDecl {
18 private String origInt;
21 * A "interface" statement:
22 * public interface Camera {
23 * public void MethodA(int A, int B);
24 * public int MethodB(int C, string D);
25 * public string MethodC(string E, int F);
26 * public float MethodD(int G, float H);
27 * public boolean MethodE(Camera I, boolean J);
28 * public void MethodF();
30 * In this data structure we will record its interface name, i.e. Camera
31 * its method names and the parameters for each method.
33 private List<String> listMethods; // Method names, e.g. MethodA
34 private List<String> listMethodTypes; // Method types, e.g. void
35 private List<List<String>> listMethodParams; // Method parameter names, e.g. A, B
36 private List<List<String>> listMethodParamTypes; // Method parameter types, e.g. int, int
41 public InterfaceDecl() {
44 listMethods = new ArrayList<String>();
45 listMethodTypes = new ArrayList<String>();
46 listMethodParams = new ArrayList<List<String>>();
47 listMethodParamTypes = new ArrayList<List<String>>();
51 public InterfaceDecl(String _origInt) {
54 listMethods = new ArrayList<String>();
55 listMethodTypes = new ArrayList<String>();
56 listMethodParams = new ArrayList<List<String>>();
57 listMethodParamTypes = new ArrayList<List<String>>();
62 * addNewMethod() adds a new method name and type into the list
64 public void addNewMethod(String newMethod, String newMethodType) {
66 listMethods.add(newMethod);
67 listMethodTypes.add(newMethodType);
68 listMethodParams.add(new ArrayList<String>());
69 listMethodParamTypes.add(new ArrayList<String>());
74 * addMethodParam() adds the name and type of a parameter
76 public void addMethodParam(String method, String paramName, String paramType) {
78 int index = listMethods.indexOf(method);
79 List<String> listMethodParam = listMethodParams.get(index);
80 listMethodParam.add(paramName);
81 List<String> listMethodParamType = listMethodParamTypes.get(index);
82 listMethodParamType.add(paramType);
87 * getMethods() gets list of methods
89 public List<String> getMethods() {
96 * getMethodTypes() gets method types
98 public List<String> getMethodTypes() {
100 return listMethodTypes;
105 * getMethodType() gets a method type
107 public String getMethodType(String method) {
109 int index = listMethods.indexOf(method);
110 return listMethodTypes.get(index);
115 * getMethodParams() gets list of method parameters for a method
117 public List<String> getMethodParams(String method) {
119 int index = listMethods.indexOf(method);
120 return listMethodParams.get(index);
125 * getMethodParams() gets list of method parameter types for a method
127 public List<String> getMethodParamTypes(String method) {
129 int index = listMethods.indexOf(method);
130 return listMethodParamTypes.get(index);
134 public static void main(String[] args) {
136 InterfaceDecl id = new InterfaceDecl("Camera");
137 id.addNewMethod("MethodA", "void");
138 id.addNewMethod("MethodB", "int");
139 id.addNewMethod("MethodC", "String");
140 id.addMethodParam("MethodA", "A", "int");
141 id.addMethodParam("MethodA", "B", "int");
142 id.addMethodParam("MethodB", "C", "int");
143 id.addMethodParam("MethodB", "D", "string");
144 id.addMethodParam("MethodC", "E", "string");
145 id.addMethodParam("MethodC", "F", "int");
149 System.out.println("Set of methods: " + id.getMethods().toString());
150 System.out.println("Set of params: " + id.getMethodParams("MethodA").toString());
151 System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString());
152 System.out.println("Set of params: " + id.getMethodParams("MethodB").toString());
153 System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodB").toString());
154 System.out.println("Set of params: " + id.getMethodParams("MethodC").toString());
155 System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodC").toString());