@Test void testToLiteralMap() { Map<String, Literal> literalMap = AutoValueReflection.toLiteralMap( AutoValueInput.create( 42L, 42.0d, "42", false, Instant.ofEpochSecond(42, 1), Duration.ofSeconds(1, 42), singletonList("foo"), singletonMap("marco", "polo")), AutoValueInput.class); assertThat(literalMap.size(), is(8)); assertThat(literalMap.get("i"), matchesLiteralInteger(is(42L))); assertThat(literalMap.get("f"), matchesLiteralFloat(is(42.0))); assertThat(literalMap.get("s"), matchesLiteralString(is("42"))); assertThat(literalMap.get("b"), matchesLiteralBoolean(is(false))); assertThat(literalMap.get("t"), matchesLiteralDatetime(is(Instant.ofEpochSecond(42, 1)))); assertThat(literalMap.get("d"), matchesLiteralDuration(is(Duration.ofSeconds(1, 42)))); requireNonNull(literalMap.get("l").collection()) .forEach(elem -> assertThat(elem, matchesLiteralString(is("foo")))); requireNonNull(literalMap.get("m").map()) .forEach( (name, value) -> { assertThat(name, is("marco")); assertThat(value, matchesLiteralString(is("polo"))); }); }
static <T> Map<String, Literal> toLiteralMap(T object, Class<T> cls) { return interfaceOf(cls).entrySet().stream() .map( entry -> { Object value = getVariableValue(entry.getKey(), object, cls); Literal literal = value != null ? toLiteral(value, entry.getValue().literalType()) : null; return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), literal); }) .filter(entry -> entry.getValue() != null) .collect( collectingAndThen( toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); }
AutoValueReflection { static <T> Map<String, Literal> toLiteralMap(T object, Class<T> cls) { return interfaceOf(cls).entrySet().stream() .map( entry -> { Object value = getVariableValue(entry.getKey(), object, cls); Literal literal = value != null ? toLiteral(value, entry.getValue().literalType()) : null; return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), literal); }) .filter(entry -> entry.getValue() != null) .collect( collectingAndThen( toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); } }
AutoValueReflection { static <T> Map<String, Literal> toLiteralMap(T object, Class<T> cls) { return interfaceOf(cls).entrySet().stream() .map( entry -> { Object value = getVariableValue(entry.getKey(), object, cls); Literal literal = value != null ? toLiteral(value, entry.getValue().literalType()) : null; return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), literal); }) .filter(entry -> entry.getValue() != null) .collect( collectingAndThen( toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); } private  AutoValueReflection(); }
AutoValueReflection { static <T> Map<String, Literal> toLiteralMap(T object, Class<T> cls) { return interfaceOf(cls).entrySet().stream() .map( entry -> { Object value = getVariableValue(entry.getKey(), object, cls); Literal literal = value != null ? toLiteral(value, entry.getValue().literalType()) : null; return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), literal); }) .filter(entry -> entry.getValue() != null) .collect( collectingAndThen( toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); } private  AutoValueReflection();  }
AutoValueReflection { static <T> Map<String, Literal> toLiteralMap(T object, Class<T> cls) { return interfaceOf(cls).entrySet().stream() .map( entry -> { Object value = getVariableValue(entry.getKey(), object, cls); Literal literal = value != null ? toLiteral(value, entry.getValue().literalType()) : null; return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), literal); }) .filter(entry -> entry.getValue() != null) .collect( collectingAndThen( toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap)); } private  AutoValueReflection();   }