### Question:
SortedNeighborhoodPairGenerator implements PairGenerator<T> { @Override public Result<T> generate(Collection<T> left, Collection<T> right) { int expectedComputations = left.size() * Math.min(windowSize, right.size()); log.info("Will compute approximately {} similarities", Integer.valueOf(expectedComputations)); Collection<T> sortedLeft = sort(left); Collection<T> sortedRight = sort(right); Stream<Tuple2<T, Collection<T>>> pairs = new Task(sortedLeft, sortedRight).generate(); boolean complete = right.size() <= windowSize; return new Result<>(pairs, complete); }  @Override Result<T> generate(Collection<T> left, Collection<T> right); @Override void hash(Hasher hasher);  }### Answer:
@Test public void test() { PairGenerator<Integer> generator = createComputer(); Collection<Tuple2<Integer, Collection<Integer>>> similarities = generator .generate(Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(6)), Arrays.asList(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5))) .getPairs() .collect(Collectors.toList()); assertThat(similarities).hasSize(4); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(1), Arrays.asList(Integer.valueOf(1), Integer.valueOf(3)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(2), Arrays.asList(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(4)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(3), Arrays.asList(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(4)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(6), Collections.singletonList(Integer.valueOf(5)))); }
@Test public void testNull() { PairGenerator<Integer> generator = createComputer(); Collection<Tuple2<Integer, Collection<Integer>>> similarities = generator .generate(Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)), Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))) .getPairs() .collect(Collectors.toList()); assertThat(similarities).hasSize(4); assertThat(similarities).contains(new Tuple2<>(null, Arrays.asList(null, Integer.valueOf(1)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(1), Arrays.asList(null, Integer.valueOf(1), Integer.valueOf(2)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(2), Arrays.asList(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)))); assertThat(similarities).contains(new Tuple2<>(Integer.valueOf(3), Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)))); }