empty ( )源码实例Demo

java.util.OptionalInt#empty ( )源码实例Demo

下面列出了java.util.OptionalInt#empty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: presto   文件: SystemSessionProperties.java
public static OptionalInt getMaxDriversPerTask(Session session)
{
    Integer value = session.getSystemProperty(MAX_DRIVERS_PER_TASK, Integer.class);
    if (value == null) {
        return OptionalInt.empty();
    }
    return OptionalInt.of(value);
}
 
源代码2 项目: hottub   文件: BasicInt.java
@Test(groups = "unit")
    public void testPresent() {
    OptionalInt empty = OptionalInt.empty();
    OptionalInt present = OptionalInt.of(1);

    // present
    assertTrue(present.equals(present));
    assertFalse(present.equals(OptionalInt.of(0)));
    assertTrue(present.equals(OptionalInt.of(1)));
    assertFalse(present.equals(empty));
    assertTrue(Integer.hashCode(1) == present.hashCode());
    assertFalse(present.toString().isEmpty());
    assertTrue(-1 != present.toString().indexOf(Integer.toString(present.getAsInt()).toString()));
    assertEquals(1, present.getAsInt());
    try {
        present.ifPresent(v -> { throw new ObscureException(); });
        fail();
    } catch(ObscureException expected) {

    }
    assertEquals(1, present.orElse(2));
    assertEquals(1, present.orElseGet(null));
    assertEquals(1, present.orElseGet(()-> 2));
    assertEquals(1, present.orElseGet(()-> 3));
    assertEquals(1, present.<RuntimeException>orElseThrow(null));
    assertEquals(1, present.<RuntimeException>orElseThrow(ObscureException::new));
}
 
源代码3 项目: auto   文件: AutoValueOrOneOfProcessor.java
private static OptionalInt nullableAnnotationIndex(List<? extends AnnotationMirror> annotations) {
  for (int i = 0; i < annotations.size(); i++) {
    if (isNullable(annotations.get(i))) {
      return OptionalInt.of(i);
    }
  }
  return OptionalInt.empty();
}
 
源代码4 项目: LuckPerms   文件: WeightCache.java
@Override
protected @NonNull OptionalInt supply() {
    boolean seen = false;
    int best = 0;
    for (Node n : this.group.getOwnNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
        if (n instanceof WeightNode) {
            WeightNode weightNode = (WeightNode) n;
            int value = weightNode.getWeight();

            if (!seen || value > best) {
                seen = true;
                best = value;
            }
        }
    }

    OptionalInt weight = seen ? OptionalInt.of(best) : OptionalInt.empty();

    if (!weight.isPresent()) {
        Map<String, Integer> configWeights = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_WEIGHTS);
        Integer w = configWeights.get(this.group.getObjectName().toLowerCase());
        if (w != null) {
            weight = OptionalInt.of(w);
        }
    }

    return weight;
}
 
源代码5 项目: warpdb   文件: WarpDb.java
public OptionalInt queryForInt(String sql, Object... args) {
	log.debug("SQL: " + sql);
	Number number = jdbcTemplate.query(sql, args, NUMBER_RESULT_SET);
	if (number == null) {
		return OptionalInt.empty();
	}
	return OptionalInt.of(number.intValue());
}
 
源代码6 项目: MantaroBot   文件: ExtraRuntimeOptions.java
private static OptionalInt maybeInt(String name) {
    var value = getValue(name);
    if (value == null) return OptionalInt.empty();
    try {
        return OptionalInt.of(Integer.parseInt(value));
    } catch (NumberFormatException e) {
        return OptionalInt.empty();
    }
}
 
源代码7 项目: presto   文件: RaptorSplit.java
public RaptorSplit(
        UUID shardUuid,
        List<HostAddress> addresses,
        OptionalLong transactionId)
{
    this(ImmutableSet.of(shardUuid), OptionalInt.empty(), addresses, transactionId);
}
 
