Skip to content

Commit 977f300

Browse files
committed
Adopt tree-io 0.9.1
1 parent dd5abac commit 977f300

File tree

8 files changed

+42
-344
lines changed

8 files changed

+42
-344
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5858

59-
<tree.version>0.8.0-SNAPSHOT</tree.version>
59+
<tree.version>0.9.1</tree.version>
6060
<jakarta.json.version>2.0.1</jakarta.json.version>
6161

6262
<copper-multibase>4.1.0</copper-multibase>

src/main/java/com/apicatalog/cborld/context/Expansion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected JsonValue compute() throws JsonLdError {
9191
return JsonValue.NULL;
9292
}
9393

94-
final NodeType dataType = adapter.typeOf(element);
94+
final NodeType dataType = adapter.type(element);
9595

9696
// 5. If element is an array,
9797
if (NodeType.COLLECTION == dataType) {

src/main/java/com/apicatalog/cborld/context/ObjectExpansion.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
*/
1616
package com.apicatalog.cborld.context;
1717

18+
import java.io.IOException;
1819
import java.net.URI;
1920
import java.util.Collection;
2021
import java.util.Iterator;
21-
import java.util.Map.Entry;
2222
import java.util.Optional;
2323
import java.util.function.Consumer;
2424

2525
import com.apicatalog.cborld.mapping.TypeKeyNameMapper;
2626
import com.apicatalog.jsonld.JsonLdError;
27+
import com.apicatalog.jsonld.JsonLdErrorCode;
2728
import com.apicatalog.jsonld.context.ActiveContext;
2829
import com.apicatalog.jsonld.context.TermDefinition;
2930
import com.apicatalog.jsonld.json.JsonUtils;
3031
import com.apicatalog.jsonld.lang.Keywords;
3132
import com.apicatalog.tree.io.JakartaMaterializer;
3233
import com.apicatalog.tree.io.NodeAdapter;
33-
import com.apicatalog.tree.io.NodeModel;
3434

3535
import jakarta.json.JsonValue;
3636

@@ -99,7 +99,11 @@ public JsonValue expand() throws JsonLdError {
9999

100100
initPropertyContext();
101101

102-
initLocalContext();
102+
try {
103+
initLocalContext();
104+
} catch (IOException e) {
105+
throw new JsonLdError(JsonLdErrorCode.UNSPECIFIED, e);
106+
}
103107

104108
// 10.
105109
final ActiveContext typeContext = activeContext;
@@ -151,18 +155,20 @@ private void initPreviousContext() throws JsonLdError {
151155

152156
boolean revert = true;
153157

154-
final Iterator<Entry<?, ?>> entries = adapter.propertyStream(element)
155-
.sorted(NodeModel.comparingEntry(e -> adapter.asString(e.getKey())))
158+
final Iterator<String> keys = adapter.keys(element)
159+
.stream()
160+
.map(adapter::asString)
161+
.sorted()
156162
.iterator();
157163

158-
while (entries.hasNext()) {
164+
while (keys.hasNext()) {
159165

160-
final Entry<?, ?> entry = entries.next();
166+
final String key = keys.next();
161167

162168
final String expandedKey = UriExpansion
163169
.with(activeContext, appliedContexts)
164170
.vocab(true)
165-
.expand(adapter.asString(entry.getKey()));
171+
.expand(adapter.asString(key));
166172

167173
if (Keywords.VALUE.equals(expandedKey) || (Keywords.ID.equals(expandedKey) && (adapter.size(element) == 1))) {
168174
revert = false;
@@ -176,7 +182,7 @@ private void initPreviousContext() throws JsonLdError {
176182
}
177183
}
178184

179-
private void initLocalContext() throws JsonLdError {
185+
private void initLocalContext() throws JsonLdError, IOException {
180186

181187
// 9.
182188
final Object contextElement = adapter.property(Keywords.CONTEXT, element);
@@ -208,15 +214,15 @@ private String processTypeScoped(final ActiveContext typeContext) throws JsonLdE
208214

209215
String typeKey = null;
210216

211-
final Iterator<Entry<?, ?>> entries = adapter.propertyStream(element)
212-
.sorted(NodeModel.comparingEntry(e -> adapter.asString(e.getKey())))
217+
final Iterator<String> keys = adapter.keys(element)
218+
.stream()
219+
.map(adapter::asString)
220+
.sorted()
213221
.iterator();
214222

215-
while (entries.hasNext()) {
216-
217-
final Entry<?, ?> entry = entries.next();
223+
while (keys.hasNext()) {
218224

219-
final String key = adapter.asString(entry.getKey());
225+
final String key = keys.next();
220226

221227
final String expandedKey = UriExpansion
222228
.with(activeContext, appliedContexts)
@@ -234,7 +240,7 @@ private String processTypeScoped(final ActiveContext typeContext) throws JsonLdE
234240
typeMapper.typeKeyName(key);
235241
}
236242

237-
final Object value = entry.getValue();// adapter.property(key, element);
243+
final Object value = adapter.property(key, element);
238244

239245
// 11.2
240246
final Iterator<String> terms = adapter.asStream(value)

src/main/java/com/apicatalog/cborld/context/ObjectExpansion1314.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121
import java.util.Iterator;
22-
import java.util.Map.Entry;
2322
import java.util.Optional;
2423
import java.util.function.Consumer;
2524

@@ -33,7 +32,6 @@
3332
import com.apicatalog.jsonld.lang.ListObject;
3433
import com.apicatalog.jsonld.lang.ValueObject;
3534
import com.apicatalog.tree.io.NodeAdapter;
36-
import com.apicatalog.tree.io.NodeModel;
3735
import com.apicatalog.tree.io.NodeType;
3836

3937
import jakarta.json.Json;
@@ -106,17 +104,15 @@ public void expand() throws JsonLdError {
106104
return;
107105
}
108106

109-
final Iterator<Entry<?, ?>> entries = adapter.propertyStream(element)
110-
.sorted(ordered
111-
? NodeModel.comparingEntry(e -> adapter.asString(e.getKey()))
112-
: (a, b) -> 0
113-
)
107+
final Iterator<String> keys = adapter.keys(element)
108+
.stream()
109+
.map(adapter::asString)
110+
.sorted()
114111
.iterator();
115112

116-
while (entries.hasNext()) {
113+
while (keys.hasNext()) {
117114

118-
final Entry<?, ?> entry = entries.next();
119-
final String key = adapter.asString(entry.getKey());
115+
final String key = keys.next();
120116

121117
// 13.1.
122118
if (Keywords.CONTEXT.equals(key)) {
@@ -135,15 +131,17 @@ public void expand() throws JsonLdError {
135131
continue;
136132
}
137133

138-
final NodeType valueType = adapter.typeOf(entry.getValue());
134+
final Object value = adapter.property(key, element);
135+
136+
final NodeType valueType = adapter.type(value);
139137

140138
// 13.4. If expanded property is a keyword:
141139
if (Keywords.contains(expandedProperty)) {
142140

143141
JsonValue expandedType = null;
144142

145143
if (NodeType.STRING == valueType) {
146-
expandedType = Json.createValue(adapter.stringValue(entry.getValue()));
144+
expandedType = Json.createValue(adapter.stringValue(value));
147145
}
148146

149147
// 13.4.1
@@ -177,7 +175,7 @@ else if (Keywords.INCLUDED.equals(expandedProperty)) {
177175
}
178176

179177
expandedType = Expansion
180-
.with(activeContext, entry.getValue(), adapter, null, baseUrl, appliedContexts, typeMapper)
178+
.with(activeContext, value, adapter, null, baseUrl, appliedContexts, typeMapper)
181179
.ordered(ordered)
182180
.compute();
183181
}
@@ -236,7 +234,7 @@ else if (Keywords.INCLUDED.equals(expandedProperty)) {
236234
// 13.9.
237235
} else {
238236
expandedType = Expansion
239-
.with(activeContext, entry.getValue(), adapter, key, baseUrl, appliedContexts, typeMapper)
237+
.with(activeContext, value, adapter, key, baseUrl, appliedContexts, typeMapper)
240238
.ordered(ordered)
241239
.compute();
242240
}

0 commit comments

Comments
 (0)