CustomizableLevelIndexWalker implements LevelIndexWalker<T> { @Override public List<T> find() { List<LevelNode<T>> nodes = inspect(index.getRoot(), 0); return levelLeafValuesExtractor.extract(this, nodes); } CustomizableLevelIndexWalker(IndexTraversalConfig overrides,
            LevelLeafValuesExtractor<T> levelLeafValuesExtractor,
            LevelIndex<T> index, String... levelValues); @Override List<T> find(); @SuppressWarnings("unchecked") List<LevelNode<T>> inspect(LevelNode<T> currentNode, int depth); int indexDepth(); int descriptorsCount(); IndexLevelDescriptor descriptorFor(int depth); IndexLevelDescriptor descriptorFor(String levelName); String levelValueFor(int depth);  }
@Test public void shouldTraverseWholeTreeGreedilyAndReturnAllMatchingValues() { LevelIndex<String> index = levelIndex().withLevelCount(3).build(); index.add(new String[]{"*", "B", "*"}, "default"); index.add(new String[]{"A", "B", "C"}, "value"); index.add(new String[]{"A", "C", "*"}, "noise"); CustomizableLevelIndexWalker<String> crawler = new CustomizableLevelIndexWalker<String>( indexTraversalOverrides().withGreediness(true, true, true).build(), new SimpleLevelLeafValuesExtractor<String>(), index, "A", "B", "C"); List<String> values = crawler.find(); assertThat(values).containsOnly("value", "default"); }
@Test public void shouldTraverseWhleTreeGreedilyWithOverridingAllowAllMatcherAndReturnAllMatchingValues() { LevelIndex<String> index = levelIndex().withLevelCount(3).build(); index.add(new String[]{"*", "B", "*"}, "default"); index.add(new String[]{"A", "B", "C"}, "value"); index.add(new String[]{"A", "C", "*"}, "allowAllValue"); Matcher allowAll = new MatchAllMatcher(); CustomizableLevelIndexWalker<String> crawler = new CustomizableLevelIndexWalker<String>( indexTraversalOverrides().withGreediness(true, true, true).overridingMatchers(null, allowAll, null).build(), new SimpleLevelLeafValuesExtractor<String>(), index, "A", "B", "C"); List<String> values = crawler.find(); assertThat(values).containsOnly("value", "default", "allowAllValue"); }
@Test public void shouldTraverseOnlyOneLevelGreedilyWhileUsingDefaultModeInRestOfLevels() { LevelIndex<String> index = levelIndex().withLevelCount(3).build(); index.add(new String[]{"*", "B", "*"}, "default"); index.add(new String[]{"A", "B", "C"}, "value"); index.add(new String[]{"A", "C", "*"}, "allowAllValue"); Matcher allowAll = new MatchAllMatcher(); CustomizableLevelIndexWalker<String> crawler = new CustomizableLevelIndexWalker<String>( indexTraversalOverrides().withGreediness(false, true, false).overridingMatchers(null, allowAll, null).build(), new SimpleLevelLeafValuesExtractor<String>(), index, "A", "B", "C"); List<String> values = crawler.find(); assertThat(values).containsOnly("value", "allowAllValue"); }