Example usage for java.util.stream LongStream of

List of usage examples for java.util.stream LongStream of

Introduction

In this page you can find the example usage for java.util.stream LongStream of.

Prototype

public static LongStream of(long... values) 

Source Link

Document

Returns a sequential ordered stream whose elements are the specified values.

Usage

From source file:Main.java

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

    b.forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5");

    stringList.stream().flatMapToLong(n -> LongStream.of(Long.parseLong(n))).forEach(System.out::println);
}

From source file:com.google.pubsub.flic.common.LatencyDistribution.java

private static int getNthPercentileIndex(long[] bucketValues, double percentile) {
    Preconditions.checkArgument(percentile > 0.0);
    Preconditions.checkArgument(percentile < 100.0);
    long total = LongStream.of(bucketValues).sum();
    if (total == 0) {
        return 0;
    }/*from  ww  w .  j  a  v  a 2s .  c  om*/
    long count = (long) (total * percentile / 100.0);
    for (int i = LATENCY_BUCKETS.length - 1; i > 0; i--) {
        total -= bucketValues[i];
        if (total < count) {
            return i;
        }
    }
    return -1;
}

From source file:io.woolford.processors.nifibenford.BenfordsLaw.java

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();/*  ww  w.ja v  a 2s  .  co  m*/
    if (flowFile == null) {
        return;
    }

    InputStream inputStream = session.read(flowFile);
    String input = new BufferedReader(new InputStreamReader(inputStream)).lines()
            .collect(Collectors.joining("\n"));

    // TODO: since the values returned by Benford's array don't ever change, these could be hard-coded rather than calling a function each time.
    double[] benfordsArray = getBenfordsArray();
    long[] firstDigitArray = getFirstDigitArray(input);

    long sampleSize = LongStream.of(firstDigitArray).sum();

    ChiSquareTest chiSquareTest = new ChiSquareTest();
    Boolean suspect = chiSquareTest.chiSquareTest(benfordsArray, firstDigitArray,
            context.getProperty(ALPHA).asDouble());

    //TODO: don't perform the chi-squared test if the sample is too small
    if (sampleSize < context.getProperty(MIN_SAMPLE).asLong()) {
        session.transfer(flowFile, INSUFFICIENT_SAMPLE);
    } else if (suspect) {
        session.transfer(flowFile, NON_CONFORMING);
    } else {
        session.transfer(flowFile, CONFORMING);
    }

}