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

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

Introduction

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

Prototype

public C upperEndpoint() 

Source Link

Document

Returns the upper endpoint of this range.

Usage

From source file:edu.cmu.sv.modelinference.eventtool.EventVisualizer.java

private void setViolationMarkers(Collection<Range<Integer>> violations, XYPlot plot) {
    for (Range<Integer> violation : violations) {

        ValueMarker startViolationMarker = new ValueMarker(violation.lowerEndpoint()); // position is the value on the axis
        startViolationMarker.setPaint(Color.BLACK);
        startViolationMarker.setStroke(new BasicStroke(1.0f));
        plot.addDomainMarker(startViolationMarker);

        ValueMarker endViolationMarker = new ValueMarker(violation.upperEndpoint()); // position is the value on the axis
        endViolationMarker.setPaint(Color.GREEN);
        endViolationMarker.setStroke(new BasicStroke(0.5f));
        plot.addDomainMarker(endViolationMarker);
    }//from   w w w .j  a va2  s.  c o  m
}

From source file:com.basistech.tclre.ColorMap.java

/**
 * subrange - allocate new subcolors to this range of chars, fill in arcs.
 * The range will overlap existing ranges; even in the simplest case,
 * it will overlap the initial WHITE range. For each existing range that
 * it overlaps, allocate a new color, mark the range as mapping to that color,
 * and add an arc between the states for that color.
 *//* w  w w .java2 s .co m*/
void subrange(int from, int to, State lp, State rp) throws RegexException {
    /* Avoid one call to map.get() for each character in the range.
     * This map will usually contain one item, but in complex cases more.
     * For example, if we had [a-f][g-h] and then someone asked for [f-g], there
     * would be two. Each of these new ranges will get a new color via subcolor.
     */
    Map<Range<Integer>, Short> curColors = map.subRangeMap(Range.closed(from, to)).asMapOfRanges();
    /*
     * To avoid concurrent mod problems, we need to copy the ranges we are working from.
     */
    List<Range<Integer>> ranges = Lists.newArrayList(curColors.keySet());
    for (Range<Integer> rangeToProcess : ranges) {
        // bound management here irritating.
        int start = rangeToProcess.lowerEndpoint();
        if (rangeToProcess.lowerBoundType() == BoundType.OPEN) {
            start++;
        }
        int end = rangeToProcess.upperEndpoint();
        if (rangeToProcess.upperBoundType() == BoundType.CLOSED) {
            end++;
        }
        // allocate a new subcolor and account it owning the entire range.
        short color = subcolor(start, end - start);
        compiler.getNfa().newarc(Compiler.PLAIN, color, lp, rp);
    }
}

From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java

/**
 * Returns the physical indices written to the given storage during the
 * given group iteration./*from  w w  w .  ja  v a  2s  .c  o m*/
 * @param s the storage being written to
 * @param iterations the group iterations
 * @return the physical indices written
 */
public ImmutableSortedSet<Integer> writes(Storage s, Range<Integer> iterations) {
    ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder();
    for (Actor a : actors())
        builder.addAll(a.writes(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a),
                iterations.upperEndpoint() * schedule.get(a))));
    return builder.build();
}

From source file:com.wealdtech.utils.RangeComparator.java

@Override
public int compare(Range<C> range1, Range<C> range2) {
    int result = ((Boolean) range1.hasLowerBound()).compareTo(range2.hasLowerBound());
    if (result == 0) {
        if (range1.hasLowerBound()) {
            result = range1.lowerEndpoint().compareTo(range2.lowerEndpoint());
            if (result == 0) {
                result = range1.lowerBoundType().compareTo(range2.lowerBoundType());
            }//from  ww w  .ja  v  a  2  s  .c o  m
        }
    }

    if (result == 0) {
        result = ((Boolean) range1.hasUpperBound()).compareTo(range2.hasUpperBound());
        if (result == 0) {
            if (range1.hasUpperBound()) {
                result = range1.upperEndpoint().compareTo(range2.upperEndpoint());
                if (result == 0) {
                    result = range1.upperBoundType().compareTo(range2.upperBoundType());
                }
            }
        }
    }

    return result;
}

From source file:net.sf.mzmine.datamodel.impl.SimpleScan.java

/**
 * @return Returns scan datapoints within a given range
 *///from   w w  w  . j a  va2s .  com
