@Test public void testAsCollection() throws ProvidenceConfigException { assertThat(asCollection(new LinkedList<>(), PPrimitive.STRING), is(instanceOf(ArrayList.class))); assertThat(asCollection(ImmutableSet.of(1, 2, 3), PPrimitive.STRING), is(containsInAnyOrder("1", "2", "3"))); try { asCollection("foo", PPrimitive.BOOL); fail("no exception"); } catch (ProvidenceConfigException e) { assertThat(e.getMessage(), is("Unable to convert String to a collection")); } }
@SuppressWarnings("unchecked") static <T> Collection<T> asCollection(Object value, PDescriptor itemType) throws ProvidenceConfigException { if (value instanceof Collection) { Collection<T> out = new ArrayList<>(); for (Object item : (Collection) value) { out.add((T) asType(itemType, item)); } return out; } throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a collection"); }
ProvidenceConfigUtil { @SuppressWarnings("unchecked") static <T> Collection<T> asCollection(Object value, PDescriptor itemType) throws ProvidenceConfigException { if (value instanceof Collection) { Collection<T> out = new ArrayList<>(); for (Object item : (Collection) value) { out.add((T) asType(itemType, item)); } return out; } throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a collection"); } }
ProvidenceConfigUtil { @SuppressWarnings("unchecked") static <T> Collection<T> asCollection(Object value, PDescriptor itemType) throws ProvidenceConfigException { if (value instanceof Collection) { Collection<T> out = new ArrayList<>(); for (Object item : (Collection) value) { out.add((T) asType(itemType, item)); } return out; } throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a collection"); } private  ProvidenceConfigUtil(); }
ProvidenceConfigUtil { @SuppressWarnings("unchecked") static <T> Collection<T> asCollection(Object value, PDescriptor itemType) throws ProvidenceConfigException { if (value instanceof Collection) { Collection<T> out = new ArrayList<>(); for (Object item : (Collection) value) { out.add((T) asType(itemType, item)); } return out; } throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a collection"); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); }
ProvidenceConfigUtil { @SuppressWarnings("unchecked") static <T> Collection<T> asCollection(Object value, PDescriptor itemType) throws ProvidenceConfigException { if (value instanceof Collection) { Collection<T> out = new ArrayList<>(); for (Object item : (Collection) value) { out.add((T) asType(itemType, item)); } return out; } throw new ProvidenceConfigException( "Unable to convert " + value.getClass().getSimpleName() + " to a collection"); } private  ProvidenceConfigUtil(); static Path canonicalFileLocation(@Nonnull Path file); static final String UNDEFINED; }