下面列出了java.util.OptionalInt#orElseThrow ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int findFreePort( InetAddress address )
{
FreePortPredicate check = new FreePortPredicate( address );
// Randomly choose MAX_PORT_CHECKS ports from the least used ranges
Range range = LEAST_USED_RANGES.get( new Random().nextInt( LEAST_USED_RANGES.size() ) );
OptionalInt port = rangeClosed( range.lowerBound, range.higherBound )
.boxed()
.collect( collectingAndThen( toList(), collected ->
{
collected.removeAll( BLACKLIST );
shuffle( collected );
return collected.stream();
} ) )
.limit( MAX_PORT_CHECKS )
.mapToInt( Integer::intValue )
.filter( check )
.findFirst();
return port.orElseThrow( () ->
{
IOException exception = new IOException( "Unable to find a free port on " + address );
check.errors.build().forEach( exception::addSuppressed );
return new UncheckedIOException( exception );
} );
}
@Override
public ListenableFuture<PartitionedConsumption<Supplier<LookupSource>>> finishProbeOperator(OptionalInt lookupJoinsCount)
{
lock.writeLock().lock();
try {
if (!spillingInfo.hasSpilled()) {
finishedProbeOperators++;
return immediateFuture(new PartitionedConsumption<>(
1,
emptyList(),
i -> {
throw new UnsupportedOperationException();
},
i -> {}));
}
int operatorsCount = lookupJoinsCount
.orElseThrow(() -> new IllegalStateException("A fixed distribution is required for JOIN when spilling is enabled"));
checkState(finishedProbeOperators < operatorsCount, "%s probe operators finished out of %s declared", finishedProbeOperators + 1, operatorsCount);
if (partitionedConsumptionParticipants.isEmpty()) {
// This is the first probe to finish after anything has been spilled.
partitionedConsumptionParticipants = OptionalInt.of(operatorsCount - finishedProbeOperators);
}
finishedProbeOperators++;
if (finishedProbeOperators == operatorsCount) {
// We can dispose partitions now since as right outer is not supported with spill
freePartitions();
verify(!partitionedConsumption.isDone());
partitionedConsumption.set(new PartitionedConsumption<>(
partitionedConsumptionParticipants.getAsInt(),
spilledPartitions.keySet(),
this::loadSpilledLookupSource,
this::disposeSpilledLookupSource));
}
return partitionedConsumption;
}
finally {
lock.writeLock().unlock();
}
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Override
public int echoOptionalInt(OptionalInt value)
throws EmptyOptionalException
{
return value.orElseThrow(EmptyOptionalException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
@Test(expected=IllegalStateException.class)
public void optional_int_orElseThrow() {
OptionalInt optionalFramework = OptionalInt.empty();
optionalFramework.orElseThrow(IllegalStateException::new);
}