@Test public void applyBinOpExcludesIncompleteTagset() { final Map<String, MetricValue> OUT_METRICS = unmodifiableMap(new HashMap<String, MetricValue>() {{ put("keep_me", MetricValue.fromStrValue("keep_me")); }}); final Map<String, MetricValue> IN_LEFT = unmodifiableMap(new HashMap<String, MetricValue>() {{ put("side", MetricValue.fromStrValue("left")); put("exclude-me", MetricValue.TRUE); putAll(OUT_METRICS); }}); final Map<String, MetricValue> IN_RIGHT = unmodifiableMap(new HashMap<String, MetricValue>() {{ put("side", MetricValue.fromStrValue("right")); putAll(OUT_METRICS); }}); WithoutTagAggregationClause clause = new WithoutTagAggregationClause(Arrays.asList("side", "exclude-me")); final Map<Tags, Collection<Map<String, MetricValue>>> application = clause.apply(Stream.of(IN_LEFT), Stream.of(IN_RIGHT), Tags::valueOf, Tags::valueOf, Function.identity(), Function.identity()); assertThat(application, hasEntry(equalTo(Tags.valueOf(OUT_METRICS)), contains(equalTo(IN_LEFT)))); assertEquals(1, application.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();  }