1515 */
1616package com .apicatalog .cborld .context ;
1717
18+ import java .io .IOException ;
1819import java .net .URI ;
1920import java .util .Collection ;
2021import java .util .Iterator ;
21- import java .util .Map .Entry ;
2222import java .util .Optional ;
2323import java .util .function .Consumer ;
2424
2525import com .apicatalog .cborld .mapping .TypeKeyNameMapper ;
2626import com .apicatalog .jsonld .JsonLdError ;
27+ import com .apicatalog .jsonld .JsonLdErrorCode ;
2728import com .apicatalog .jsonld .context .ActiveContext ;
2829import com .apicatalog .jsonld .context .TermDefinition ;
2930import com .apicatalog .jsonld .json .JsonUtils ;
3031import com .apicatalog .jsonld .lang .Keywords ;
3132import com .apicatalog .tree .io .JakartaMaterializer ;
3233import com .apicatalog .tree .io .NodeAdapter ;
33- import com .apicatalog .tree .io .NodeModel ;
3434
3535import 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 )
0 commit comments