Example usage for java.util OptionalLong isPresent

List of usage examples for java.util OptionalLong isPresent

Introduction

In this page you can find the example usage for java.util OptionalLong isPresent.

Prototype

boolean isPresent

To view the source code for java.util OptionalLong isPresent.

Click Source Link

Document

If true then the value is present, otherwise indicates no value is present

Usage

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    OptionalLong o = b.min();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {/*from w w w  . ja  va  2 s  .c  o  m*/
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    OptionalLong o = b.max();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {/*from   w w w  .j av  a 2s.c  o  m*/
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    OptionalLong o = b.findAny();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {/*from  w  ww.j a v  a2 s.  co  m*/
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    OptionalLong o = b.findFirst();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {//w  w w .ja va2  s  .c o  m
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, 3L, 4L);

    OptionalLong v = b.reduce(Long::sum);
    if (v.isPresent()) {
        System.out.println(v.getAsLong());
    } else {//from w  w  w . j a  va2  s .  c  om
        System.out.println("no value");
    }

}

From source file:com.kurtraschke.nyctrtproxy.services.TripUpdateProcessor.java

private static boolean expiredTripUpdate(GtfsRealtime.TripUpdate tu, long timestamp) {
    OptionalLong latestTime = tu.getStopTimeUpdateList().stream()
            .map(stu -> stu.hasDeparture() ? stu.getDeparture() : stu.getArrival())
            .filter(GtfsRealtime.TripUpdate.StopTimeEvent::hasTime)
            .mapToLong(GtfsRealtime.TripUpdate.StopTimeEvent::getTime).max();
    return latestTime.isPresent() && latestTime.getAsLong() < timestamp - 300;
}

From source file:com.aba.eveonline.crest.repo.CrestSolarSystemRepository.java

@Override
@Cacheable("solar-system-id")
public Long getSolarSystemId(String systemName) {
    Long result = null;//from w w w  . j  a v  a2s . c  om

    List<CrestSolarSystem> solarSystems = crestService.getLocations();

    //TODO: Look into orElseGet
    OptionalLong systemId = solarSystems.stream()
            .filter(system -> system.getName().equalsIgnoreCase(systemName)).mapToLong(system -> system.getId())
            .findFirst();

    if (systemId.isPresent()) {
        result = systemId.getAsLong();
    }

    return result;
}

From source file:com.aba.eveonline.crest.repo.CrestRegionRepository.java

@Override
@Cacheable("crest-region-id")
public Long findRegionId(String regionName) {
    Long result = null;//from w w  w  .  ja  v  a2 s . c  o m

    //TODO: Look into orElseGet
    OptionalLong regionId = getRegions().stream()
            .filter(region -> region.getName().equalsIgnoreCase(regionName)).mapToLong(region -> region.getId())
            .findFirst();

    if (regionId.isPresent()) {
        result = regionId.getAsLong();
    }

    return result;
}

From source file:org.apache.hadoop.hbase.regionserver.HStoreFile.java

@Override
public String toStringDetailed() {
    StringBuilder sb = new StringBuilder();
    sb.append(this.getPath().toString());
    sb.append(", isReference=").append(isReference());
    sb.append(", isBulkLoadResult=").append(isBulkLoadResult());
    if (isBulkLoadResult()) {
        sb.append(", bulkLoadTS=");
        OptionalLong bulkLoadTS = getBulkLoadTimestamp();
        if (bulkLoadTS.isPresent()) {
            sb.append(bulkLoadTS.getAsLong());
        } else {/*from ww  w  . j a va 2  s .c o m*/
            sb.append("NotPresent");
        }
    } else {
        sb.append(", seqid=").append(getMaxSequenceId());
    }
    sb.append(", majorCompaction=").append(isMajorCompactionResult());

    return sb.toString();
}

From source file:org.apache.nifi.schemaregistry.hortonworks.HortonworksSchemaRegistry.java

private RecordSchema retrieveSchemaByIdAndVersion(final SchemaIdentifier schemaIdentifier)
        throws org.apache.nifi.schema.access.SchemaNotFoundException, IOException {
    final SchemaRegistryClient client = getClient();

    final String schemaName;
    final SchemaVersionInfo versionInfo;

    final OptionalLong schemaId = schemaIdentifier.getIdentifier();
    if (!schemaId.isPresent()) {
        throw new org.apache.nifi.schema.access.SchemaNotFoundException(
                "Cannot retrieve schema because Schema Id is not present");
    }/* ww w .j a  v  a2  s  .c o  m*/

    final OptionalInt version = schemaIdentifier.getVersion();
    if (!version.isPresent()) {
        throw new org.apache.nifi.schema.access.SchemaNotFoundException(
                "Cannot retrieve schema because Schema Version is not present");
    }

    try {
        final SchemaMetadataInfo info = client.getSchemaMetadataInfo(schemaId.getAsLong());
        if (info == null) {
            throw new org.apache.nifi.schema.access.SchemaNotFoundException(
                    "Could not find schema with ID '" + schemaId + "' and version '" + version + "'");
        }

        final SchemaMetadata metadata = info.getSchemaMetadata();
        schemaName = metadata.getName();

        final SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaName, version.getAsInt());
        versionInfo = getSchemaVersionInfo(client, schemaVersionKey);
        if (versionInfo == null) {
            throw new org.apache.nifi.schema.access.SchemaNotFoundException(
                    "Could not find schema with ID '" + schemaId + "' and version '" + version + "'");
        }
    } catch (final Exception e) {
        handleException("Failed to retrieve schema with ID '" + schemaId + "' and version '" + version + "'",
                e);
        return null;
    }

    final String schemaText = versionInfo.getSchemaText();

    final SchemaIdentifier resultSchemaIdentifier = SchemaIdentifier.builder().name(schemaName)
            .id(schemaId.getAsLong()).version(version.getAsInt()).build();

    final Tuple<SchemaIdentifier, String> tuple = new Tuple<>(resultSchemaIdentifier, schemaText);
    return schemaNameToSchemaMap.computeIfAbsent(tuple, t -> {
        final Schema schema = new Schema.Parser().parse(schemaText);
        return AvroTypeUtil.createSchema(schema, schemaText, resultSchemaIdentifier);
    });
}