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:org.caleydo.view.table.TableView.java

private void showJustSelection() {
    rowHidder.showAllRows(); // show all by default

    // find out, which rows should be visible
    Collection<Integer> toKeep = new ArrayList<>();
    for (Integer id : selection.getRecordSelectionManager().getElements(SelectionType.SELECTION)) {
        int index = data.indexOfRowObject(id);
        if (index < 0)
            continue;
        int position = rowHidder.getRowPositionByIndex(index);
        if (position < 0)
            continue;
        toKeep.add(position);/*  w w  w. ja  v  a 2 s .c  o m*/
    }
    if (!toKeep.isEmpty()) { // at least one visible otherwise show all
        // all - visible = those to hide

        Set<Integer> all = new HashSet<>(ContiguousSet.create(Range.closed(rowHidder.getRowPositionByIndex(0),
                rowHidder.getRowPositionByIndex(data.getRowCount() - 1)), DiscreteDomain.integers()));
        all.removeAll(toKeep);
        rowHidder.hideRowPositions(all);
    }

    columnHidder.showAllColumns();
    toKeep.clear();
    for (Integer id : selection.getDimensionSelectionManager().getElements(SelectionType.SELECTION)) {
        int index = data.indexOfColumnObject(id);
        if (index < 0)
            continue;
        int position = columnHidder.getColumnPositionByIndex(index);
        if (position < 0)
            continue;
        toKeep.add(position);
    }
    if (!toKeep.isEmpty()) {
        Set<Integer> all = new HashSet<>(ContiguousSet.create(
                Range.closed(columnHidder.getColumnPositionByIndex(0),
                        columnHidder.getColumnPositionByIndex(data.getColumnCount() - 1)),
                DiscreteDomain.integers()));
        all.removeAll(toKeep);
        columnHidder.hideColumnPositions(all);
    }
}

From source file:com.squareup.wire.schema.internal.parser.ProtoParser.java

/** Reads a reserved tags and names list like "reserved 10, 12 to 14, 'foo';". */
private ReservedElement readReserved(Location location, String documentation) {
    ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();

    while (true) {
        char c = peekChar();
        if (c == '"' || c == '\'') {
            valuesBuilder.add(readQuotedString());
        } else {//from   ww w .  j a v  a  2 s  .c o m
            int tagStart = readInt();

            c = peekChar();
            if (c != ',' && c != ';') {
                if (!readWord().equals("to")) {
                    throw unexpected("expected ',', ';', or 'to'");
                }
                int tagEnd = readInt();
                valuesBuilder.add(Range.closed(tagStart, tagEnd));
            } else {
                valuesBuilder.add(tagStart);
            }
        }
        c = readChar();
        if (c == ';')
            break;
        if (c != ',')
            throw unexpected("expected ',' or ';'");
    }

    ImmutableList<Object> values = valuesBuilder.build();
    if (values.isEmpty()) {
        throw unexpected("'reserved' must have at least one field name or tag");
    }
    return ReservedElement.create(location, documentation, values);
}

From source file:org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.java

@Override
public void asyncGetNthEntry(int N, IndividualDeletedEntries deletedEntries, ReadEntryCallback callback,
        Object ctx) {/*  w  ww.ja va 2 s . c  om*/
    checkArgument(N > 0);
    if (STATE_UPDATER.get(this) == State.Closed) {
        callback.readEntryFailed(new ManagedLedgerException("Cursor was already closed"), ctx);
        return;
    }

    PositionImpl startPosition = ledger.getNextValidPosition(markDeletePosition);
    PositionImpl endPosition = ledger.getLastPosition();
    if (startPosition.compareTo(endPosition) <= 0) {
        long numOfEntries = getNumberOfEntries(Range.closed(startPosition, endPosition));
        if (numOfEntries >= N) {
            long deletedMessages = 0;
            if (deletedEntries == IndividualDeletedEntries.Exclude) {
                deletedMessages = getNumIndividualDeletedEntriesToSkip(N);
            }
            PositionImpl positionAfterN = ledger.getPositionAfterN(markDeletePosition, N + deletedMessages,
                    PositionBound.startExcluded);
            ledger.asyncReadEntry(positionAfterN, callback, ctx);
        } else {
            callback.readEntryComplete(null, ctx);
        }
    } else {
        callback.readEntryComplete(null, ctx);
    }
}

From source file:ddf.catalog.filter.impl.SimpleFilterDelegate.java

public T during(String propertyName, Date startDate, Date endDate) {

    return temporalOperation(propertyName, Range.closed(startDate, endDate), Range.class,
            TemporalPropertyOperation.DURING);
}

From source file:com.b2international.snowowl.snomed.core.ecl.SnomedEclRefinementEvaluator.java

