Example usage for java.util OptionalLong getAsLong

List of usage examples for java.util OptionalLong getAsLong

Introduction

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

Prototype

public long getAsLong() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

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   ww  w  . j a  va2 s  .com*/
        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 {//  w w  w.j  a v  a 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.findAny();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {/*from w  ww  .  j av a2 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.findFirst();

    if (o.isPresent()) {
        System.out.println(o.getAsLong());
    } else {/* ww w .j  a v a 2  s. c om*/
        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 {// w  w  w  .j  av a  2s. 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 ww w . j  ava  2s. c  o  m*/

    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 .j a  v a  2 s .c  om*/

    //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  av  a2s. com
            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");
    }/*w w  w.j a v  a2  s . co  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);
    });
}