1 package iotruntime.slave;
3 import java.io.Serializable;
4 import java.lang.UnsupportedOperationException;
6 import java.util.HashMap;
7 import java.util.HashSet;
11 /** Class IRelation is another wrapper class of IoTRelation that is the
12 * actual implementation of @config IoTRelation<...>.
13 * The function is the same as the IoTRelation class, but this class
14 * is meant for the class instrumenter to have full access to
15 * our class object. The IoTRelation class functions as an immutable
16 * interface to clients/users.
18 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
22 public final class IRelation<K,V> implements Serializable {
25 * Reference to an object Map<T>
27 private Map<K,HashSet<V> > mapRelation;
35 * Class constructor (create object in this mutable wrapper)
37 protected IRelation() {
39 mapRelation = new HashMap<K,HashSet<V> >();
43 * Method containsKey() inherited from Map interface
45 * @param key The first Object that is usually a key in a Map
48 public boolean containsKey(Object key) {
50 return mapRelation.containsKey(key);
55 * Method relationMap() returns this mapRelation object
57 * @return Map<K,HashSet<V>>>
59 public Map<K,HashSet<V> > relationMap() {
66 * Method entrySet() inherited from Map interface
68 * @return Set<Map.Entry<K,HashSet<V>>>
70 public Set<Map.Entry<K,HashSet<V>>> entrySet() {
72 return mapRelation.entrySet();
77 * Method keySet() inherited from Map interface
81 public Set<K> keySet() {
83 return mapRelation.keySet();
88 * Method get() inherited from Map interface
90 * @param key The first Object that is usually a key in a Map
93 public HashSet<V> get(Object key) {
95 return mapRelation.get(key);
100 * Method isEmpty() inherited from Map interface
104 public boolean isEmpty() {
106 return mapRelation.isEmpty();
113 * We check whether the same object has existed or not
114 * If it has, then we don't insert it again if it is a key
115 * If it is a value and it maps to the same value, we don't
116 * try to create a new key; we just map it to the same key
117 * This method is just used the first time it is needed to
118 * add new objects, then it is going to be made immutable
121 * -------------------------------
122 * | Obj 1 | Set Obj 1.1 |
126 * -------------------------------
127 * | Obj 2 | Set Obj 2.1 |
128 * -------------------------------
129 * | Obj 3 | Set Obj 3.1 |
131 * -------------------------------
133 * @param key The first Object that is usually a key in a Map
134 * @param value The second Object that is usually a value in a Map
137 public boolean put(K key, V value) {
141 // Go to our map first
142 if (mapRelation.containsKey(key)) {
143 // Such a key (first element) exists already
144 hsSecond = mapRelation.get(key);
146 // It is a new key ...
147 hsSecond = new HashSet<V>();
148 mapRelation.put(key, hsSecond);
151 // Go to our Set of objects
152 if (hsSecond.contains(value)) {
153 // This object exists
156 // This is a new object