public int getOrdinalPosition() { return ordinalPosition.orElseThrow(() -> new UnsupportedOperationException("Testing handle was created without ordinal position")); }
@Override public ToIntFunction<ConnectorSplit> getSplitBucketFunction( ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) { return value -> ((HiveSplit) value).getBucketNumber() .orElseThrow(() -> new IllegalArgumentException("Bucket number not set in split")); }
int getMaxValue(final List<int[]> vals) { return vals .stream() .mapToInt(array -> IntStream.of(array).max().orElse(0)) .max() .orElseThrow(NoSuchElementException::new); }
.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);
private static int findOpenPort(final int startInclusive, final int endExclusive) { return range(startInclusive, endExclusive) .filter(RedisRule::testPort) .findFirst() .orElseThrow(() ->new IllegalStateException(format( "No open port found in the range [%d, %d]", startInclusive, endExclusive))); }
public int getOrdinalPosition() { return ordinalPosition.orElseThrow(() -> new UnsupportedOperationException("Testing handle was created without ordinal position")); }
static int getNumber(final String methodName, final Class<?>[] argTypes, final Class<?> remoteInterface) { final Method[] methods = remoteInterface.getMethods(); Arrays.sort(methods, methodComparator); return IntStream.range(0, methods.length) .filter(i -> methods[i].getName().equals(methodName)) .filter(i -> Arrays.equals(argTypes, methods[i].getParameterTypes())) .findAny() .orElseThrow(() -> new IllegalStateException("Method not found: " + methodName)); }
@Override public int echoOptionalInt(OptionalInt value) throws EmptyOptionalException { return value.orElseThrow(EmptyOptionalException::new); }
@Override public void write(OptionalInt value, TProtocolWriter protocol) throws Exception { requireNonNull(value, "value is null"); requireNonNull(protocol, "protocol is null"); // write can not be called with a missing value, and instead the write should be skipped // after check the result from isNull protocol.writeI32(value.orElseThrow(() -> new IllegalArgumentException("value is not present"))); }
@Override public ToIntFunction<ConnectorSplit> getSplitBucketFunction( ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) { return value -> ((HiveSplit) value).getBucketNumber() .orElseThrow(() -> new IllegalArgumentException("Bucket number not set in split")); }
public void execute(BooleanSupplier functionNotifyingSuccess) throws LightweightTransactionException { IntStream.range(0, maxRetry) .filter((x) -> functionNotifyingSuccess.getAsBoolean()) .findFirst() .orElseThrow(() -> new LightweightTransactionException(maxRetry)); }
private static <T> Integer modelToPresentation(ListBox<T> listBox, T selectedItem) { if (selectedItem == null) { return Integer.valueOf(-1); } List<VaadinItem<T>> itemComponents = listBox.getItemComponents(); int itemIndex = IntStream.range(0, itemComponents.size()).filter( i -> selectedItem.equals(itemComponents.get(i).getItem())) .findFirst().orElseThrow(() -> new IllegalArgumentException( "Could not find given value from the item set")); return Integer.valueOf(itemIndex); }
private int getParameterIndex(CassandraParameters parameters, String parameterName) { return parameters.stream() // .filter(cassandraParameter -> cassandraParameter // .getName().filter(s -> s.equals(parameterName)) // .isPresent()) // .mapToInt(Parameter::getIndex) // .findFirst() // .orElseThrow(() -> new IllegalArgumentException( String.format("Invalid parameter name; Cannot resolve parameter [%s]", parameterName))); }
public int nextPrime(int num) { OptionalInt optionalInt = IntStream.iterate(num + 1, n -> n + 1) .filter(this::isPrime) .findFirst(); return optionalInt.orElseThrow(IllegalArgumentException::new); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
private int nextCodePoint(final SourceGenerator source) { return IntStream.range(0, MAX_TRIES) .map(i -> minValue + source.generateInt(range)) .filter(Character::isDefined) .findFirst() .orElseThrow(Generators::exceededMaxTries); }
private int getTotalPartitions() { try (Producer<byte[], byte[]> producer = this.getProducer()) { return producer.partitionsFor(this.topic).stream().mapToInt(PartitionInfo::partition).max().orElseThrow(() -> new InvalidPartitionsException("partitions not found")) + 1; } }
private int nextCodePoint(final SourceGenerator source) { return IntStream.range(0, MAX_TRIES) .map(i -> minValue + source.generateInt(range)) .filter(Character::isDefined) .findFirst() .orElseThrow(Generators::exceededMaxTries); }
private double factorToNextCoupon(ResolvedCapitalIndexedBond bond, LocalDate settlementDate) { if (bond.getUnadjustedStartDate().isAfter(settlementDate)) { return 0d; } int periodIndex = bond.findPeriodIndex(settlementDate) .orElseThrow(() -> new IllegalArgumentException("Date outside range of bond")); CapitalIndexedBondPaymentPeriod period = bond.getPeriodicPayments().get(periodIndex); LocalDate previousAccrualDate = period.getUnadjustedStartDate(); double factorSpot = bond.yearFraction(previousAccrualDate, settlementDate); double factorPeriod = bond.yearFraction(previousAccrualDate, period.getUnadjustedEndDate()); return (factorPeriod - factorSpot) / factorPeriod; }