Adding last version of iotruntime and iotinstaller; preparing to extend IoTMaster...
[iot2.git] / iotjava / iotruntime / slave / IoTRelation.java
1 package iotruntime.slave;
2
3 import java.lang.UnsupportedOperationException;
4
5 import java.util.HashMap;
6 import java.util.HashSet;
7 import java.util.Map;
8 import java.util.Set;
9
10
11 /** Class IoTRelation is the actual implementation of @config IoTRelation<...>.
12  *  Upon extracting DB information, RelationInstrumenter class will use
13  *  this class to actually instantiate the Map as IoTRelation uses a
14  *  combination between a HashMap and a IoTSet; we don't provide interfaces
15  *  to modify the contents, but we do provide means to read them out.
16  *  The add method is just used the first time it is needed to add new objects,
17  *  then it is going to be made immutable
18  *
19  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
20  * @version     1.0
21  * @since       2015-12-01
22  */
23 public final class IoTRelation<K, V> {
24
25         /**
26          * Reference to an object Map<T>
27          */
28         private Map<K,HashSet<V> > mapRelation;
29         private int iSize;
30
31         /**
32          * Class constructor (pass the reference to this immutable wrapper)
33          */
34         protected IoTRelation(Map<K,HashSet<V>> mapRel, int _iSize) {
35                 mapRelation = mapRel;
36                 iSize = _iSize;
37         }
38
39         /**
40          * Method containsKey() inherited from Map interface
41          *
42          * @param  key  The first Object that is usually a key in a Map
43          * @return      boolean
44          */
45         public boolean containsKey(K key) {
46
47                 return mapRelation.containsKey(key);
48
49         }
50
51         /**
52          * Method entrySet() inherited from Map interface
53          *
54          * @return      Set<Map.Entry<K,HashSet<V>>>
55          */
56         public Set<Map.Entry<K,HashSet<V>>> entrySet() {
57
58                 return new HashSet<Map.Entry<K,HashSet<V>>>(mapRelation.entrySet());
59
60         }
61
62         /**
63          * Method keySet() inherited from Map interface
64          *
65          * @return      Set<K>
66          */
67         public Set<K> keySet() {
68
69                 return new HashSet<K>(mapRelation.keySet());
70
71         }
72
73         /**
74          * Method get() inherited from Map interface
75          *
76          * @param  key  The first Object that is usually a key in a Map
77          * @return      HashSet<V>
78          */
79         public HashSet<V> get(K key) {
80
81                 return new HashSet<V>(mapRelation.get(key));
82
83         }
84
85         /**
86          * Method isEmpty() inherited from Map interface
87          *
88          * @return      boolean
89          */
90         public boolean isEmpty() {
91
92                 return mapRelation.isEmpty();
93
94         }
95
96         /**
97          * size() method
98          *
99          * @return      int
100          */
101         public int size() {
102
103                 return this.iSize;
104
105         }
106 }