1 package iotpolicy.tree;
3 import java.util.ArrayList;
4 import java.util.HashMap;
9 /** Class RequiresDecl is a data structure for "requires"
10 * declaration section in the policy file.
11 * This section declares the needed interfaces based on
12 * different combinations of capabilities.
14 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
18 public final class RequiresDecl {
23 private String origInt;
26 * A "requires" statement:
27 * requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData;
29 * In this data structure we will record its new interface name, i.e. CameraWithCaptureAndData
30 * and its required capabilities, i.e. VideoRecording and ImageCapture.
32 private Map<String,List<String>> mapRequires;
37 public RequiresDecl() {
40 mapRequires = new HashMap<String,List<String>>();
44 public RequiresDecl(String _origInt) {
47 mapRequires = new HashMap<String,List<String>>();
52 * addNewInterface() adds a new interface name into the map
54 public void addNewIntface(String newInt) {
56 mapRequires.put(newInt, new ArrayList<String>());
61 * addNewCapability() adds a new capability name into the map
63 public void addNewCapability(String intFace, String newCapab) {
65 List<String> listCapab = mapRequires.get(intFace);
66 listCapab.add(newCapab);
71 * getInterfaces() gets set of interfaces
73 public Set<String> getInterfaces() {
75 return mapRequires.keySet();
80 * getCapabList() gets list of capabilities
82 public List<String> getCapabList(String intFace) {
84 return mapRequires.get(intFace);
88 public static void main(String[] args) {
90 RequiresDecl rd = new RequiresDecl("Camera");
91 rd.addNewIntface("CameraWithCaptureAndData");
92 rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture");
93 rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording");
95 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
96 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
98 rd.addNewIntface("CameraWithCaptureAndRecording");
99 rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture");
100 rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData");
102 System.out.println("Set of interfaces: " + rd.getInterfaces().toString());
103 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());
104 System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString());