@Test public void filter() { final Map<String, MetricValue> OUT_METRICS = unmodifiableMap(new HashMap<String, MetricValue>() {{ put("keep_me", MetricValue.fromStrValue("keep_me")); }}); final Map<String, MetricValue> IN_METRICS = unmodifiableMap(new HashMap<String, MetricValue>() {{ put("foo", MetricValue.fromStrValue("foo")); put("bar", MetricValue.TRUE); put("1", MetricValue.FALSE); putAll(OUT_METRICS); }}); WithoutTagAggregationClause clause = new WithoutTagAggregationClause(Arrays.asList("foo", "bar", "1")); final Map<Tags, Collection<Map<String, MetricValue>>> filtered = clause.apply(Stream.of(IN_METRICS), Tags::valueOf, Function.identity()); assertThat(filtered, hasEntry(equalTo(Tags.valueOf(OUT_METRICS)), contains(equalTo(IN_METRICS)))); assertEquals(1, filtered.size()); }
@Override public <X, R> Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn) { return x_stream .map(x -> SimpleMapEntry.create(x_tag_fn.apply(x), x_map_fn.apply(x))) .filter(entry -> tags.stream().allMatch(entry.getKey()::contains)) .collect(Collectors.groupingBy( entry -> key_(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toCollection(() -> (Collection<R>)new ArrayList())))); }
WithoutTagAggregationClause implements TagAggregationClause { @Override public <X, R> Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn) { return x_stream .map(x -> SimpleMapEntry.create(x_tag_fn.apply(x), x_map_fn.apply(x))) .filter(entry -> tags.stream().allMatch(entry.getKey()::contains)) .collect(Collectors.groupingBy( entry -> key_(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toCollection(() -> (Collection<R>)new ArrayList())))); } }
WithoutTagAggregationClause implements TagAggregationClause { @Override public <X, R> Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn) { return x_stream .map(x -> SimpleMapEntry.create(x_tag_fn.apply(x), x_map_fn.apply(x))) .filter(entry -> tags.stream().allMatch(entry.getKey()::contains)) .collect(Collectors.groupingBy( entry -> key_(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toCollection(() -> (Collection<R>)new ArrayList())))); } WithoutTagAggregationClause(Collection<String> tags); }
WithoutTagAggregationClause implements TagAggregationClause { @Override public <X, R> Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn) { return x_stream .map(x -> SimpleMapEntry.create(x_tag_fn.apply(x), x_map_fn.apply(x))) .filter(entry -> tags.stream().allMatch(entry.getKey()::contains)) .collect(Collectors.groupingBy( entry -> key_(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toCollection(() -> (Collection<R>)new ArrayList())))); } WithoutTagAggregationClause(Collection<String> tags); @Override boolean isScalar(); @Override Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn); @Override Map<Tags, Collection<R>> apply(Stream<X> x_stream, Stream<Y> y_stream,
            Function<? super X, Tags> x_tag_fn, Function<? super Y, Tags> y_tag_fn,
            Function<? super X, R> x_map_fn, Function<? super Y, R> y_map_fn); @Override StringBuilder configString(); }
WithoutTagAggregationClause implements TagAggregationClause { @Override public <X, R> Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn) { return x_stream .map(x -> SimpleMapEntry.create(x_tag_fn.apply(x), x_map_fn.apply(x))) .filter(entry -> tags.stream().allMatch(entry.getKey()::contains)) .collect(Collectors.groupingBy( entry -> key_(entry.getKey()), Collectors.mapping(Map.Entry::getValue, Collectors.toCollection(() -> (Collection<R>)new ArrayList())))); } WithoutTagAggregationClause(Collection<String> tags); @Override boolean isScalar(); @Override Map<Tags, Collection<R>> apply(Stream<X> x_stream, Function<? super X, Tags> x_tag_fn, Function<? super X, R> x_map_fn); @Override Map<Tags, Collection<R>> apply(Stream<X> x_stream, Stream<Y> y_stream,
            Function<? super X, Tags> x_tag_fn, Function<? super Y, Tags> y_tag_fn,
            Function<? super X, R> x_map_fn, Function<? super Y, R> y_map_fn); @Override StringBuilder configString();  }