源代码8 项目: robozonky   文件: ReservationWrapper.java
@Override
public OptionalInt getLongestDpd() {
    return OptionalInt.empty();
}
 
StreamingMkvReader(boolean requirePath,
        Collection<EBMLTypeInfo> typeInfosToRead,
        ParserByteSource byteSource) {
    this(requirePath, typeInfosToRead, byteSource, OptionalInt.empty());
}
 
源代码10 项目: jdk8u60   文件: BasicInt.java
@Test(expectedExceptions=NoSuchElementException.class)
public void testEmptyGet() {
    OptionalInt empty = OptionalInt.empty();

    int got = empty.getAsInt();
}
 
源代码11 项目: dalesbred   文件: OptionalUtils.java
public static @NotNull OptionalInt optionalIntOfNullable(@Nullable Integer v) {
    return v != null ? OptionalInt.of(v) : OptionalInt.empty();
}
 
源代码12 项目: jdk8u-dev-jdk   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values, producing an optional integer result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, OptionalInt>
makeInt(IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
        private boolean empty;
        private int state;

        public void begin(long size) {
            empty = true;
            state = 0;
        }

        @Override
        public void accept(int t) {
            if (empty) {
                empty = false;
                state = t;
            }
            else {
                state = operator.applyAsInt(state, t);
            }
        }

        @Override
        public OptionalInt get() {
            return empty ? OptionalInt.empty() : OptionalInt.of(state);
        }

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码13 项目: vespa   文件: HealthInfo.java
static HealthInfo fromHealthStatusCode(String healthStatusCode) {
    return new HealthInfo(Optional.empty(), OptionalInt.empty(), Optional.of(healthStatusCode));
}
 
源代码14 项目: cloudbreak   文件: FreeIpaClientException.java
public FreeIpaClientException(String message, Throwable cause) {
    super(message, cause);
    statusCode = OptionalInt.empty();
}
 
源代码15 项目: helper   文件: Uuid2PosIntTable.java
@Override
protected OptionalInt emptyOptional() {
    return OptionalInt.empty();
}
 
源代码16 项目: TencentKona-8   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code int} values, producing an optional integer result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Integer, OptionalInt>
makeInt(IntBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Integer, OptionalInt, ReducingSink>, Sink.OfInt {
        private boolean empty;
        private int state;

        public void begin(long size) {
            empty = true;
            state = 0;
        }

        @Override
        public void accept(int t) {
            if (empty) {
                empty = false;
                state = t;
            }
            else {
                state = operator.applyAsInt(state, t);
            }
        }

        @Override
        public OptionalInt get() {
            return empty ? OptionalInt.empty() : OptionalInt.of(state);
        }

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Integer, OptionalInt, ReducingSink>(StreamShape.INT_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码17 项目: buck   文件: BuildLogHelper.java
private BuildLogEntry newBuildLogEntry(Path logFile) throws IOException {

    Optional<Path> machineReadableLogFile =
        Optional.of(logFile.resolveSibling(BuckConstant.BUCK_MACHINE_LOG_FILE_NAME))
            .filter(path -> projectFilesystem.isFile(path));

    Optional<Integer> exitCode =
        machineReadableLogFile.flatMap(
            machineFile -> readObjectFieldFromLog(machineFile, PREFIX_EXIT_CODE, "exitCode"));

    Optional<InvocationInfo> invocationInfo =
        machineReadableLogFile.flatMap(
            machineLogFile ->
                readObjectFromLog(
                    machineLogFile,
                    PREFIX_INVOCATION_INFO,
                    new TypeReference<InvocationInfo>() {}));

    Optional<List<String>> commandArgs =
        invocationInfo.flatMap(iInfo -> Optional.ofNullable(iInfo.getUnexpandedCommandArgs()));
    Optional<List<String>> expandedCommandArgs =
        invocationInfo.flatMap(iInfo -> Optional.ofNullable(iInfo.getCommandArgs()));

    Optional<BuildId> buildId =
        machineReadableLogFile.map(
            machineLogFile ->
                invocationInfo.map(InvocationInfo::getBuildId).orElse(new BuildId("unknown")));

    Optional<Long> startTimestampMs = invocationInfo.map(InvocationInfo::getTimestampMillis);

    Optional<Long> finishTimestampMs =
        machineReadableLogFile.flatMap(
            machineFile -> readObjectFieldFromLog(machineFile, PREFIX_BUILD_FINISHED, "timestamp"));

    OptionalInt buildTimeMs =
        finishTimestampMs.isPresent() && startTimestampMs.isPresent()
            ? OptionalInt.of((int) (finishTimestampMs.get() - startTimestampMs.get()))
            : OptionalInt.empty();

    Optional<Path> ruleKeyLoggerFile =
        Optional.of(logFile.getParent().resolve(BuckConstant.RULE_KEY_LOGGER_FILE_NAME))
            .filter(path -> projectFilesystem.isFile(path));

    Optional<Path> ruleKeyDiagKeysFile =
        Optional.of(logFile.getParent().resolve(BuckConstant.RULE_KEY_DIAG_KEYS_FILE_NAME))
            .filter(path -> projectFilesystem.isFile(path));

    Optional<Path> ruleKeyDiagGraphFile =
        Optional.of(logFile.getParent().resolve(BuckConstant.RULE_KEY_DIAG_GRAPH_FILE_NAME))
            .filter(path -> projectFilesystem.isFile(path));

    Optional<Path> traceFile =
        projectFilesystem.asView()
            .getFilesUnderPath(logFile.getParent(), EnumSet.of(FileVisitOption.FOLLOW_LINKS))
            .stream()
            .filter(input -> input.toString().endsWith(".trace"))
            .findFirst();

    Optional<Path> configJsonFile =
        Optional.of(logFile.resolveSibling(BuckConstant.CONFIG_JSON_FILE_NAME))
            .filter(projectFilesystem::isFile);

    Optional<Path> fixSpecFile =
        Optional.of(logFile.resolveSibling(BuckConstant.BUCK_FIX_SPEC_FILE_NAME))
            .filter(projectFilesystem::isFile);

    return BuildLogEntry.of(
        logFile,
        buildId,
        commandArgs,
        expandedCommandArgs,
        exitCode.map(OptionalInt::of).orElseGet(OptionalInt::empty),
        buildTimeMs,
        ruleKeyLoggerFile,
        machineReadableLogFile,
        ruleKeyDiagKeysFile,
        ruleKeyDiagGraphFile,
        traceFile,
        configJsonFile,
        fixSpecFile,
        projectFilesystem.getFileSize(logFile),
        Date.from(projectFilesystem.getLastModifiedTime(logFile).toInstant()));
  }
 
源代码18 项目: levelup-java-examples   文件: OptionalIntExample.java
@Test
public void optional_int_orElse() {
	
	OptionalInt optionalInt = OptionalInt.empty();
	
	assertEquals(77, optionalInt.orElse(77), 0);
}
 
源代码19 项目: RichTextFX   文件: CharacterHit.java
/**
 * Returns a {@link CharacterHit} for cases where the insertion occurs outside the bounds of some visible entity
 * (e.g. the area, the paragraph in an area, the line in a paragraph)
 */
public static CharacterHit insertionAt(int insertionIndex) {
    return new CharacterHit(OptionalInt.empty(), insertionIndex);
}
 
源代码20 项目: Strata   文件: FutureValueNotional.java
/**
 * Gets the number of days in the calculation period.
 * <p>
 * This defines the number of days from the adjusted start date to the adjusted end date
 * as calculated by the day count.
 * @return the optional value of the property, not null
 */
public OptionalInt getDayCountDays() {
  return dayCountDays != null ? OptionalInt.of(dayCountDays) : OptionalInt.empty();
}