Example usage for java.lang Integer max

List of usage examples for java.lang Integer max

Introduction

In this page you can find the example usage for java.lang Integer max.

Prototype

public static int max(int a, int b) 

Source Link

Document

Returns the greater of two int values as if by calling Math#max(int,int) Math.max .

Usage

From source file:Main.java

public static void main(String... args) {
    List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2);

    int max = numbers.stream().reduce(0, (a, b) -> Integer.max(a, b));
    System.out.println(max);/*from w  w  w  .  j a  va2 s. c om*/

}

From source file:io.pravega.controller.store.stream.tables.IndexRecord.java

public static Optional<IndexRecord> readLatestRecord(final byte[] indexTable) {
    final int lastIndexedRecordOffset = Integer.max(indexTable.length - IndexRecord.INDEX_RECORD_SIZE, 0);

    return readRecord(indexTable, lastIndexedRecordOffset);
}

From source file:ch.cyberduck.core.worker.ConcurrentTransferWorker.java

public ConcurrentTransferWorker(final ConnectionService connect, final Transfer transfer,
        final TransferOptions options, final TransferSpeedometer meter, final TransferPrompt prompt,
        final TransferErrorCallback error, final TransferItemCallback transferItemCallback,
        final ConnectionCallback connectionCallback, final ProgressListener progressListener,
        final StreamListener streamListener, final X509TrustManager trust, final X509KeyManager key,
        final PathCache cache, final Integer connections) {
    super(transfer, options, prompt, meter, error, transferItemCallback, progressListener, streamListener,
            connectionCallback);/* w  w  w  . j ava2 s  .  co  m*/
    final GenericObjectPoolConfig configuration = new GenericObjectPoolConfig() {
        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("GenericObjectPoolConfig{");
            sb.append("connections=").append(connections);
            sb.append('}');
            return sb.toString();
        }
    };
    configuration.setJmxEnabled(false);
    configuration.setMinIdle(0);
    configuration.setMaxTotal(connections);
    configuration.setMaxIdle(connections);
    configuration.setBlockWhenExhausted(true);
    configuration.setMaxWaitMillis(BORROW_MAX_WAIT_INTERVAL);
    progress = progressListener;
    retry = Integer.max(PreferencesFactory.get().getInteger("connection.retry"), connections);
    pool = new GenericObjectPool<Session>(new SessionPool(connect, trust, key, cache, transfer.getHost()),
            configuration) {
        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder("GenericObjectPool{");
            sb.append("configuration=").append(configuration);
            sb.append('}');
            return sb.toString();
        }
    };
    completion = new DefaultThreadPool<TransferStatus>(connections, "transfer");
}

From source file:com.github.lynxdb.server.core.Aggregator.java

protected TimeSerie doInterpolate(List<TimeSerie> _series, Reducer _reducer) {
    Assert.notEmpty(_series);//from ww  w .  j  a  va  2  s  .  c o  m

    List<SuperIterator> sil = new ArrayList<>();

    _series.forEach((TimeSerie t) -> {
        if (t.hasNext()) {
            SuperIterator<Entry> si = new SuperIterator<>(t);
            si.next();
            sil.add(si);
        }
    });

    Map<String, String> tags = new HashMap<>();
    tags.putAll(_series.get(0).getTags());

    _series.forEach((TimeSerie t) -> {
        Iterator<Map.Entry<String, String>> i = tags.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, String> e = i.next();
            if (!t.getTags().containsKey(e.getKey()) || !t.getTags().get(e.getKey()).equals(e.getValue())) {
                i.remove();
            }

        }
    });

    return new TimeSerie(_series.get(0).getName(), tags, new ChainableIterator<Entry>() {

        @Override
        public boolean hasNext() {
            return sil.stream().anyMatch((SuperIterator t) -> t.hasNext() || t.getCurrent() != null);
        }

        @Override
        public Entry next() {
            _reducer.reset();

            Iterator<SuperIterator> rr = sil.iterator();
            while (rr.hasNext()) {
                if (rr.next().getCurrent() == null) {
                    rr.remove();
                }
            }

            int max = Integer.MIN_VALUE;

            for (SuperIterator<Entry> r : sil) {
                max = Integer.max(max, r.getCurrent().getTime());
            }

            for (SuperIterator<Entry> r : sil) {
                if (r.getCurrent().getTime() == max) {
                    _reducer.update(r.getCurrent());
                    r.next();
                } else if (r.getPrevious() != null) {
                    _reducer.update(new Entry(max, interpolate(r.getCurrent(), r.getPrevious(), max)));
                }
            }
            return new Entry(max, _reducer.result());
        }
    });
}

From source file:com.github.lynxdb.server.core.Aggregator.java

protected TimeSerie doDefaultIfMissing(List<TimeSerie> _series, Reducer _reducer, double _default) {
    Assert.notEmpty(_series);//from  w w  w .j  a va 2 s  .com

    List<SuperIterator> sil = new ArrayList<>();

    _series.forEach((TimeSerie t) -> {
        if (t.hasNext()) {
            SuperIterator<Entry> si = new SuperIterator<>(t);
            si.next();
            sil.add(si);
        }
    });

    Map<String, String> tags = new HashMap<>();
    tags.putAll(_series.get(0).getTags());

    _series.forEach((TimeSerie t) -> {
        Iterator<Map.Entry<String, String>> i = tags.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry<String, String> e = i.next();
            if (!t.getTags().containsKey(e.getKey()) || !t.getTags().get(e.getKey()).equals(e.getValue())) {
                i.remove();
            }

        }
    });

    return new TimeSerie(_series.get(0).getName(), tags, new ChainableIterator<Entry>() {

        @Override
        public boolean hasNext() {
            return sil.stream().anyMatch((SuperIterator t) -> t.hasNext() || t.getCurrent() != null);
        }

        @Override
        public Entry next() {
            _reducer.reset();

            Iterator<SuperIterator> rr = sil.iterator();
            while (rr.hasNext()) {
                if (rr.next().getCurrent() == null) {
                    rr.remove();
                }
            }

            int max = Integer.MIN_VALUE;

            for (SuperIterator<Entry> r : sil) {
                max = Integer.max(max, r.getCurrent().getTime());
            }

            for (SuperIterator<Entry> r : sil) {
                if (r.getCurrent().getTime() == max) {
                    _reducer.update(r.getCurrent());
                    r.next();
                } else if (r.getPrevious() != null) {
                    _reducer.update(new Entry(max, _default));
                }
            }
            return new Entry(max, _reducer.result());
        }
    });
}

From source file:org.ncic.bioinfo.sparkseq.algorithms.data.sam.IntervalLocusSamTraverser.java

private List<GenomeLoc> getOverlappedIntervals(GenomeLoc refLocus, List<GenomeLoc> rawTraverseIntervals) {
    // intervalsrefLocus??
    if (CollectionUtils.isEmpty(rawTraverseIntervals)) {
        List<GenomeLoc> singleGenomeLoc = new ArrayList<>(1);
        singleGenomeLoc.add(refLocus);/*from  w w  w. j  a va2s  .  co m*/
        return singleGenomeLoc;
    }

    List<GenomeLoc> rawOverlappedIntervals = rawTraverseIntervals.stream()
            .filter(interval -> interval.overlapsP(refLocus))
            .map(interval -> new GenomeLoc(interval.getContig(), interval.getContigIndex(),
                    (interval.getStart() - OVERLAP_LEN) < refLocus.getStart() ? refLocus.getStart()
                            : (interval.getStart() - OVERLAP_LEN),
                    (interval.getStop() + OVERLAP_LEN) > refLocus.getStop() ? refLocus.getStop()
                            : (interval.getStop() + OVERLAP_LEN)))
            .collect(Collectors.toList());

    Collections.sort(rawOverlappedIntervals,
            (interval1, interval2) -> interval1.getStart() - interval2.getStart());

    //?intervals
    List<GenomeLoc> finalIntervals = new ArrayList<>();
    GenomeLoc tmpInterval = null;
    for (GenomeLoc interval : rawOverlappedIntervals) {
        if (tmpInterval == null) {
            tmpInterval = interval;
        } else {
            if (tmpInterval.overlapsP(interval)) {
                tmpInterval = new GenomeLoc(tmpInterval.getContig(), tmpInterval.getContigIndex(),
                        Integer.min(tmpInterval.getStart(), interval.getStart()),
                        Integer.max(tmpInterval.getStop(), interval.getStop()));
            } else {
                finalIntervals.add(tmpInterval);
                tmpInterval = interval;
            }
        }
    }
    if (tmpInterval != null) {
        finalIntervals.add(tmpInterval);
    }

    return finalIntervals;
}