/**
 * Evaluates attribute refinements. /*  www  .j  av a  2 s.c  om*/
 * @param context - the branch where the evaluation should happen
 * @param refinement - the refinement itself
 * @param grouped - whether the refinement should consider groups
 * @param groupCardinality - the cardinality to use when grouped parameter is <code>true</code>
 * @return a {@link Collection} of {@link Property} objects that match the parameters
 */
private Promise<Collection<Property>> evalRefinement(final BranchContext context,
        final AttributeConstraint refinement, final boolean grouped, final Range<Long> groupCardinality) {
    final Cardinality cardinality = refinement.getCardinality();
    // the default cardinality is [1..*]
    final boolean isUnbounded = cardinality == null ? true : cardinality.getMax() == UNBOUNDED_CARDINALITY;
    final long min = cardinality == null ? 1 : cardinality.getMin();
    final long max = isUnbounded ? Long.MAX_VALUE : cardinality.getMax();

    final Range<Long> propertyCardinality;
    if (min == 0) {
        if (isUnbounded) {
            // zero and unbounded attributes, just match all focus concepts using the focusConcept IDs
            return Promise.fail(new MatchAll());
        } else {
            // zero bounded attributes should eval to BOOL(MUST(focus) MUST_NOT(max+1))
            propertyCardinality = Range.closed(max + 1, Long.MAX_VALUE);
        }
    } else {
        // use cardinality range specified in the expression
        propertyCardinality = Range.closed(min, max);
    }
    final Function<Property, Object> idProvider = refinement.isReversed() ? Property::getValue
            : Property::getObjectId;
    final Set<String> focusConceptIds = focusConcepts.isAnyExpression() ? Collections.emptySet()
            : grouped ? focusConcepts.resolveToConceptsWithGroups(context).getSync().keySet()
                    : focusConcepts.resolve(context).getSync();
    return evalRefinement(context, refinement, grouped, focusConceptIds)
            .then(filterByCardinality(grouped, groupCardinality, propertyCardinality, idProvider));
}

From source file:net.sf.mzmine.modules.visualization.peaklisttable.PeakListTablePopupMenu.java

/**
 * Get a peak's m/z range./* ww  w. j a v  a 2 s.c o m*/
 * 
 * @param peak
 *            the peak.
 * @return The peak's m/z range.
 */
private static Range<Double> getPeakMZRange(final Feature peak) {

    final Range<Double> peakMZRange = peak.getRawDataPointsMZRange();

    // By default, open the visualizer with the m/z range of
    // "peak_width x 2", but no smaller than 0.1 m/z, because with smaller
    // ranges VisAD tends to show nasty anti-aliasing artifacts.
    // For example of such artifacts, set mzMin = 440.27, mzMax = 440.28 and
    // mzResolution = 500
    final double minRangeCenter = (peakMZRange.upperEndpoint() + peakMZRange.lowerEndpoint()) / 2.0;
    final double minRangeWidth = Math.max(0.1, (peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint()) * 2);
    double mzMin = minRangeCenter - (minRangeWidth / 2);
    if (mzMin < 0)
        mzMin = 0;
    double mzMax = minRangeCenter + (minRangeWidth / 2);
    return Range.closed(mzMin, mzMax);
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventDetailsChart.java

/**
 * layout the nodes in the given list, starting form the given minimum y
 * coordinate.//from  ww w .  ja  v a 2s.  co m
 *
 * Layout the nodes representing events via the following algorithm.
 *
 * we start with a list of nodes (each representing an event) - sort the
 * list of nodes by span start time of the underlying event - initialize
 * empty map (maxXatY) from y-position to max used x-value - for each node:
 *
 * -- size the node based on its children (recursively)
 *
 * -- get the event's start position from the dateaxis
 *
 * -- to position node (1)check if maxXatY is to the left of the left x
 * coord: if maxXatY is less than the left x coord, good, put the current
 * node here, mark right x coord as maxXatY, go to next node ; if maxXatY
 * greater than start position, increment y position, do check(1) again
 * until maxXatY less than start position
 *
 * @param nodes collection of nodes to layout
 * @param minY  the minimum y coordinate to position the nodes at.
 */
double layoutEventBundleNodes(final Collection<? extends EventBundleNodeBase<?, ?, ?>> nodes,
        final double minY) {

    TreeRangeMap<Double, Double> treeRangeMap = TreeRangeMap.create();
    // maximum y values occupied by any of the given nodes,  updated as nodes are layed out.
    double localMax = minY;

    Set<String> activeQuickHidefilters = getController().getQuickHideFilters().stream()
            .filter(AbstractFilter::isActive).map(DescriptionFilter::getDescription)
            .collect(Collectors.toSet());
    //for each node do a recursive layout to size it and then position it in first available slot
    for (EventBundleNodeBase<?, ?, ?> bundleNode : nodes) {
        //is the node hiden by a quick hide filter?
        boolean quickHide = activeQuickHidefilters.contains(bundleNode.getDescription());
        if (quickHide) {
            //hide it and skip layout
            bundleNode.setVisible(false);
            bundleNode.setManaged(false);
        } else {
            bundleLayoutHelper(bundleNode);
            //get computed height and width
            double h = bundleNode.getBoundsInLocal().getHeight();
            double w = bundleNode.getBoundsInLocal().getWidth();
            //get left and right x coords from axis plus computed width
            double xLeft = getXForEpochMillis(bundleNode.getStartMillis())
                    - bundleNode.getLayoutXCompensation();
            double xRight = xLeft + w + MINIMUM_EVENT_NODE_GAP;

            //initial test position
            double yTop = minY;

            if (oneEventPerRow.get()) {
                // if onePerRow, just put it at end
                yTop = (localMax + MINIMUM_EVENT_NODE_GAP);
            } else {
                double yBottom = yTop + h;

                //until the node is not overlapping any others try moving it down.
                boolean overlapping = true;
                while (overlapping) {
                    overlapping = false;
                    //check each pixel from bottom to top.
                    for (double y = yBottom; y >= yTop; y--) {
                        final Double maxX = treeRangeMap.get(y);
                        if (maxX != null && maxX >= xLeft - MINIMUM_EVENT_NODE_GAP) {
                            //if that pixel is already used
                            //jump top to this y value and repeat until free slot is found.
                            overlapping = true;
                            yTop = y + MINIMUM_EVENT_NODE_GAP;
                            yBottom = yTop + h;
                            break;
                        }
                    }
                }
                treeRangeMap.put(Range.closed(yTop, yBottom), xRight);
            }

            localMax = Math.max(yTop + h, localMax);

            if ((xLeft != bundleNode.getLayoutX()) || (yTop != bundleNode.getLayoutY())) {

                //animate node to new position
                Timeline timeline = new Timeline(
                        new KeyFrame(Duration.millis(100), new KeyValue(bundleNode.layoutXProperty(), xLeft),
                                new KeyValue(bundleNode.layoutYProperty(), yTop)));
                timeline.setOnFinished((ActionEvent event) -> {
                    requestChartLayout();
                });
                timeline.play();
            }
        }
    }
    return localMax; //return new max
}

From source file:net.sf.mzmine.modules.visualization.peaklisttable.PeakListTablePopupMenu.java

/**
 * Get a peak's RT range.//from  w  w  w .  j a  va  2s .com
 * 
 * @param peak
 *            the peak.
 * @return The peak's RT range.
 */
private static Range<Double> getPeakRTRange(final Feature peak) {

    final Range<Double> range = peak.getRawDataPointsRTRange();
    final double rtLen = range.upperEndpoint() - range.lowerEndpoint();
    return Range.closed(Math.max(0.0, range.lowerEndpoint() - rtLen), range.upperEndpoint() + rtLen);
}

From source file:org.eumetsat.usd.gcp.server.data.NetCDFCalibrationDataManager.java

/**
 * {@inheritDoc}//from   w ww.ja v a2s . co m
 */
@Override
public final Range<Date> dateWindowForUser(final String userID) {
    return Range.closed(dataForUser(userID).firstDate(), dataForUser(userID).lastDate());
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleShowXIC(Event event) {
    Double xicMz = (Double) showXICMenuItem.getUserData();
    if (xicMz == null)
        return;//from w  ww.  jav  a2s  .c o m

    // Collect all displayed raw data files
    List<RawDataFile> rawDataFiles = new ArrayList<>();
    for (MsSpectrumDataSet dataset : datasets) {
        if (dataset.getSpectrum() instanceof MsScan) {
            MsScan scan = (MsScan) dataset.getSpectrum();
            RawDataFile rawFile = scan.getRawDataFile();
            if (rawFile != null)
                rawDataFiles.add(rawFile);
        }
    }

    ParameterSet chromatogramParams = MZmineCore.getConfiguration()
            .getModuleParameters(ChromatogramPlotModule.class);
    chromatogramParams.getParameter(ChromatogramPlotParameters.mzRange)
            .setValue(Range.closed(xicMz - 0.005, xicMz + 0.005));
    if (!rawDataFiles.isEmpty()) {
        chromatogramParams.getParameter(ChromatogramPlotParameters.inputFiles)
                .setValue(new RawDataFilesSelection(rawDataFiles));
    }
    chromatogramParams.showSetupDialog("Show XIC");

}