Refine search
public void setDriverInstanceCount(int driverInstanceCount) { checkArgument(driverInstanceCount > 0, "driverInstanceCount must be > 0"); if (this.driverInstanceCount.isPresent()) { checkState(this.driverInstanceCount.getAsInt() == driverInstanceCount, "driverInstance count already set to " + this.driverInstanceCount.getAsInt()); } this.driverInstanceCount = OptionalInt.of(driverInstanceCount); } }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * Convert an optional value to a boxed one. If the inner value is * empty, {@code null} will be returned. * * @param optional the optional value (or null) * @return the inner value or {@code null} */ public static Integer unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalInt optional) { return optional == null ? null : optional.isPresent() ? optional.getAsInt() : null; }
@Override public void writeTo(OptionalInt entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw EmptyOptionalException.INSTANCE; } entityStream.write(Integer.toString(entity.getAsInt()).getBytes(StandardCharsets.US_ASCII)); } }
private List<String> getNewWarnings(List<PrestoWarning> warnings) { int end = warnings.size(); if (maxWarnings.isPresent()) { end = Math.min(processedWarnings + maxWarnings.getAsInt(), end); } List<String> subList = warnings.subList(processedWarnings, end).stream() .map(this::getWarningMessage) .collect(toImmutableList()); processedWarnings = end; return subList; }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
private boolean meetsPredicate(List<String> fields) { if (!timestampOrdinalPosition.isPresent() || !domain.isPresent()) { return true; } long millis = Instant.from(ISO_FORMATTER.parse(fields.get(timestampOrdinalPosition.getAsInt()))).toEpochMilli(); return domain.get().includesNullableValue(millis); }
private static void addLeaves(Node node, ImmutableMap.Builder<Integer, Rectangle> leaves, Predicate<Node> predicate) { if (!predicate.apply(node)) { return; } if (node.leafId.isPresent()) { leaves.put(node.leafId.getAsInt(), node.extent); } else { addLeaves(node.left.get(), leaves, predicate); addLeaves(node.right.get(), leaves, predicate); } }
@JsonCreator public Node( @JsonProperty("extent") Rectangle extent, @JsonProperty("leafId") OptionalInt leafId, @JsonProperty("left") Optional<Node> left, @JsonProperty("right") Optional<Node> right) { this.extent = requireNonNull(extent, "extent is null"); this.leafId = requireNonNull(leafId, "leafId is null"); this.left = requireNonNull(left, "left is null"); this.right = requireNonNull(right, "right is null"); if (leafId.isPresent()) { checkArgument(leafId.getAsInt() >= 0, "leafId must be >= 0"); checkArgument(!left.isPresent(), "Leaf node cannot have left child"); checkArgument(!right.isPresent(), "Leaf node cannot have right child"); } else { checkArgument(left.isPresent(), "Intermediate node must have left child"); checkArgument(right.isPresent(), "Intermediate node must have right child"); } }
private static Optional<Domain> getDomain(OptionalInt timestampOrdinalPosition, TupleDomain<LocalFileColumnHandle> predicate) { Optional<Map<LocalFileColumnHandle, Domain>> domains = predicate.getDomains(); Domain domain = null; if (domains.isPresent() && timestampOrdinalPosition.isPresent()) { Map<LocalFileColumnHandle, Domain> domainMap = domains.get(); Set<Domain> timestampDomain = domainMap.entrySet().stream() .filter(entry -> entry.getKey().getOrdinalPosition() == timestampOrdinalPosition.getAsInt()) .map(Map.Entry::getValue) .collect(toSet()); if (!timestampDomain.isEmpty()) { domain = Iterables.getOnlyElement(timestampDomain); } } return Optional.ofNullable(domain); }
public AsyncQueue<InternalHiveSplit> queueFor(OptionalInt bucketNumber) { checkArgument(bucketNumber.isPresent()); AtomicBoolean isNew = new AtomicBoolean(); AsyncQueue<InternalHiveSplit> queue = queues.computeIfAbsent(bucketNumber.getAsInt(), ignored -> { isNew.set(true); return new AsyncQueue<>(estimatedOutstandingSplitsPerBucket, executor); }); if (isNew.get() && finished.get()) { // Check `finished` and invoke `queue.finish` after the `queue` is added to the map. // Otherwise, `queue.finish` may not be invoked if `finished` is set while the lambda above is being evaluated. queue.finish(); } return queue; } },
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
@Override public synchronized ListenableFuture<?> whenSplitQueueHasSpace(int threshold) { if (whenSplitQueueHasSpaceThreshold.isPresent()) { checkArgument(threshold == whenSplitQueueHasSpaceThreshold.getAsInt(), "Multiple split queue space notification thresholds not supported"); } else { whenSplitQueueHasSpaceThreshold = OptionalInt.of(threshold); updateSplitQueueSpace(); } if (splitQueueHasSpace) { return immediateFuture(null); } return whenSplitQueueHasSpace.createNewListener(); }