Java Code Examples for java.util.OptionalLong#empty()

The following examples show how to use java.util.OptionalLong#empty() . 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: BasicLong.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 2
Source File: BasicLong.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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));
}
 
Example 3
Source File: ConfigFacade.java    From cxf with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: HiveMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 5
Source File: TestInformationSchemaTableHandle.java    From presto with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 6
Source File: CollectionCreated.java    From java-dcp-client with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: ISortedMap.java    From bifurcan with MIT License 5 votes vote down vote up
@Override
default OptionalLong indexOf(K key) {
  OptionalLong idx = floorIndex(key);
  return idx.isPresent() && comparator().compare(key, nth(idx.getAsLong()).key()) == 0
      ? idx
      : OptionalLong.empty();
}
 
Example 8
Source File: Configuration.java    From rheem with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 9
Source File: BoundedLocalCache.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 10
Source File: HttpHeadersImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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));
    }
}
 
Example 11
Source File: DatabaseOperation.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
private OptionalLong fetchGeneratedKey(PreparedStatement statement) throws SQLException {
    try (ResultSet keys = statement.getGeneratedKeys()) {
        if (keys.next()) {
            return OptionalLong.of(keys.getLong(1));
        }
    }
    return OptionalLong.empty();
}
 
Example 12
Source File: RemoteExecutionStrategyTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public OptionalLong largeBlobSizeBytes() {
  return OptionalLong.empty();
}
 
Example 13
Source File: ReduceOps.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
        }
    };
}
 
Example 14
Source File: HiveBasicStatistics.java    From presto with Apache License 2.0 4 votes vote down vote up
public static HiveBasicStatistics createEmptyStatistics()
{
    return new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty(), OptionalLong.empty());
}
 
Example 15
Source File: BasicLong.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 {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(null);
}
 
Example 16
Source File: BasicLong.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 {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(ObscureException::new);
}
 
Example 17
Source File: BasicLong.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 {
    OptionalLong empty = OptionalLong.empty();

    long got = empty.orElseThrow(ObscureException::new);
}
 
Example 18
Source File: SeqnoAndVbucketUuid.java    From kafka-connect-couchbase with Apache License 2.0 4 votes vote down vote up
public SeqnoAndVbucketUuid(long seqno, Long vbucketUuid) {
  this.seqno = seqno;
  this.vbucketUuid = vbucketUuid == null ? OptionalLong.empty() : OptionalLong.of(vbucketUuid);
}
 
Example 19
Source File: FindOps.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: AbstractFeatureSet.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}