@Test public void testAsLong() throws ProvidenceConfigException { assertThat(asLong(2.0f), is(2L)); assertThat(asLong((byte) 2), is(2L)); assertThat(asLong((Numeric) () -> 55), is(55L)); assertThat(asLong(false), is(0L)); assertThat(asLong(true), is(1L)); try { asLong(2.2); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Truncating long decimals from 2.2")); } try { asLong("foo"); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert String to a long")); } try { asLong(new Object()); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert Object to a long")); } }
static long asLong(Object value) throws ProvidenceConfigException { if (value instanceof Float || value instanceof Double) { long l = ((Number) value).longValue(); if ((double) l != ((Number) value).doubleValue()) { throw new ProvidenceConfigException("Truncating long decimals from " + value.toString()); } return l; } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof Numeric) { return ((Numeric) value).asInteger(); } else if (value instanceof Boolean) { return ((Boolean) value) ? 1L : 0L; } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a long"); }
ProvidenceConfigUtil { static long asLong(Object value) throws ProvidenceConfigException { if (value instanceof Float || value instanceof Double) { long l = ((Number) value).longValue(); if ((double) l != ((Number) value).doubleValue()) { throw new ProvidenceConfigException("Truncating long decimals from " + value.toString()); } return l; } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof Numeric) { return ((Numeric) value).asInteger(); } else if (value instanceof Boolean) { return ((Boolean) value) ? 1L : 0L; } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a long"); } }
ProvidenceConfigUtil { static long asLong(Object value) throws ProvidenceConfigException { if (value instanceof Float || value instanceof Double) { long l = ((Number) value).longValue(); if ((double) l != ((Number) value).doubleValue()) { throw new ProvidenceConfigException("Truncating long decimals from " + value.toString()); } return l; } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof Numeric) { return ((Numeric) value).asInteger(); } else if (value instanceof Boolean) { return ((Boolean) value) ? 1L : 0L; } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a long"); } private  ProvidenceConfigUtil(); }
ProvidenceConfigUtil { static long asLong(Object value) throws ProvidenceConfigException { if (value instanceof Float || value instanceof Double) { long l = ((Number) value).longValue(); if ((double) l != ((Number) value).doubleValue()) { throw new ProvidenceConfigException("Truncating long decimals from " + value.toString()); } return l; } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof Numeric) { return ((Numeric) value).asInteger(); } else if (value instanceof Boolean) { return ((Boolean) value) ? 1L : 0L; } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a long"); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); }
ProvidenceConfigUtil { static long asLong(Object value) throws ProvidenceConfigException { if (value instanceof Float || value instanceof Double) { long l = ((Number) value).longValue(); if ((double) l != ((Number) value).doubleValue()) { throw new ProvidenceConfigException("Truncating long decimals from " + value.toString()); } return l; } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof Numeric) { return ((Numeric) value).asInteger(); } else if (value instanceof Boolean) { return ((Boolean) value) ? 1L : 0L; } throw new ProvidenceConfigException("Unable to convert " + value.getClass().getSimpleName() + " to a long"); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); static final String UNDEFINED; }