@Test public void testAsString() throws ProvidenceConfigException { assertThat(asString(55.5), is("55.5")); assertThat(asString(new StringBuilder("123345")), is("123345")); assertThat(asString((Stringable) () -> "foo"), is("foo")); assertThat(asString(new Date(1234567890000L)), is("2009-02-13T23:31:30Z")); assertThat(asString(new Object() { @Override public String toString() { return "bar"; } }), is("bar")); assertThat(asString(null), is("null")); try { asString(Collections.EMPTY_LIST); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert EmptyList to a string")); } }
static String asString(Object value) throws ProvidenceConfigException { if (value instanceof Collection || value instanceof Map) { throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a string"); } else if (value instanceof Stringable) { return ((Stringable) value).asString(); } else if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); return DateTimeFormatter.ISO_INSTANT.format(instant); } return Objects.toString(value); }
ProvidenceConfigUtil { static String asString(Object value) throws ProvidenceConfigException { if (value instanceof Collection || value instanceof Map) { throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a string"); } else if (value instanceof Stringable) { return ((Stringable) value).asString(); } else if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); return DateTimeFormatter.ISO_INSTANT.format(instant); } return Objects.toString(value); } }
ProvidenceConfigUtil { static String asString(Object value) throws ProvidenceConfigException { if (value instanceof Collection || value instanceof Map) { throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a string"); } else if (value instanceof Stringable) { return ((Stringable) value).asString(); } else if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); return DateTimeFormatter.ISO_INSTANT.format(instant); } return Objects.toString(value); } private  ProvidenceConfigUtil(); }
ProvidenceConfigUtil { static String asString(Object value) throws ProvidenceConfigException { if (value instanceof Collection || value instanceof Map) { throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a string"); } else if (value instanceof Stringable) { return ((Stringable) value).asString(); } else if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); return DateTimeFormatter.ISO_INSTANT.format(instant); } return Objects.toString(value); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); }
ProvidenceConfigUtil { static String asString(Object value) throws ProvidenceConfigException { if (value instanceof Collection || value instanceof Map) { throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a string"); } else if (value instanceof Stringable) { return ((Stringable) value).asString(); } else if (value instanceof Date) { Instant instant = ((Date) value).toInstant(); return DateTimeFormatter.ISO_INSTANT.format(instant); } return Objects.toString(value); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); static final String UNDEFINED; }