public @Nonnull DataPoint[] getDataPointsByMass(@Nonnull Range<Double> mzRange) {

    int startIndex, endIndex;
    for (startIndex = 0; startIndex < dataPoints.length; startIndex++) {
        if (dataPoints[startIndex].getMZ() >= mzRange.lowerEndpoint())
            break;
    }

    for (endIndex = startIndex; endIndex < dataPoints.length; endIndex++) {
        if (dataPoints[endIndex].getMZ() > mzRange.upperEndpoint())
            break;
    }

    DataPoint pointsWithinRange[] = new DataPoint[endIndex - startIndex];

    // Copy the relevant points
    System.arraycopy(dataPoints, startIndex, pointsWithinRange, 0, endIndex - startIndex);

    return pointsWithinRange;
}

From source file:net.sf.mzmine.util.components.PeakSummaryComponent.java

public void actionPerformed(ActionEvent e) {

    String command = e.getActionCommand();

    if (command.equals("SHOW")) {

        String visualizerType = (String) comboShow.getSelectedItem();
        int[] indexesRow = peaksInfoList.getSelectedRows();
        Feature[] selectedPeaks = new Feature[indexesRow.length];
        RawDataFile[] dataFiles = new RawDataFile[indexesRow.length];
        Range<Double> rtRange = null, mzRange = null;
        for (int i = 0; i < indexesRow.length; i++) {
            selectedPeaks[i] = listElementModel.getElementAt(indexesRow[i]);
            dataFiles[i] = selectedPeaks[i].getDataFile();

            if ((rtRange == null) || (mzRange == null)) {
                rtRange = dataFiles[i].getDataRTRange(1);
                mzRange = selectedPeaks[i].getRawDataPointsMZRange();
            } else {
                rtRange = rtRange.span(dataFiles[i].getDataRTRange(1));
                mzRange = mzRange.span(selectedPeaks[i].getRawDataPointsMZRange());
            }//from  w w  w  .  ja v  a 2 s.  c  om
        }

        if (dataFiles.length == 0) {
            return;
        }

        if (visualizerType.equals("Chromatogram")) {

            // Label best peak with preferred identity.
            final Feature bestPeak = row.getBestPeak();
            final PeakIdentity peakIdentity = row.getPreferredPeakIdentity();
            final Map<Feature, String> labelMap = new HashMap<Feature, String>(1);
            if (bestPeak != null && peakIdentity != null) {

                labelMap.put(bestPeak, peakIdentity.getName());
            }

            ScanSelection scanSelection = new ScanSelection(rtRange, 1);

            TICVisualizerModule.showNewTICVisualizerWindow(dataFiles, selectedPeaks, labelMap, scanSelection,
                    TICPlotType.BASEPEAK, mzRange);
            return;

        } else if (visualizerType.equals("Mass spectrum")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i],
                        selectedPeaks[i].getRepresentativeScanNumber());
            }
        } else if (visualizerType.equals("Peak in 2D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen),
                        peakRTRange.upperEndpoint() + rtLen);

                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen),
                        peakMZRange.upperEndpoint() + mzLen);
                TwoDVisualizerModule.show2DVisualizerSetupDialog(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("Peak in 3D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen),
                        peakRTRange.upperEndpoint() + rtLen);
                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen),
                        peakMZRange.upperEndpoint() + mzLen);
                ThreeDVisualizerModule.setupNew3DVisualizer(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("MS/MS")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                int scanNumber = selectedPeaks[i].getMostIntenseFragmentScanNumber();
                if (scanNumber > 0) {
                    SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], scanNumber);
                } else {
                    JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
                    MZmineCore.getDesktop().displayMessage(frame, "There is no fragment for the mass "
                            + MZmineCore.getConfiguration().getMZFormat().format(selectedPeaks[i].getMZ())
                            + "m/z in the current raw data.");
                    return;
                }
            }

        } else if (visualizerType.equals("Isotope pattern")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                IsotopePattern ip = selectedPeaks[i].getIsotopePattern();
                if (ip == null) {
                    return;
                }
                SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i],
                        selectedPeaks[i].getMostIntenseFragmentScanNumber(), ip);

            }
        }
        return;
    }

    if (command.equals("CHANGE")) {
        int indexRow = peaksInfoList.getSelectedRow();
        if (indexRow == -1) {
            return;
        }
        Feature selectedPeak = listElementModel.getElementAt(indexRow);
        ManualPeakPickerModule.runManualDetection(selectedPeak.getDataFile(), row, null, null);

        return;
    }

}

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

