/** * @return an empty {@code Optional} */ public static <T> Optional<T> absent() { return empty(); }
/** * @return an empty {@code Optional} */ public static <T> Optional<T> absent() { return empty(); }
/** * @return an empty {@code Optional} */ public static <T> Optional<T> absent() { return empty(); }
/** * @param value value to wrap, which may be null * @return {@code Optional} wrapping this value, which may be empty */ public static <T> Optional<T> ofNullable(T value) { if (value == null) { return empty(); } else { return of(value); } }
/** * @param value value to wrap, which may be null * @return {@code Optional} wrapping this value, which may be empty */ public static <T> Optional<T> ofNullable(T value) { if (value == null) { return empty(); } else { return of(value); } }
/** * @param value value to wrap, which may be null * @return {@code Optional} wrapping this value, which may be empty */ public static <T> Optional<T> ofNullable(T value) { if (value == null) { return empty(); } else { return of(value); } }
@Test(expected = NullPointerException.class) public void testEmptyGet() { Optional.empty().get(); }
@Test(expected = NullPointerException.class) public void testEmptyGet() { Optional.empty().get(); }
@Test(expected = NullPointerException.class) public void testEmptyGet() { Optional.empty().get(); }
private void emitLeft() { leftQueue.forEach( left -> outQueue.add( new Tuple2<>( left._1.getKey(), new Tuple2<>(Optional.of(left._2.left()), Optional.empty())))); leftQueue.clear(); }
sjk.getKey(), new Tuple2<>(Optional.empty(), Optional.of(tuple._2.right()))));
@Test public void emitsARightLonerWhenARightSideWithADifferentKeyComes() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), // ~ a right side with a different key entry("key3", RIGHT, Either.right("w1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals(asList(entry("key1", "v1", "w1"), entry("key3", Optional.empty(), "w1")), results); }
@Test public void emitsALeftLonerAndARightLonerWhenARightSideWithADifferentKeyComes() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), // ~ a left side with no right sides entry("key2", LEFT, Either.left("v1")), // ~ a right side with a different key entry("key3", RIGHT, Either.right("w1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals( asList( entry("key1", "v1", "w1"), entry("key3", Optional.empty(), "w1"), entry("key2", "v1", Optional.empty())), results); }
@Test public void lonerRightSideInTheEnd() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), entry("key1", RIGHT, Either.right("w2")), entry("key2", RIGHT, Either.right("w1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals( asList( entry("key1", "v1", "w1"), entry("key1", "v1", "w2"), entry("key2", Optional.empty(), "w1")), results); }
@Test public void lonerLeftSideInTheEnd() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), entry("key1", RIGHT, Either.right("w2")), entry("key2", LEFT, Either.left("v1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals( asList( entry("key1", "v1", "w1"), entry("key1", "v1", "w2"), entry("key2", "v1", Optional.empty())), results); }
@Test public void emitsALeftLonerWhenAConsecutiveSecondLeftSideComes() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), // ~ a left side with no right sides entry("key2", LEFT, Either.left("v1")), // ~ a consecutive second left side entry("key3", LEFT, Either.left("v1")), entry("key3", RIGHT, Either.right("w1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals( asList( entry("key1", "v1", "w1"), entry("key2", "v1", Optional.empty()), entry("key3", "v1", "w1")), results); }
@Test public void emitsARightLonerWhenAConsecutiveSecondLeftSideComes() { final Iterator<Tuple2<BatchJoinKey<String>, Either<String, String>>> inner = asList( entry("key1", LEFT, Either.left("v1")), entry("key1", RIGHT, Either.right("w1")), // ~ a left side with no right sides entry("key2", RIGHT, Either.right("w1")), // ~ a consecutive second left side entry("key3", LEFT, Either.left("v1")), entry("key3", RIGHT, Either.right("w1"))) .iterator(); final List<Tuple2<String, Tuple2<Optional<String>, Optional<String>>>> results = Lists.newArrayList(new BatchJoinIterator<>(inner)); assertEquals( asList( entry("key1", "v1", "w1"), entry("key2", Optional.empty(), "w1"), entry("key3", "v1", "w1")), results); }