@Test public void canMergeSetOfFrames() { var frameRangeString = Stream.of(15, 5, 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 99, 17, 18) .collect(DetectionErrorUtil.toFrameRangesString()); assertEquals("(Frames: 0 - 5, 7 - 10, 15, 17, 18, 99)", frameRangeString.get()); frameRangeString = Stream.of(99).collect(DetectionErrorUtil.toFrameRangesString()); assertEquals("(Frames: 99)", frameRangeString.get()); frameRangeString = Stream.<Integer>empty().collect(DetectionErrorUtil.toFrameRangesString()); assertTrue(frameRangeString.isEmpty()); }
private static <T> Collector<T, ?, Optional<String>> toFrameRangesString(Function<T, Range<Integer>> toRangeFn) { return Collector.of( TreeRangeSet::create, (rs, el) -> rs.add(toRangeFn.apply(el)), (rs1, rs2) -> { rs1.addAll(rs2); return rs1; }, DetectionErrorUtil::createFrameRangeString ); }
DetectionErrorUtil { private static <T> Collector<T, ?, Optional<String>> toFrameRangesString(Function<T, Range<Integer>> toRangeFn) { return Collector.of( TreeRangeSet::create, (rs, el) -> rs.add(toRangeFn.apply(el)), (rs1, rs2) -> { rs1.addAll(rs2); return rs1; }, DetectionErrorUtil::createFrameRangeString ); } }
DetectionErrorUtil { private static <T> Collector<T, ?, Optional<String>> toFrameRangesString(Function<T, Range<Integer>> toRangeFn) { return Collector.of( TreeRangeSet::create, (rs, el) -> rs.add(toRangeFn.apply(el)), (rs1, rs2) -> { rs1.addAll(rs2); return rs1; }, DetectionErrorUtil::createFrameRangeString ); } private  DetectionErrorUtil(); }
DetectionErrorUtil { private static <T> Collector<T, ?, Optional<String>> toFrameRangesString(Function<T, Range<Integer>> toRangeFn) { return Collector.of( TreeRangeSet::create, (rs, el) -> rs.add(toRangeFn.apply(el)), (rs1, rs2) -> { rs1.addAll(rs2); return rs1; }, DetectionErrorUtil::createFrameRangeString ); } private  DetectionErrorUtil(); static Multimap<Long, JsonIssueDetails> getMergedDetectionErrors(BatchJob job); static Collector<Integer, ?, Optional<String>> toFrameRangesString(); }
DetectionErrorUtil { private static <T> Collector<T, ?, Optional<String>> toFrameRangesString(Function<T, Range<Integer>> toRangeFn) { return Collector.of( TreeRangeSet::create, (rs, el) -> rs.add(toRangeFn.apply(el)), (rs1, rs2) -> { rs1.addAll(rs2); return rs1; }, DetectionErrorUtil::createFrameRangeString ); } private  DetectionErrorUtil(); static Multimap<Long, JsonIssueDetails> getMergedDetectionErrors(BatchJob job); static Collector<Integer, ?, Optional<String>> toFrameRangesString();  }