11
11
import com .jayway .jsonpath .JsonPath ;
12
12
import com .jayway .jsonpath .PathNotFoundException ;
13
13
import com .yetanalytics .xapi .model .deserializers .ExtensionDeserializer ;
14
- import com .yetanalytics .xapi .model .serializers .ExtensionSerializer ;
14
+ import com .yetanalytics .xapi .model .serializers .FreeMapSerializer ;
15
15
import com .yetanalytics .xapi .util .Mapper ;
16
16
17
17
/**
22
22
* or through a JSONPath API.
23
23
*/
24
24
@ JsonDeserialize (using = ExtensionDeserializer .class )
25
- @ JsonSerialize (using = ExtensionSerializer .class )
26
- public class Extensions {
25
+ @ JsonSerialize (using = FreeMapSerializer .class )
26
+ public class Extensions implements IFreeMap < URI , Object > {
27
27
28
28
private Map <URI , Object > extMap = new HashMap <>();
29
29
@@ -33,25 +33,49 @@ public Extensions(Map<URI, Object> input) {
33
33
34
34
/**
35
35
* Sets an entry in the Extensions Map
36
- * @param key the IRI key of the extension
36
+ * @param key the URI key of the extension
37
37
* @param value The Collections API representation of the JSON Data
38
38
*/
39
+ @ Override
39
40
public void put (URI key , Object value ) {
40
41
extMap .put (key , value );
41
42
}
42
43
44
+ /**
45
+ * Sets an entry in the Extensions Map
46
+ * @param key the IRI String key of the extension
47
+ * @param value The Collections API representation of the JSON Data
48
+ * @throws IllegalArgumentException
49
+ */
50
+ @ Override
51
+ public void put (String key , Object value ) throws IllegalArgumentException {
52
+ put (URI .create (key ), value );
53
+ }
54
+
43
55
/**
44
56
* Retrieve extension data
45
- * @param key The IRI of the extension
57
+ * @param key The URI key of the extension
46
58
* @return The Collections API representation of the JSON Data
47
59
*/
60
+ @ Override
48
61
public Object get (URI key ) {
49
62
return extMap .get (key );
50
63
}
51
64
65
+ /**
66
+ * Retrieve extension data
67
+ * @param key The IRI string key of the extension
68
+ * @return The Collections API representation of the JSON Data
69
+ * @throws IllegalArgumentException
70
+ */
71
+ @ Override
72
+ public Object get (String key ) throws IllegalArgumentException {
73
+ return get (URI .create (key ));
74
+ }
75
+
52
76
/**
53
77
* Attempt a JSONPath query of the Extension data.
54
- * @param key The IRI key of the extension in which to perform the query
78
+ * @param key The URI key of the extension in which to perform the query
55
79
* @param jsonPathExpression A JSONPath query to perform in the Extension data
56
80
* @param typeKey The typereference for the type that the query is expecting to retrieve
57
81
* @param <T> The type that the query is expecting to convert the results to
@@ -73,25 +97,52 @@ public <T> T read(URI key, String jsonPathExpression, Class<T> typeKey) {
73
97
return null ;
74
98
}
75
99
100
+ /**
101
+ * Attempt a JSONPath query of the Extension data.
102
+ * @param key The IRI String key of the extension in which to perform the query
103
+ * @param jsonPathExpression A JSONPath query to perform in the Extension data
104
+ * @param typeKey The typereference for the type that the query is expecting to retrieve
105
+ * @param <T> The type that the query is expecting to convert the results to
106
+ * @return Object of type T that is the result of deserialization from the query
107
+ * @throws IllegalArgumentException
108
+ */
109
+ public <T > T read (String key , String jsonPathExpression , Class <T > typeKey ) throws IllegalArgumentException {
110
+ return read (URI .create (key ), jsonPathExpression , typeKey );
111
+ }
112
+
76
113
/**
77
114
* Remove an extension by IRI key
78
- * @param key the IRI of the extension to remove
115
+ * @param key the URI key of the extension to remove
79
116
*/
117
+ @ Override
80
118
public void remove (URI key ) {
81
119
extMap .remove (key );
82
120
}
83
121
122
+ /**
123
+ * Remove an extension by IRI key
124
+ * @param key the IRI String key of the extension to remove
125
+ * @throws IllegalArgumentException
126
+ */
127
+ @ Override
128
+ public void remove (String key ) throws IllegalArgumentException {
129
+ remove (URI .create (key ));
130
+ }
131
+
84
132
/**
85
133
* Returns a set of all IRI Extension keys
86
134
* @return Set of IRI keys
87
135
*/
136
+ @ Override
88
137
public Set <URI > getKeys () {
89
138
return extMap .keySet ();
90
139
}
140
+
91
141
/**
92
142
* Returns the full raw Extension Map as a HashMap<URI, Object>
93
143
* @return The raw Extensions Map
94
144
*/
145
+ @ Override
95
146
public Map <URI , Object > getMap () {
96
147
return extMap ;
97
148
}
0 commit comments