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

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

源代码1 项目: cxf   文件: ConfigFacade.java
public static OptionalLong getOptionalLong(String propNameFormat, Class<?> clientIntf) {
    Optional<Config> c = config();
    if (c.isPresent()) {
        String propertyName = String.format(propNameFormat, clientIntf.getName());
        Long value = c.get().getOptionalValue(propertyName, Long.class).orElseGet(() -> {
            RegisterRestClient anno = clientIntf.getAnnotation(RegisterRestClient.class);
            if (anno != null && !StringUtils.isEmpty(anno.configKey())) {
                String configKeyPropName = String.format(propNameFormat, anno.configKey());
                return c.get().getOptionalValue(configKeyPropName, Long.class).orElse(null);
            }
            return null;
        });
        return value == null ? OptionalLong.empty() : OptionalLong.of(value);
    }
    return OptionalLong.empty();
}
 
源代码2 项目: presto   文件: TestInformationSchemaTableHandle.java
@Test
public void testInformationSchemaSerialize()
        throws Exception
{
    InformationSchemaTableHandle informationSchemaTableHandle = new InformationSchemaTableHandle(
            "information_schema_catalog",
            COLUMNS,
            ImmutableSet.of(new QualifiedTablePrefix("abc", INFORMATION_SCHEMA)),
            Optional.of(ImmutableSet.of("role")),
            Optional.of(ImmutableSet.of("grantee")),
            OptionalLong.empty());

    assertTrue(objectMapper.canSerialize(InformationSchemaTableHandle.class));
    String json = objectMapper.writeValueAsString(informationSchemaTableHandle);
    testJsonEquals(json, SCHEMA_AS_MAP);
}
 
源代码3 项目: presto   文件: HiveMetadata.java
@Override
public OptionalLong executeDelete(ConnectorSession session, ConnectorTableHandle deleteHandle)
{
    HiveTableHandle handle = (HiveTableHandle) deleteHandle;

    Optional<Table> table = metastore.getTable(new HiveIdentity(session), handle.getSchemaName(), handle.getTableName());
    if (table.isEmpty()) {
        throw new TableNotFoundException(handle.getSchemaTableName());
    }

    if (table.get().getPartitionColumns().isEmpty()) {
        metastore.truncateUnpartitionedTable(session, handle.getSchemaName(), handle.getTableName());
    }
    else {
        for (HivePartition hivePartition : partitionManager.getOrLoadPartitions(metastore, new HiveIdentity(session), handle)) {
            metastore.dropPartition(session, handle.getSchemaName(), handle.getTableName(), toPartitionValues(hivePartition.getPartitionId()), true);
        }
    }
    // it is too expensive to determine the exact number of deleted rows
    return OptionalLong.empty();
}
 
源代码4 项目: jdk8u_jdk   文件: BasicLong.java
@Test(groups = "unit")
public void testEmpty() {
    OptionalLong empty = OptionalLong.empty();
    OptionalLong present = OptionalLong.of(1);

    // empty
    assertTrue(empty.equals(empty));
    assertTrue(empty.equals(OptionalLong.empty()));
    assertTrue(!empty.equals(present));
    assertTrue(0 == empty.hashCode());
    assertTrue(!empty.toString().isEmpty());
    assertTrue(!empty.isPresent());
    empty.ifPresent(v -> { fail(); });
    assertEquals(2, empty.orElse(2));
    assertEquals(2, empty.orElseGet(()-> 2));
}
 
源代码5 项目: jdk8u-jdk   文件: BasicLong.java
@Test(groups = "unit")
public void testEmpty() {
    OptionalLong empty = OptionalLong.empty();
    OptionalLong present = OptionalLong.of(1);

    // empty
    assertTrue(empty.equals(empty));
    assertTrue(empty.equals(OptionalLong.empty()));
    assertTrue(!empty.equals(present));
    assertTrue(0 == empty.hashCode());
    assertTrue(!empty.toString().isEmpty());
    assertTrue(!empty.isPresent());
    empty.ifPresent(v -> { fail(); });
    assertEquals(2, empty.orElse(2));
    assertEquals(2, empty.orElseGet(()-> 2));
}
 
源代码6 项目: java-dcp-client   文件: CollectionCreated.java
public CollectionCreated(int vbucket, long seqno, int version, ByteBuf buffer) {
  super(Type.COLLECTION_CREATED, vbucket, seqno, version);

  collectionName = MessageUtil.getKeyAsString(buffer);
  ByteBuf value = MessageUtil.getContent(buffer);

  newManifestId = value.readLong();
  scopeId = value.readUnsignedInt();
  collectionId = value.readUnsignedInt();

  // absent in version 0
  maxTtl = value.isReadable() ? OptionalLong.of(value.readUnsignedInt()) : OptionalLong.empty();
}
 
