@Test public void testValueAsDouble() { ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class) .resource(BW1.bps()); Optional<Double> value = resource.valueAs(Double.class); assertThat(value.get(), is(BW1.bps())); }
@Override public <T> Optional<T> valueAs(Class<T> type) { checkNotNull(type); if (type == Object.class || type == double.class || type == Double.class) { @SuppressWarnings("unchecked") T value = (T) Double.valueOf(this.value); return Optional.of(value); } return Optional.empty(); }
ContinuousResource implements Resource { @Override public <T> Optional<T> valueAs(Class<T> type) { checkNotNull(type); if (type == Object.class || type == double.class || type == Double.class) { @SuppressWarnings("unchecked") T value = (T) Double.valueOf(this.value); return Optional.of(value); } return Optional.empty(); } }
ContinuousResource implements Resource { @Override public <T> Optional<T> valueAs(Class<T> type) { checkNotNull(type); if (type == Object.class || type == double.class || type == Double.class) { @SuppressWarnings("unchecked") T value = (T) Double.valueOf(this.value); return Optional.of(value); } return Optional.empty(); } ContinuousResource(ContinuousResourceId id, double value);   ContinuousResource(); }
ContinuousResource implements Resource { @Override public <T> Optional<T> valueAs(Class<T> type) { checkNotNull(type); if (type == Object.class || type == double.class || type == Double.class) { @SuppressWarnings("unchecked") T value = (T) Double.valueOf(this.value); return Optional.of(value); } return Optional.empty(); } ContinuousResource(ContinuousResourceId id, double value);   ContinuousResource(); @Override ContinuousResourceId id(); @Override String simpleTypeName(); @Override boolean isTypeOf(Class<?> type); double value(); @Override boolean isSubTypeOf(Class<?> ancestor); @Override Optional<T> valueAs(Class<T> type); @Override DiscreteResource child(Object child); @Override ContinuousResource child(Class<?> child, double value); @Override Optional<DiscreteResource> parent(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
ContinuousResource implements Resource { @Override public <T> Optional<T> valueAs(Class<T> type) { checkNotNull(type); if (type == Object.class || type == double.class || type == Double.class) { @SuppressWarnings("unchecked") T value = (T) Double.valueOf(this.value); return Optional.of(value); } return Optional.empty(); } ContinuousResource(ContinuousResourceId id, double value);   ContinuousResource(); @Override ContinuousResourceId id(); @Override String simpleTypeName(); @Override boolean isTypeOf(Class<?> type); double value(); @Override boolean isSubTypeOf(Class<?> ancestor); @Override Optional<T> valueAs(Class<T> type); @Override DiscreteResource child(Object child); @Override ContinuousResource child(Class<?> child, double value); @Override Optional<DiscreteResource> parent(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }