Skip to content

Commit e953c7c

Browse files
committed
Minor documentation and variable naming changes
1 parent b784f3f commit e953c7c

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

core/src/main/java/com/github/jsonldjava/core/JsonLdProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ public static Map<String, Object> frame(Object input, Object frame, JsonLdOption
342342
return rval;
343343
}
344344

345+
/**
346+
* Builds the context to be returned in framing and compaction algorithms.
347+
* In cases where the context is empty or from an unexpected type, it returns null.
348+
* When JsonLdOptions compactArrays is set to true and the context contains a List with a single element,
349+
* the element is returned instead of the list
350+
*/
345351
private static Object returnedContext(Object context, JsonLdOptions opts) {
346352
if (context != null &&
347353
((context instanceof Map && !((Map<String, Object>) context).isEmpty())

core/src/test/java/com/github/jsonldjava/core/ContextFramingTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public class ContextFramingTest {
1717
@Test
1818
public void testFraming() throws Exception {
1919

20-
final Map<String, Object> contextAbbrevs = new HashMap<String, Object>();
20+
final Map<String, Object> contextAbbrevs = new HashMap<>();
2121
contextAbbrevs.put("so", "http://schema.org/");
2222

23-
final Map<String, Object> json = new HashMap<String, Object>();
23+
final Map<String, Object> json = new HashMap<>();
2424
json.put("@context", contextAbbrevs);
2525
json.put("@id", "http://example.org/my_work");
2626

27-
final List<Object> types = new LinkedList<Object>();
27+
final List<Object> types = new LinkedList<>();
2828
types.add("so:CreativeWork");
2929

3030
json.put("@type", types);
@@ -36,20 +36,20 @@ public void testFraming() throws Exception {
3636
options.setCompactArrays(true);
3737
options.setOmitGraph(true);
3838

39-
// System.out.println("Before compact");
39+
// System.out.println("Before framing");
4040
// System.out.println(JsonUtils.toPrettyString(json));
4141

4242
final String frameStr = "{\"@id\": \"http://schema.org/myid\", \"@context\": \"http://schema.org/\"}";
4343
final Object frame = JsonUtils.fromString(frameStr);
4444

45-
final Map<String, Object> compacted = JsonLdProcessor.frame(json, frame, options);
45+
final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);
4646

47-
// System.out.println("\n\nAfter compact:");
48-
// System.out.println(JsonUtils.toPrettyString(compacted));
47+
// System.out.println("\n\nAfter framing:");
48+
// System.out.println(JsonUtils.toPrettyString(framed));
4949

50-
assertTrue("Framing removed the context", compacted.containsKey("@context"));
50+
assertTrue("Framing removed the context", framed.containsKey("@context"));
5151
assertFalse("Framing of context should be a string, not a list",
52-
compacted.get("@context") instanceof List);
52+
framed.get("@context") instanceof List);
5353
}
5454

5555
@Test
@@ -63,15 +63,15 @@ public void testFramingRemoteContext() throws Exception {
6363
final JsonLdOptions options = new JsonLdOptions();
6464
options.setOmitGraph(true);
6565

66-
final Map<String, Object> compacted = JsonLdProcessor.frame(json, frame, options);
66+
final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);
6767

68-
// System.out.println("\n\nAfter compact:");
69-
// System.out.println(JsonUtils.toPrettyString(compacted));
68+
// System.out.println("\n\nAfter framing:");
69+
// System.out.println(JsonUtils.toPrettyString(framed));
7070

71-
assertEquals("Wrong framing context", "http://schema.org/", compacted.get("@context"));
72-
assertEquals("Wrong framing id", "schema:myid", compacted.get("id"));
73-
assertEquals("Wrong framing type", "Person", compacted.get("type"));
74-
assertEquals("Wrong number of Json entries",3, compacted.size());
71+
assertEquals("Wrong framing context", "http://schema.org/", framed.get("@context"));
72+
assertEquals("Wrong framing id", "schema:myid", framed.get("id"));
73+
assertEquals("Wrong framing type", "Person", framed.get("type"));
74+
assertEquals("Wrong number of Json entries",3, framed.size());
7575
}
7676

7777
}

0 commit comments

Comments
 (0)