BdioContext { public Object putFieldValue(Map<String, Object> map, Object field, @Nullable Object value) { String key = field.toString(); if (value == null) { return map.computeIfPresent(key, this::computeFieldValueIfPresent); } else if (map.containsKey(key)) { return map.merge(key, value, mergeFieldValue(key)); } else { return map.put(key, toFieldValue(term(key), value)); } } private  BdioContext(Builder builder); static BdioContext getDefault(); JsonLdOptions jsonLdOptions(); Object fromFieldValue(String term, @Nullable Object input); Object toFieldValue(String term, @Nullable Object input); boolean isEmbedded(@Nullable Object type); Optional<String> lookupTerm(String iri); Stream<?> getFieldValue(Object field, Map<?, ?> values); Object putFieldValue(Map<String, Object> map, Object field, @Nullable Object value); Builder newBuilder();  }
@Test public void putDefaultTypeDataProperty() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.name, "foobar"); assertThat(map).containsEntry(Bdio.DataProperty.name.toString(), "foobar"); }
@Test public void putSingleDataProperty() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.name, "foo"); assertThat(context.putFieldValue(map, Bdio.DataProperty.name, "bar")).isEqualTo("bar"); assertThat(map).containsEntry(Bdio.DataProperty.name.toString(), "bar"); }
@Test public void putSingleDataPropertyNullValue() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.name, "foo"); assertThat(context.putFieldValue(map, Bdio.DataProperty.name, null)).isNull(); assertThat(map).doesNotContainKey(Bdio.DataProperty.name.toString()); }
@Test public void putMultivaluedDataProperty() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.fingerprint, new Digest.Builder().algorithm("test").value("123").build()); context.putFieldValue(map, Bdio.DataProperty.fingerprint, new Digest.Builder().algorithm("test").value("456").build()); context.putFieldValue(map, Bdio.DataProperty.fingerprint, new Digest.Builder().algorithm("test").value("789").build()); assertThat(map.get(Bdio.DataProperty.fingerprint.toString())).isInstanceOf(List.class); assertThat((List<?>) map.get(Bdio.DataProperty.fingerprint.toString())).containsExactly( ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:123"), ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:456"), ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:789")); }
@Test public void putMultivaluedDataPropertyNullValue() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.fingerprint, new Digest.Builder().algorithm("test").value("123").build()); context.putFieldValue(map, Bdio.DataProperty.fingerprint, null); assertThat((List<?>) map.get(Bdio.DataProperty.fingerprint.toString())).containsExactly( ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:123")); context.putFieldValue(map, Bdio.DataProperty.fingerprint, new Digest.Builder().algorithm("test").value("456").build()); context.putFieldValue(map, Bdio.DataProperty.fingerprint, null); assertThat((List<?>) map.get(Bdio.DataProperty.fingerprint.toString())).containsExactly( ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:123"), ImmutableMap.of("@type", Bdio.Datatype.Digest.toString(), "@value", "test:456")); }
@Test public void putDateTimeTypeDataProperty() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault()); context.putFieldValue(map, Bdio.DataProperty.creationDateTime, now); assertThat(map).containsEntry(Bdio.DataProperty.creationDateTime.toString(), ImmutableMap.of("@type", Bdio.Datatype.DateTime.toString(), "@value", now.toString())); }
@Test public void putLongTypeDataProperty() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.DataProperty.byteCount, 1L); assertThat(map).containsEntry(Bdio.DataProperty.byteCount.toString(), ImmutableMap.of("@type", Bdio.Datatype.Long.toString(), "@value", 1L)); }
@Test public void putSingleObjectProperty() { BdioContext context = DEFAULT_CONTEXT; String currentVersionId = BdioObject.randomId(); Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.ObjectProperty.parent, currentVersionId); assertThat(map).containsEntry(Bdio.ObjectProperty.parent.toString(), ImmutableMap.of("@id", currentVersionId)); }
@Test public void putSingleObjectPropertyNullValue() { BdioContext context = DEFAULT_CONTEXT; Map<String, Object> map = new LinkedHashMap<>(); context.putFieldValue(map, Bdio.ObjectProperty.parent, BdioObject.randomId()); assertThat(context.putFieldValue(map, Bdio.ObjectProperty.parent, null)).isNull(); assertThat(map).doesNotContainKey(Bdio.ObjectProperty.parent.toString()); }