@Test public void testSupply() { AtomicInteger counter = new AtomicInteger(0); Context context = Context.create(); context.register(1); Date date = new Date(); context.register(date); context.register("aaa"); context.supply(String.class, () -> { counter.incrementAndGet(); return "bbb"; }); context.register(2); assertThat(context.get(Date.class), is(Optional.of(date))); assertThat(counter.get(), is(0)); assertThat(context.get(String.class), is(Optional.of("bbb"))); assertThat(counter.get(), is(1)); assertThat(context.get(String.class), is(Optional.of("bbb"))); assertThat(counter.get(), is(1)); assertThat(context.get(Date.class), is(Optional.of(date))); assertThat(context.get(String.class), is(Optional.of("bbb"))); assertThat(counter.get(), is(1)); }
@Override public <T> void supply(Class<T> type, Supplier<T> supplier) { registry.supply(type, supplier); }
ListContext implements Context { @Override public <T> void supply(Class<T> type, Supplier<T> supplier) { registry.supply(type, supplier); } }
ListContext implements Context { @Override public <T> void supply(Class<T> type, Supplier<T> supplier) { registry.supply(type, supplier); } ListContext(Builder builder); }
ListContext implements Context { @Override public <T> void supply(Class<T> type, Supplier<T> supplier) { registry.supply(type, supplier); } ListContext(Builder builder); @Override String id(); @Override void register(T instance); @Override void supply(Class<T> type, Supplier<T> supplier); @Override Optional<T> get(Class<T> type); @Override void register(Object classifier, T instance); @Override void supply(Object classifier, Class<T> type, Supplier<T> supplier); @Override Optional<T> get(Object classifier, Class<T> type); }
ListContext implements Context { @Override public <T> void supply(Class<T> type, Supplier<T> supplier) { registry.supply(type, supplier); } ListContext(Builder builder); @Override String id(); @Override void register(T instance); @Override void supply(Class<T> type, Supplier<T> supplier); @Override Optional<T> get(Class<T> type); @Override void register(Object classifier, T instance); @Override void supply(Object classifier, Class<T> type, Supplier<T> supplier); @Override Optional<T> get(Object classifier, Class<T> type);  }