DisplayData implements Serializable { @Override public String toString() { StringBuilder builder = new StringBuilder(); boolean isFirstLine = true; for (Item entry : entries.values()) { if (isFirstLine) { isFirstLine = false; } else { builder.append("\n"); } builder.append(entry); } return builder.toString(); } private  DisplayData(Map<Identifier, Item> entries); static DisplayData none(); static DisplayData from(HasDisplayData component); static @Nullable Type inferType(@Nullable Object value); @JsonValue Collection<Item> items(); Map<Identifier, Item> asMap(); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); @Override String toString(); static ItemSpec<String> item(String key, @Nullable String value); static ItemSpec<?> item(String key, @Nullable ValueProvider<?> value); static ItemSpec<Integer> item(String key, @Nullable Integer value); static ItemSpec<Long> item(String key, @Nullable Long value); static ItemSpec<Float> item(String key, @Nullable Float value); static ItemSpec<Double> item(String key, @Nullable Double value); static ItemSpec<Boolean> item(String key, @Nullable Boolean value); static ItemSpec<Instant> item(String key, @Nullable Instant value); static ItemSpec<Duration> item(String key, @Nullable Duration value); static ItemSpec<Class<T>> item(String key, @Nullable Class<T> value); static ItemSpec<T> item(String key, Type type, @Nullable T value);  }
@Test public void testPathToString() { assertEquals("root string", "[]", DisplayData.Path.root().toString()); assertEquals("single component", "[a]", DisplayData.Path.absolute("a").toString()); assertEquals("hierarchy", "[a/b/c]", DisplayData.Path.absolute("a", "b", "c").toString()); }
@Test public void testToString() { HasDisplayData component = new HasDisplayData() { @Override public void populateDisplayData(DisplayData.Builder builder) { builder.add(DisplayData.item("foo", "bar")); } }; DisplayData data = DisplayData.from(component); assertEquals(String.format("[]%s:foo=bar", component.getClass().getName()), data.toString()); }