源代码7 项目: core-ng-project   文件: DatabaseOperation.java
private OptionalLong fetchGeneratedKey(PreparedStatement statement) throws SQLException {
    try (ResultSet keys = statement.getGeneratedKeys()) {
        if (keys.next()) {
            return OptionalLong.of(keys.getLong(1));
        }
    }
    return OptionalLong.empty();
}
 
源代码8 项目: openjdk-jdk9   文件: HttpHeadersImpl.java
@Override
public OptionalLong firstValueAsLong(String name) {
    List<String> l = headers.get(name);
    if (l == null) {
        return OptionalLong.empty();
    } else {
        String v = l.get(0);
        return OptionalLong.of(Long.parseLong(v));
    }
}
 
源代码9 项目: caffeine   文件: BoundedLocalCache.java
@Override public OptionalLong weightedSize() {
  if (cache.evicts() && isWeighted()) {
    cache.evictionLock.lock();
    try {
      return OptionalLong.of(Math.max(0, cache.weightedSize()));
    } finally {
      cache.evictionLock.unlock();
    }
  }
  return OptionalLong.empty();
}
 
源代码10 项目: rheem   文件: Configuration.java
public OptionalLong getOptionalLongProperty(String key) {
    final Optional<String> longValue = this.properties.optionallyProvideFor(key);
    if (longValue.isPresent()) {
        return OptionalLong.of(Long.valueOf(longValue.get()));
    } else {
        return OptionalLong.empty();
    }
}
 
源代码11 项目: bifurcan   文件: ISortedMap.java
@Override
default OptionalLong indexOf(K key) {
  OptionalLong idx = floorIndex(key);
  return idx.isPresent() && comparator().compare(key, nth(idx.getAsLong()).key()) == 0
      ? idx
      : OptionalLong.empty();
}
 
源代码12 项目: jdk8u-jdk   文件: BasicLong.java
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(ObscureException::new);
}
 
源代码13 项目: jdk8u-dev-jdk   文件: BasicLong.java
@Test(expectedExceptions=NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(null);
}
 
源代码14 项目: j2objc   文件: ReduceOps.java
/**
 * Constructs a {@code TerminalOp} that implements a functional reduce on
 * {@code long} values, producing an optional long result.
 *
 * @param operator the combining function
 * @return a {@code TerminalOp} implementing the reduction
 */
public static TerminalOp<Long, OptionalLong>
makeLong(LongBinaryOperator operator) {
    Objects.requireNonNull(operator);
    class ReducingSink
            implements AccumulatingSink<Long, OptionalLong, ReducingSink>, Sink.OfLong {
        private boolean empty;
        private long state;

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

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

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

        @Override
        public void combine(ReducingSink other) {
            if (!other.empty)
                accept(other.state);
        }
    }
    return new ReduceOp<Long, OptionalLong, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
源代码15 项目: buck   文件: RemoteExecutionStrategyTest.java
@Override
public OptionalLong largeBlobSizeBytes() {
  return OptionalLong.empty();
}
 
源代码16 项目: presto   文件: HiveBasicStatistics.java
public static HiveBasicStatistics createEmptyStatistics()
{
    return new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty());
}
 
源代码17 项目: hottub   文件: BasicLong.java
@Test(expectedExceptions=ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(ObscureException::new);
}
 
public SeqnoAndVbucketUuid(long seqno, Long vbucketUuid) {
  this.seqno = seqno;
  this.vbucketUuid = vbucketUuid == null ? OptionalLong.empty() : OptionalLong.of(vbucketUuid);
}
 
源代码19 项目: sis   文件: AbstractFeatureSet.java
/**
 * Returns an estimation of the number of features in this set, or empty if unknown.
 * The default implementation returns an empty value.
 *
 * @return estimation of the number of features.
 */
protected OptionalLong getFeatureCount() {
    return OptionalLong.empty();
}
 
源代码20 项目: hottub   文件: FindOps.java
/**
 * Constructs a {@code TerminalOp} for streams of longs.
 *
 * @param mustFindFirst whether the {@code TerminalOp} must produce the
 *        first element in the encounter order
 * @return a {@code TerminalOp} implementing the find operation
 */
public static TerminalOp<Long, OptionalLong> makeLong(boolean mustFindFirst) {
    return new FindOp<>(mustFindFirst, StreamShape.LONG_VALUE, OptionalLong.empty(),
                        OptionalLong::isPresent, FindSink.OfLong::new);
}