BdioContext { public Object fromFieldValue(String term, @Nullable Object input) { return _fromFieldValue(term, input).collect(valueMapper.getCollector(context.getContainer(term))); } 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 fromFieldValue_identifier() { BdioContext context = DEFAULT_CONTEXT; assertThat(context.fromFieldValue("test", ImmutableMap.of("@id", "test"))).isEqualTo("test"); assertThat(context.fromFieldValue("test", ImmutableMap.of("@id", "test", "foo", "bar"))).isEqualTo(ImmutableMap.of("@id", "test", "foo", "bar")); }
@Test public void fromFieldValue_primitive() { BdioContext context = DEFAULT_CONTEXT; assertThat(context.fromFieldValue("test", ImmutableMap.of("@value", "test"))).isEqualTo("test"); assertThat(context.fromFieldValue("test", ImmutableMap.of("@value", Boolean.TRUE))).isEqualTo(Boolean.TRUE); assertThat(context.fromFieldValue("test", ImmutableMap.of("@value", Integer.valueOf(1)))).isEqualTo(Integer.valueOf(1)); }
@Test public void fromFieldValue_dateTime() { BdioContext context = DEFAULT_CONTEXT; ZonedDateTime zoned = ZonedDateTime.now(ZoneId.systemDefault()); assertThat(context.fromFieldValue("test", ImmutableMap.of("@type", Bdio.Datatype.DateTime.toString(), "@value", zoned.toString()))) .named("zoned").isEqualTo(zoned); OffsetDateTime offset = OffsetDateTime.now(ZoneId.systemDefault()); assertThat(context.fromFieldValue("test", ImmutableMap.of("@type", Bdio.Datatype.DateTime.toString(), "@value", offset.toString()))) .named("offset").isEqualTo(offset.toZonedDateTime()); Instant instant = Instant.now(); assertThat(context.fromFieldValue("test", ImmutableMap.of("@type", Bdio.Datatype.DateTime.toString(), "@value", instant.toString()))) .named("instant").isEqualTo(instant.atZone(ZoneOffset.UTC)); Date date = new Date(); assertThat(context.fromFieldValue("test", ImmutableMap.of("@type", Bdio.Datatype.DateTime.toString(), "@value", date))) .named("date").isEqualTo(date.toInstant().atZone(ZoneOffset.UTC)); }
@Test public void fromFieldValue_multiValueKey() { String exampleContext = "{\"@context\":{\"@vocab\":\"http: BdioContext context = new BdioContext.Builder() .injectDocument("http: .expandContext("http: .build(); assertThat(context.fromFieldValue("test", ImmutableList.of("foobar"))).isEqualTo("foobar"); assertThat(context.fromFieldValue("test2", ImmutableList.of("foobar"))).isEqualTo(ImmutableList.of("foobar")); assertThat(context.fromFieldValue("test2", "foobar")).isEqualTo(ImmutableList.of("foobar")); }
@Test public void fromFieldValue_multiValueCollector_stringArray() { String exampleContext = "{\"@context\":{\"@vocab\":\"http: BdioContext context = new BdioContext.Builder() .injectDocument("http: .expandContext("http: .valueMapper(new StandardJavaValueMapper() { @Override public Collector<? super Object, ?, ?> getCollector(String container) { return collectingAndThen(mapping(o -> Objects.toString(o, null), toList()), l -> l.stream().allMatch(Objects::isNull) ? null : l.toArray(new String[l.size()])); } }) .build(); assertThat((String[]) context.fromFieldValue("test2", ImmutableList.of("foobar"))).isEqualTo(new String[] { "foobar" }); assertThat((String[]) context.fromFieldValue("test2", Arrays.asList((String) null))).isNull(); }
@Test public void fromFieldValue_singleValueFromMultipleNull() { BdioContext context = new BdioContext.Builder().build(); assertThat(context.fromFieldValue("test", Arrays.asList(null, null))).isNull(); }