package iotpolicy.tree;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/** Class InterfaceDecl is a data structure for interface
* declaration section in the policy file.
* @version 1.0
* @since 2016-09-20
*/
-public final class InterfaceDecl {
+public class InterfaceDecl {
/**
* Class properties
* In this data structure we will record its interface name, i.e. Camera
* its method names and the parameters for each method.
*/
- private List<String> listMethods; // Method names, e.g. MethodA
+ private List<String> listMethods; // Method signature (no spaces), e.g. MethodA(intA,SpeakerB)
+ private List<String> listMethodIds; // Method identifiers, e.g. MethodA
private List<String> listMethodTypes; // Method types, e.g. void
private List<List<String>> listMethodParams; // Method parameter names, e.g. A, B
private List<List<String>> listMethodParamTypes; // Method parameter types, e.g. int, int
origInt = null;
listMethods = new ArrayList<String>();
+ listMethodIds = new ArrayList<String>();
listMethodTypes = new ArrayList<String>();
listMethodParams = new ArrayList<List<String>>();
listMethodParamTypes = new ArrayList<List<String>>();
origInt = _origInt;
listMethods = new ArrayList<String>();
+ listMethodIds = new ArrayList<String>();
listMethodTypes = new ArrayList<String>();
listMethodParams = new ArrayList<List<String>>();
listMethodParamTypes = new ArrayList<List<String>>();
/**
* addNewMethod() adds a new method name and type into the list
*/
- public void addNewMethod(String newMethod, String newMethodType) {
+ public void addNewMethod(String newMethod, String newMethodId, String newMethodType) {
listMethods.add(newMethod);
+ listMethodIds.add(newMethodId);
listMethodTypes.add(newMethodType);
listMethodParams.add(new ArrayList<String>());
listMethodParamTypes.add(new ArrayList<String>());
return listMethods;
}
-
-
+
+
+ /**
+ * getMethodIds() gets method identifiers
+ */
+ public List<String> getMethodIds() {
+
+ return listMethodIds;
+ }
+
+
/**
* getMethodTypes() gets method types
*/
}
+ /**
+ * getMethodId() gets a method identifier
+ */
+ public String getMethodId(String method) {
+
+ int index = listMethods.indexOf(method);
+ return listMethodIds.get(index);
+ }
+
+
/**
* getMethodType() gets a method type
*/
public static void main(String[] args) {
InterfaceDecl id = new InterfaceDecl("Camera");
- id.addNewMethod("MethodA", "void");
- id.addNewMethod("MethodB", "int");
- id.addNewMethod("MethodC", "String");
+ id.addNewMethod("MethodA(intA,SpeakerB)", "MethodA", "void");
id.addMethodParam("MethodA", "A", "int");
id.addMethodParam("MethodA", "B", "int");
id.addMethodParam("MethodB", "C", "int");
id.addMethodParam("MethodC", "E", "string");
id.addMethodParam("MethodC", "F", "int");
-
-
System.out.println("Set of methods: " + id.getMethods().toString());
System.out.println("Set of params: " + id.getMethodParams("MethodA").toString());
System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString());