Example usage for com.google.common.collect Range closed

List of usage examples for com.google.common.collect Range closed

Introduction

In this page you can find the example usage for com.google.common.collect Range closed.

Prototype

public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) 

Source Link

Document

Returns a range that contains all values greater than or equal to lower and less than or equal to upper .

Usage

From source file:io.github.mzmine.util.FeatureTableUtil.java

/**
 * <p>//w w  w.  ja va 2s. c  o  m
 * getFeatureRt1Range.
 * </p>
 *
 * @param row a {@link io.github.msdk.datamodel.featuretables.FeatureTableRow} object.
 * @return a {@link com.google.common.collect.Range} object.
 */
public static Range<Float> getFeatureRt1Range(FeatureTableRow row) {
    FeatureTable featureTable = row.getFeatureTable();
    FeatureTableColumn<Float> column;
    float min = 0f;
    float max = 0f;

    for (Sample sample : featureTable.getSamples()) {
        column = featureTable.getColumn(ColumnName.RT, sample);
        if (column != null) {
            if (row.getData(column) != null) {
                Float rt = row.getData(column);
                if (rt != null) {
                    if (rt < min || min == 0d)
                        min = rt;
                    if (rt > max || max == 0d)
                        max = rt;
                }
            }
        }
    }

    return Range.closed(min, max);
}

From source file:org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyFlatBatchImpl.java

static Map<Range<Integer>, Batch> mapBatchesToRanges(final List<Batch> inputBatchBag,
        final int failureIndexLimit) {
    final Map<Range<Integer>, Batch> batchMap = new LinkedHashMap<>();
    final PeekingIterator<Batch> batchPeekingIterator = Iterators.peekingIterator(inputBatchBag.iterator());
    while (batchPeekingIterator.hasNext()) {
        final Batch batch = batchPeekingIterator.next();
        final int nextBatchOrder = batchPeekingIterator.hasNext() ? batchPeekingIterator.peek().getBatchOrder()
                : failureIndexLimit;//  ww  w . j  a v  a 2s. co m
        batchMap.put(Range.closed(batch.getBatchOrder(), nextBatchOrder - 1), batch);
    }
    return batchMap;
}

From source file:io.github.msdk.util.FeatureTableUtil.java

/**
 * <p>getFeatureMzRange.</p>
 *
 * @param row a {@link io.github.msdk.datamodel.featuretables.FeatureTableRow} object.
 * @return a {@link com.google.common.collect.Range} object.
 *///from w  w w. j a  va 2 s  .  c  om
public static Range<Double> getFeatureMzRange(FeatureTableRow row) {
    FeatureTable featureTable = row.getFeatureTable();
    FeatureTableColumn<?> column;
    double min = 0d;
    double max = 0d;

    for (Sample sample : featureTable.getSamples()) {
        column = featureTable.getColumn(ColumnName.MZ, sample);
        if (column != null) {
            if (row.getData(column) != null) {
                double mz = (double) row.getData(column);
                if (mz < min || min == 0d)
                    min = mz;
                if (mz > max || max == 0d)
                    max = mz;
            }
        }
    }

    return Range.closed(min, max);
}

From source file:org.eclipse.fx.ui.controls.styledtext.internal.ContentView.java

private void bindCaretListener() {
    this.caretOffset.addListener((x, o, n) -> {
        int oldCaretLine = getContent().getLineAtOffset(o.intValue());
        int newCaretLine = getContent().getLineAtOffset(n.intValue());

        RangeSet<Integer> toUpdate = TreeRangeSet.create();
        toUpdate.add(Range.closed(Integer.valueOf(oldCaretLine), Integer.valueOf(oldCaretLine)));
        toUpdate.add(Range.closed(Integer.valueOf(newCaretLine), Integer.valueOf(newCaretLine)));

        updateNodesNow(toUpdate);/*from  w ww.  j  a  v a2  s  . c  om*/
    });
}

From source file:org.eclipse.fx.ui.controls.styledtext.internal.ContentView.java

private Range<Integer> getAffectedLines(TextSelection selection) {
    int firstLine = getContent().getLineAtOffset(selection.offset);
    int lastLine = getContent().getLineAtOffset(selection.offset + selection.length);
    if (lastLine == -1) {
        lastLine = this.numberOfLines.get();
    }//from   ww w  . ja v a 2 s . c  om
    return Range.closed(Integer.valueOf(firstLine),
            Integer.valueOf(Math.min(lastLine, this.numberOfLines.get())));
}

From source file:io.github.msdk.util.FeatureTableUtil.java

/**
 * <p>getFeatureRt1Range.</p>
 *
 * @param row a {@link io.github.msdk.datamodel.featuretables.FeatureTableRow} object.
 * @return a {@link com.google.common.collect.Range} object.
 *//*from   w ww .  ja va2 s  .  co m*/
public static Range<Float> getFeatureRt1Range(FeatureTableRow row) {
    FeatureTable featureTable = row.getFeatureTable();
    FeatureTableColumn<ChromatographyInfo> column;
    float min = 0f;
    float max = 0f;

    for (Sample sample : featureTable.getSamples()) {
        column = featureTable.getColumn(ColumnName.RT, sample);
        if (column != null) {
            if (row.getData(column) != null) {
                ChromatographyInfo chromatographyInfo = row.getData(column);
                if (chromatographyInfo.getRetentionTime() != null) {
                    float rt = (float) chromatographyInfo.getRetentionTime();
                    if (rt < min || min == 0d)
                        min = rt;
                    if (rt > max || max == 0d)
                        max = rt;
                }
            }
        }
    }

    return Range.closed(min, max);
}

From source file:net.sf.mzmine.util.ScanUtils.java

/**
 * Find the m/z range of the data points in the array. We assume there is at
 * least one data point, and the data points are sorted by m/z.
 *//*from   www  .  j  a  v  a 2s . c o  m*/
public static @Nonnull Range<Double> findMzRange(@Nonnull DataPoint dataPoints[]) {

    assert dataPoints.length > 0;

    double lowMz = dataPoints[0].getMZ();
    double highMz = lowMz;
    for (int i = 1; i < dataPoints.length; i++) {
        if (dataPoints[i].getMZ() < lowMz) {
            lowMz = dataPoints[i].getMZ();
            continue;
        }
        if (dataPoints[i].getMZ() > highMz)
            highMz = dataPoints[i].getMZ();
    }

    return Range.closed(lowMz, highMz);
}

From source file:net.sf.mzmine.util.ScanUtils.java

/**
 * Find the RT range of given scans. We assume there is at least one scan.
 *///from w w  w .j a v a2s. co m
public static @Nonnull Range<Double> findRtRange(@Nonnull Scan scans[]) {

    assert scans.length > 0;

    double lowRt = scans[0].getRetentionTime();
    double highRt = lowRt;
    for (int i = 1; i < scans.length; i++) {
        if (scans[i].getRetentionTime() < lowRt) {
            lowRt = scans[i].getRetentionTime();
            continue;
        }
        if (scans[i].getRetentionTime() > highRt) {
            highRt = scans[i].getRetentionTime();
        }
    }

    return Range.closed(lowRt, highRt);
}

From source file:zipkin.storage.cassandra3.CassandraSpanStore.java

ListenableFuture<Map<TraceIdUDT, Long>> getTraceIdsByServiceNames(QueryRequest request) {
    long oldestData = indexTtl == 0 ? 0 : (System.currentTimeMillis() - indexTtl * 1000);
    long startTsMillis = Math.max((request.endTs - request.lookback), oldestData);
    long endTsMillis = Math.max(request.endTs, oldestData);

    try {/*from w ww  . j  av a2  s  .  com*/
        Set<String> serviceNames;
        if (null != request.serviceName) {
            serviceNames = Collections.singleton(request.serviceName);
        } else {
            serviceNames = new LinkedHashSet<>(getServiceNames().get());
            if (serviceNames.isEmpty()) {
                return immediateFuture(Collections.<TraceIdUDT, Long>emptyMap());
            }
        }

        int startBucket = CassandraUtil.durationIndexBucket(startTsMillis * 1000);
        int endBucket = CassandraUtil.durationIndexBucket(endTsMillis * 1000);
        if (startBucket > endBucket) {
            throw new IllegalArgumentException(
                    "Start bucket (" + startBucket + ") > end bucket (" + endBucket + ")");
        }
        Set<Integer> buckets = ContiguousSet.create(Range.closed(startBucket, endBucket), integers());
        boolean withDuration = null != request.minDuration || null != request.maxDuration;
        List<ListenableFuture<Map<TraceIdUDT, Long>>> futures = new ArrayList<>();

        if (200 < serviceNames.size() * buckets.size()) {
            LOG.warn("read against " + TABLE_TRACE_BY_SERVICE_SPAN + " fanning out to "
                    + serviceNames.size() * buckets.size() + " requests");
            //@xxx the fan-out of requests here can be improved
        }

        for (String serviceName : serviceNames) {
            for (Integer bucket : buckets) {
                BoundStatement bound = CassandraUtil
                        .bindWithName(withDuration ? selectTraceIdsByServiceSpanNameAndDuration
                                : selectTraceIdsByServiceSpanName, "select-trace-ids-by-service-name")
                        .setString("service_name", serviceName)
                        .setString("span_name", null != request.spanName ? request.spanName : "")
                        .setInt("bucket", bucket).setUUID("start_ts", UUIDs.startOf(startTsMillis))
                        .setUUID("end_ts", UUIDs.endOf(endTsMillis)).setInt("limit_", request.limit);

                if (withDuration) {
                    bound = bound
                            .setLong("start_duration", null != request.minDuration ? request.minDuration : 0)
                            .setLong("end_duration",
                                    null != request.maxDuration ? request.maxDuration : Long.MAX_VALUE);
                }
                bound.setFetchSize(Integer.MAX_VALUE);
                futures.add(transform(session.executeAsync(bound), traceIdToTimestamp));
            }
        }

        return transform(allAsList(futures), collapseTraceIdMaps);
    } catch (RuntimeException | InterruptedException | ExecutionException ex) {
        return immediateFailedFuture(ex);
    }
}

From source file:view.FXApplicationController.java

private void calculatePercentageKComplex() {

    double percentageSum = 0.0;
    RangeSet<Double> rangeset = TreeRangeSet.create();

    for (int i = 0; i < lines.size(); i++) {
        Line line = lines.get(i);

        double lengthOfLine;

        Range r = Range.closed(
                Math.min(line.getLayoutX(), line.getEndX() + line.getLayoutX()) / xAxis.getWidth() * 100.
                        - 1e-9,//from  ww w  .j a  va2  s .c  o  m
                Math.max(line.getLayoutX(), line.getEndX() + line.getLayoutX()) / xAxis.getWidth() * 100.
                        + 1e-9);

        rangeset.add(r);

    }

    percentageSum = rangeset.asRanges().stream().mapToDouble(e -> (e.upperEndpoint() - e.lowerEndpoint()))
            .sum();

    kComplexLabel.setText("K-Complex: " + Math.round(percentageSum) + "%");
}