Пример #1
0
  @Test
  public void test_flatMap_null_right() {
    // prepare
    final String left = "foo";
    Pair<String> pair = new Pair<>(left, null);

    // action
    Pair<Integer> result =
        pair.flatMap(
            (l, r) -> {
              final int lengthL = (l == null ? 0 : l.length());
              final int lengthR = (r == null ? 0 : r.length());
              Pair<Integer> tmp = new Pair<>(lengthL, lengthR);
              reverse(tmp);
              return tmp;
            });

    // check
    assertEquals(left.length(), result.getRight().intValue());
    assertEquals(0, result.getLeft().intValue());
  }
Пример #2
0
 private <T> void reverse(Pair<T> pair) {
   final T left = pair.getLeft();
   pair.setLeft(pair.getRight());
   pair.setRight(left);
 }