Lists { static int lengthOfTrailingPartialSubList(final List<?> source, final List<?> target) { final int s = source.size() - 1; final int t = target.size() - 1; int l = 0; while (l <= s && l <= t && source.get(s - l).equals(target.get(t - l))) { l++; } return l; } private  Lists();   }
@Test void shouldFindCompleteMatch() { final int length = lengthOfTrailingPartialSubList( asList("a", "b", "c"), asList("a", "b", "c")); assertThat(length, is(equalTo(3))); }
@Test void shouldFindPartialMatch() { final int length = lengthOfTrailingPartialSubList( asList("a", "b", "c"), asList("e", "d", "c")); assertThat(length, is(equalTo(1))); }
@Test void shouldFindNoMatch() { final int length = lengthOfTrailingPartialSubList( asList("a", "b", "c"), asList("d", "e", "f")); assertThat(length, is(equalTo(0))); }
@Test void shouldFindNoMatchInEmptySource() { final int length = lengthOfTrailingPartialSubList( emptyList(), asList("a", "b", "c")); assertThat(length, is(equalTo(0))); }
@Test void shouldFindNoMatchInEmptyTarget() { final int length = lengthOfTrailingPartialSubList( asList("a", "b", "c"), emptyList()); assertThat(length, is(equalTo(0))); }