private long getNumberOfEntries(Range<PositionImpl> range,
        NavigableMap<Long, MLDataFormats.ManagedLedgerInfo.LedgerInfo> ledgers) {
    PositionImpl fromPosition = range.lowerEndpoint();
    boolean fromIncluded = range.lowerBoundType() == BoundType.CLOSED;
    PositionImpl toPosition = range.upperEndpoint();
    boolean toIncluded = range.upperBoundType() == BoundType.CLOSED;

    if (fromPosition.getLedgerId() == toPosition.getLedgerId()) {
        // If the 2 positions are in the same ledger
        long count = toPosition.getEntryId() - fromPosition.getEntryId() - 1;
        count += fromIncluded ? 1 : 0;//from www . j  a  v a 2s  .co m
        count += toIncluded ? 1 : 0;
        return count;
    } else {
        long count = 0;
        // If the from & to are pointing to different ledgers, then we need to :
        // 1. Add the entries in the ledger pointed by toPosition
        count += toPosition.getEntryId();
        count += toIncluded ? 1 : 0;

        // 2. Add the entries in the ledger pointed by fromPosition
        MLDataFormats.ManagedLedgerInfo.LedgerInfo li = ledgers.get(fromPosition.getLedgerId());
        if (li != null) {
            count += li.getEntries() - (fromPosition.getEntryId() + 1);
            count += fromIncluded ? 1 : 0;
        }

        // 3. Add the whole ledgers entries in between
        for (MLDataFormats.ManagedLedgerInfo.LedgerInfo ls : ledgers
                .subMap(fromPosition.getLedgerId(), false, toPosition.getLedgerId(), false).values()) {
            count += ls.getEntries();
        }

        return count;
    }
}

From source file:net.sf.mzmine.modules.visualization.scatterplot.ScatterPlotBottomPanel.java

public void actionPerformed(ActionEvent event) {

    String command = event.getActionCommand();

    if (command.equals("DATA_CHANGE")) {

        ScatterPlotAxisSelection optionX = (ScatterPlotAxisSelection) comboX.getSelectedItem();
        ScatterPlotAxisSelection optionY = (ScatterPlotAxisSelection) comboY.getSelectedItem();

        if ((optionX == null) || (optionY == null))
            return;

        String foldText = foldXvalues[comboFold.getSelectedIndex()];
        int foldValue = Integer.parseInt(foldText);
        if (foldValue <= 0)
            foldValue = 2;//www . jav  a2 s  .  co m

        chart.setDisplayedAxes(optionX, optionY, foldValue);
        return;
    }

    if (command.equals("LABEL_ITEMS")) {
        chart.setItemLabels(labeledItems.isSelected());
    }

    if (command.equals("SEARCH")) {

        SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem();
        String searchRegex = txtSearchField.getText();
        Number minValue = ((Number) minSearchField.getValue());
        if (minValue == null)
            minValue = 0;
        Number maxValue = ((Number) maxSearchField.getValue());
        if (maxValue == null)
            maxValue = 0;
        Range<Double> searchRange = Range.closed(minValue.doubleValue(), maxValue.doubleValue());
        try {
            SearchDefinition newSearch = new SearchDefinition(searchType, searchRegex, searchRange);
            chart.updateSearchDefinition(newSearch);
        } catch (PatternSyntaxException pe) {
            MZmineCore.getDesktop().displayErrorMessage(window,
                    "The regular expression's syntax is invalid: " + pe);
        }
        return;
    }

    if (command.equals("SEARCH_DATA_TYPE")) {

        SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem();

        switch (searchType) {

        case MASS:
            minSearchField.setVisible(true);
            maxSearchField.setVisible(true);
            labelRange.setVisible(true);
            txtSearchField.setVisible(false);
            NumberFormat mzFormatter = MZmineCore.getConfiguration().getMZFormat();
            Range<Double> mzRange = peakList.getRowsMZRange();
            DefaultFormatterFactory mzFormatFac = new DefaultFormatterFactory(new NumberFormatter(mzFormatter));
            minSearchField.setFormatterFactory(mzFormatFac);
            minSearchField.setValue(mzRange.lowerEndpoint());
            maxSearchField.setFormatterFactory(mzFormatFac);
            maxSearchField.setValue(mzRange.upperEndpoint());
            break;

        case RT:
            minSearchField.setVisible(true);
            maxSearchField.setVisible(true);
            labelRange.setVisible(true);
            txtSearchField.setVisible(false);
            NumberFormat rtFormatter = MZmineCore.getConfiguration().getRTFormat();
            Range<Double> rtRange = peakList.getRowsRTRange();
            DefaultFormatterFactory rtFormatFac = new DefaultFormatterFactory(new NumberFormatter(rtFormatter));
            minSearchField.setFormatterFactory(rtFormatFac);
            minSearchField.setValue(rtRange.lowerEndpoint());
            maxSearchField.setFormatterFactory(rtFormatFac);
            maxSearchField.setValue(rtRange.upperEndpoint());
            break;

        case NAME:
            minSearchField.setVisible(false);
            maxSearchField.setVisible(false);
            labelRange.setVisible(false);
            txtSearchField.setVisible(true);
            break;
        }

        return;
    }

}

