Java Code Examples for java.util.OptionalInt#orElseThrow()

The following examples show how to use java.util.OptionalInt#orElseThrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreePortFinder.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
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 );
    } );
}
 
Example 2
Source File: BasicInt.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 3
Source File: BasicInt.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 4
Source File: BasicInt.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 5
Source File: BasicInt.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 6
Source File: BasicInt.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 7
Source File: BasicInt.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 8
Source File: BasicInt.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 9
Source File: BasicInt.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 10
Source File: BasicInt.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 11
Source File: BasicInt.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 12
Source File: PartitionedLookupSourceFactory.java    From presto with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 13
Source File: EchoServiceHandler.java    From drift with Apache License 2.0 4 votes vote down vote up
@Override
public int echoOptionalInt(OptionalInt value)
        throws EmptyOptionalException
{
    return value.orElseThrow(EmptyOptionalException::new);
}
 
Example 14
Source File: BasicInt.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 15
Source File: BasicInt.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 16
Source File: BasicInt.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 17
Source File: BasicInt.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 18
Source File: BasicInt.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(ObscureException::new);
}
 
Example 19
Source File: BasicInt.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.orElseThrow(null);
}
 
Example 20
Source File: OptionalIntExample.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test(expected=IllegalStateException.class)
public void optional_int_orElseThrow() {
	
	OptionalInt optionalFramework = OptionalInt.empty();

	optionalFramework.orElseThrow(IllegalStateException::new);
}