ForwardLongestSelector implements SegmentationSelector { @Override public List<Emit> select(final Collection<Emit> emits) { if (emits == null) { return null; } List<Emit> results = new ArrayList<Emit>(emits); Collections.sort(results, HIT_COMPARATOR); int endValueToRemove = -1; Set<Emit> emitToRemove = new TreeSet<Emit>(); for (Emit emit : results) { if (emit.getStart() > endValueToRemove && emit.getEnd() > endValueToRemove) { endValueToRemove = emit.getEnd(); } else { emitToRemove.add(emit); } } results.removeAll(emitToRemove); return results; }  @Override List<Emit> select(final Collection<Emit> emits);  }
@Test public void select_single_hit() throws Exception { List<Emit> list = new ArrayList<Emit>(); list.add(new Emit(0, 4, null)); List<Emit> result = mSelector.select(list); assertThat(result.size(), is(1)); assertThat(result.get(0).getStart(), is(0)); assertThat(result.get(0).getEnd(), is(4)); }
@Test public void select_multi_hit_no_overlap() throws Exception { List<Emit> list = new ArrayList<Emit>(); list.add(new Emit(0, 5, null)); list.add(new Emit(7, 8, null)); list.add(new Emit(9, 10, null)); List<Emit> result = mSelector.select(list); assertThat(result.size(), is(3)); assertThat(result.get(0).getStart(), is(0)); assertThat(result.get(0).getEnd(), is(5)); assertThat(result.get(1).getStart(), is(7)); assertThat(result.get(1).getEnd(), is(8)); assertThat(result.get(2).getStart(), is(9)); assertThat(result.get(2).getEnd(), is(10)); }
@Test public void select_multi_hit_with_overlap() throws Exception { List<Emit> list = new ArrayList<Emit>(); list.add(new Emit(0, 4, null)); list.add(new Emit(0, 4, null)); list.add(new Emit(0, 5, null)); list.add(new Emit(2, 3, null)); list.add(new Emit(2, 10, null)); list.add(new Emit(5, 7, null)); list.add(new Emit(7, 8, null)); list.add(new Emit(8, 9, null)); List<Emit> result = mSelector.select(list); assertThat(result.size(), is(2)); assertThat(result.get(0).getStart(), is(0)); assertThat(result.get(0).getEnd(), is(5)); assertThat(result.get(1).getStart(), is(7)); assertThat(result.get(1).getEnd(), is(8)); }
@Test public void select_null_return_null() throws Exception { List<Emit> result = mSelector.select(null); assertThat(result, nullValue()); }