@Test public void canStopSearchingAfterFirstMatch() { final AtomicInteger count = new AtomicInteger(); mAllOpts.findOptions( "option", new Config.OptionMatcher() { @Override public boolean onOptionMatched(Option<?> option) { count.getAndIncrement(); return false; } }); assertThat(count.get()).isEqualTo(1); }
@Override public void findOptions(String idStem, OptionMatcher matcher) { Option<Void> query = Option.create(idStem, Void.class); for (Entry<Option<?>, Object> entry : mOptions.tailMap(query).entrySet()) { if (!entry.getKey().getId().startsWith(idStem)) { break; } Option<?> option = entry.getKey(); if (!matcher.onOptionMatched(option)) { break; } } }
OptionsBundle implements Config { @Override public void findOptions(String idStem, OptionMatcher matcher) { Option<Void> query = Option.create(idStem, Void.class); for (Entry<Option<?>, Object> entry : mOptions.tailMap(query).entrySet()) { if (!entry.getKey().getId().startsWith(idStem)) { break; } Option<?> option = entry.getKey(); if (!matcher.onOptionMatched(option)) { break; } } } }
OptionsBundle implements Config { @Override public void findOptions(String idStem, OptionMatcher matcher) { Option<Void> query = Option.create(idStem, Void.class); for (Entry<Option<?>, Object> entry : mOptions.tailMap(query).entrySet()) { if (!entry.getKey().getId().startsWith(idStem)) { break; } Option<?> option = entry.getKey(); if (!matcher.onOptionMatched(option)) { break; } } } OptionsBundle(TreeMap<Option<?>, Object> options); }
OptionsBundle implements Config { @Override public void findOptions(String idStem, OptionMatcher matcher) { Option<Void> query = Option.create(idStem, Void.class); for (Entry<Option<?>, Object> entry : mOptions.tailMap(query).entrySet()) { if (!entry.getKey().getId().startsWith(idStem)) { break; } Option<?> option = entry.getKey(); if (!matcher.onOptionMatched(option)) { break; } } } OptionsBundle(TreeMap<Option<?>, Object> options); static OptionsBundle from(Config otherConfig); static OptionsBundle emptyBundle(); @Override Set<Option<?>> listOptions(); @Override boolean containsOption(Option<?> id); @Override ValueT retrieveOption(Option<ValueT> id); @Nullable @Override ValueT retrieveOption(Option<ValueT> id, @Nullable ValueT valueIfMissing); @Override void findOptions(String idStem, OptionMatcher matcher); }
OptionsBundle implements Config { @Override public void findOptions(String idStem, OptionMatcher matcher) { Option<Void> query = Option.create(idStem, Void.class); for (Entry<Option<?>, Object> entry : mOptions.tailMap(query).entrySet()) { if (!entry.getKey().getId().startsWith(idStem)) { break; } Option<?> option = entry.getKey(); if (!matcher.onOptionMatched(option)) { break; } } } OptionsBundle(TreeMap<Option<?>, Object> options); static OptionsBundle from(Config otherConfig); static OptionsBundle emptyBundle(); @Override Set<Option<?>> listOptions(); @Override boolean containsOption(Option<?> id); @Override ValueT retrieveOption(Option<ValueT> id); @Nullable @Override ValueT retrieveOption(Option<ValueT> id, @Nullable ValueT valueIfMissing); @Override void findOptions(String idStem, OptionMatcher matcher);  }