DefaultChunk implements Chunk<E> { @Override public boolean isOverlappingWith(Chunk<E> otherChunk) { if (getIndex() <= otherChunk.getIndex()) { return getLastIndex() + 1 >= otherChunk.getIndex(); } else { return getIndex() <= otherChunk.getLastIndex() + 1; } } DefaultChunk(int index, List<E> elements);  DefaultChunk(difflib.Chunk<E> chunk); @Override void verify(List<E> target); @Override int getIndex(); @Override void setElements(List<E> lines); @Override List<E> getElements(); @Override int size(); @Override int getLastIndex(); @Override boolean isOverlappingWith(Chunk<E> otherChunk); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test void isOverlapping() { Chunk<Integer> chunk1 = new DefaultChunk<>(5, Arrays.asList(1, 2, 3, 4, 5)); Chunk<Integer> chunk2 = new DefaultChunk<>(5, Arrays.asList(1, 2)); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(3, Arrays.asList(1, 2, 3)); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(2, Arrays.asList(1, 2)); assertFalse(chunk1.isOverlappingWith(chunk2)); assertFalse(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(2, Arrays.asList(1, 2, 3)); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(6, Arrays.asList(1, 2, 3)); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(10, Collections.emptyList()); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(11, Arrays.asList(1, 2)); assertFalse(chunk1.isOverlappingWith(chunk2)); assertFalse(chunk2.isOverlappingWith(chunk1)); chunk2 = new DefaultChunk<>(3, Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)); assertTrue(chunk1.isOverlappingWith(chunk2)); assertTrue(chunk2.isOverlappingWith(chunk1)); }