From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java

/**
 * Returns the physical indices read from the given storage during the given
 * group iterations.//from   w  ww . j  a v a 2 s  .  c o  m
 * @param s the storage being read from
 * @param iterations the group iterations
 * @return the physical indices read
 */
public ImmutableSortedSet<Integer> reads(Storage s, Range<Integer> iterations) {
    iterations = iterations.canonical(DiscreteDomain.integers());
    ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder();
    for (Actor a : actors())
        builder.addAll(a.reads(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a),
                iterations.upperEndpoint() * schedule.get(a))));
    return builder.build();
}

From source file:it.units.malelab.ege.ge.mapper.BitsSGEMapper.java

@Override
public Node<T> map(BitsGenotype genotype, Map<String, Object> report) throws MappingException {
    int[] bitUsages = new int[genotype.size()];
    //transform genotypes in ints
    if (genotype.size() < overallSize) {
        throw new MappingException(String.format("Short genotype (%d<%d)", genotype.size(), overallSize));
    }//from ww  w . j av  a  2  s.  com
    Map<Pair<T, Integer>, List<Range<Integer>>> codonRanges = new LinkedHashMap<>();
    List<Range<Integer>> nonTerminalRanges = Utils.slices(Range.closedOpen(0, genotype.size()),
            nonTerminalSizes);
    for (int i = 0; i < nonTerminals.size(); i++) {
        //int codonSize = (int) Math.max(Math.ceil(Math.log10(nonRecursiveGrammar.getRules().get(nonTerminals.get(i)).size()) / Math.log10(2)), 1);
        List<Range<Integer>> boundaries = Utils.slices(nonTerminalRanges.get(i),
                nonTerminalCodonsNumbers.get(i));
        codonRanges.put(nonTerminals.get(i), boundaries);
    }
    //map
    Multiset<Pair<T, Integer>> expandedSymbols = LinkedHashMultiset.create();
    Node<Pair<T, Integer>> tree = new Node<>(nonRecursiveGrammar.getStartingSymbol());
    while (true) {
        Node<Pair<T, Integer>> nodeToBeReplaced = null;
        for (Node<Pair<T, Integer>> node : tree.leafNodes()) {
            if (nonRecursiveGrammar.getRules().keySet().contains(node.getContent())) {
                nodeToBeReplaced = node;
                break;
            }
        }
        if (nodeToBeReplaced == null) {
            break;
        }
        //get codon
        Range<Integer> range = codonRanges.get(nodeToBeReplaced.getContent())
                .get(expandedSymbols.count(nodeToBeReplaced.getContent()));
        List<List<Pair<T, Integer>>> options = nonRecursiveGrammar.getRules()
                .get(nodeToBeReplaced.getContent());
        int codonSize = (int) Math.max(Math.ceil(Math.log10(options.size()) / Math.log10(2)), 1);
        int codonValue = genotype.slice(range).compress(codonSize).toInt();
        int optionIndex = codonValue % options.size();
        //update usages
        for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); i++) {
            bitUsages[i] = bitUsages[i] + 1;
        }
        //add children
        for (Pair<T, Integer> p : options.get(optionIndex)) {
            Node<Pair<T, Integer>> newChild = new Node<>(p);
            nodeToBeReplaced.getChildren().add(newChild);
        }
        expandedSymbols.add(nodeToBeReplaced.getContent());
    }
    report.put(BIT_USAGES_INDEX_NAME, bitUsages);
    //transform tree
    return transform(tree);
}