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

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

Introduction

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

Prototype

public boolean encloses(Range<C> other) 

Source Link

Document

Returns true if the bounds of other do not extend outside the bounds of this range.

Usage

From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java

/**
 * Texts in tableContent have been ordered by .getY() ASC
 *
 * @param pageIdx/*w w  w  . j a  v a2  s  .c  o m*/
 * @param tableContent
 * @param rowTrapRanges
 * @param columnTrapRanges
 * @return
 */
private Table buildTable(int pageIdx, List<TextPosition> tableContent, List<Range<Integer>> rowTrapRanges,
        List<Range<Integer>> columnTrapRanges) {
    Table retVal = new Table(pageIdx, columnTrapRanges.size());
    int idx = 0;
    int rowIdx = 0;
    List<TextPosition> rowContent = new ArrayList<>();
    while (idx < tableContent.size()) {
        TextPosition textPosition = tableContent.get(idx);
        Range<Integer> rowTrapRange = rowTrapRanges.get(rowIdx);
        Range<Integer> textRange = Range.closed((int) textPosition.getY(),
                (int) (textPosition.getY() + textPosition.getHeight()));
        if (rowTrapRange.encloses(textRange)) {
            rowContent.add(textPosition);
            idx++;
        } else {
            TableRow row = buildRow(rowIdx, rowContent, columnTrapRanges);
            retVal.getRows().add(row);
            //next row: clear rowContent
            rowContent.clear();
            rowIdx++;
        }
    }
    //last row
    if (!rowContent.isEmpty() && rowIdx < rowTrapRanges.size()) {
        TableRow row = buildRow(rowIdx, rowContent, columnTrapRanges);
        retVal.getRows().add(row);
    }
    //return
    return retVal;
}

From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java

/**
 *
 * @param rowIdx//from w ww .  j  ava 2s . c o m
 * @param rowContent
 * @param columnTrapRanges
 * @return
 */
private TableRow buildRow(int rowIdx, List<TextPosition> rowContent, List<Range<Integer>> columnTrapRanges) {
    TableRow retVal = new TableRow(rowIdx);
    //Sort rowContent
    Collections.sort(rowContent, new Comparator<TextPosition>() {
        @Override
        public int compare(TextPosition o1, TextPosition o2) {
            int retVal = 0;
            if (o1.getX() < o2.getX()) {
                retVal = -1;
            } else if (o1.getX() > o2.getX()) {
                retVal = 1;
            }
            return retVal;
        }
    });
    int idx = 0;
    int columnIdx = 0;
    List<TextPosition> cellContent = new ArrayList<>();
    while (idx < rowContent.size()) {
        TextPosition textPosition = rowContent.get(idx);
        Range<Integer> columnTrapRange = columnTrapRanges.get(columnIdx);
        Range<Integer> textRange = Range.closed((int) textPosition.getX(),
                (int) (textPosition.getX() + textPosition.getWidth()));
        if (columnTrapRange.encloses(textRange)) {
            cellContent.add(textPosition);
            idx++;
        } else {
            TableCell cell = buildCell(columnIdx, cellContent);
            retVal.getCells().add(cell);
            //next column: clear cell content
            cellContent.clear();
            columnIdx++;
        }
    }
    if (!cellContent.isEmpty() && columnIdx < columnTrapRanges.size()) {
        TableCell cell = buildCell(columnIdx, cellContent);
        retVal.getCells().add(cell);
    }
    //return
    return retVal;
}

From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java

void updateTitle() {

    NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

    StringBuffer mainTitle = new StringBuffer();
    StringBuffer subTitle = new StringBuffer();

    // If all data files have m/z range less than or equal to range of
    // the plot (mzMin, mzMax), then call this TIC, otherwise XIC
    Set<RawDataFile> fileSet = ticDataSets.keySet();
    String ticOrXIC = "TIC";

    // Enlarge range a bit to avoid rounding errors
    Range<Double> mzRange2 = Range.range(mzRange.lowerEndpoint() - 1, BoundType.CLOSED,
            mzRange.upperEndpoint() + 1, BoundType.CLOSED);
    for (RawDataFile df : fileSet) {
        if (!mzRange2.encloses(df.getDataMZRange())) {
            ticOrXIC = "XIC";
            break;
        }/*from w ww .  j  a v a  2 s . co m*/
    }

    if (plotType == TICPlotType.BASEPEAK) {
        if (ticOrXIC.equals("TIC")) {
            mainTitle.append("Base peak chromatogram");
        } else {
            mainTitle.append("XIC (base peak)");
        }
    } else {
        if (ticOrXIC.equals("TIC")) {
            mainTitle.append("TIC");
        } else {
            mainTitle.append("XIC");
        }
    }

    mainTitle.append(", m/z: " + mzFormat.format(mzRange.lowerEndpoint()) + " - "
            + mzFormat.format(mzRange.upperEndpoint()));

    CursorPosition pos = getCursorPosition();

    if (pos != null) {
        subTitle.append("Selected scan #");
        subTitle.append(pos.getScanNumber());
        if (ticDataSets.size() > 1) {
            subTitle.append(" (" + pos.getDataFile() + ")");
        }
        subTitle.append(", RT: " + rtFormat.format(pos.getRetentionTime()));
        if (plotType == TICPlotType.BASEPEAK) {
            subTitle.append(", base peak: " + mzFormat.format(pos.getMzValue()) + " m/z");
        }
        subTitle.append(", IC: " + intensityFormat.format(pos.getIntensityValue()));
    }

    // update window title
    RawDataFile files[] = ticDataSets.keySet().toArray(new RawDataFile[0]);
    Arrays.sort(files, new SimpleSorter());
    String dataFileNames = Joiner.on(",").join(files);
    setTitle("Chromatogram: [" + dataFileNames + "; " + mzFormat.format(mzRange.lowerEndpoint()) + " - "
            + mzFormat.format(mzRange.upperEndpoint()) + " m/z" + "]");

    // update plot title
    ticPlot.setTitle(mainTitle.toString(), subTitle.toString());

}

From source file:com.wealdtech.collect.TreeRangedMap.java

@Override
public void put(final Range<K> key, final V value) {
    validateRange(key);/*from   www  . j av  a 2  s.  com*/
    K resultantStart = key.lowerEndpoint();
    K resultantEnd = key.upperEndpoint();

    // Truncate or coalesce anything which overlaps the start of our new entry
    final Map.Entry<K, TwoTuple<Range<K>, V>> prior = getEntry(key.lowerEndpoint());
    if (prior != null) {
        if (prior.getValue().getT().equals(value)) {
            // Values are the same so we can coalesce.
            if (resultantEnd.compareTo(prior.getValue().getS().upperEndpoint()) < 0) {
                // Existing entry already covers this; we don't have to do anything more
                return;
            }
            underlying.remove(prior.getKey());
            // Set our start to the start of the prior entry
            resultantStart = prior.getKey();
        } else {
            // Values are different; truncate prior item
            underlying.put(prior.getKey(),
                    new TwoTuple<>(Range.closedOpen(prior.getKey(), resultantStart), prior.getValue().getT()));
            // If the prior entry stretches beyond the new entry we also need to put in our remaining item
            if (resultantEnd.compareTo(prior.getValue().getS().upperEndpoint()) < 0) {
                underlying.put(resultantEnd,
                        new TwoTuple<>(Range.closedOpen(resultantEnd, prior.getValue().getS().upperEndpoint()),
                                prior.getValue().getT()));
            }

        }
    }

    // Remove any items which are covered by our new entry, and truncate or coalesce anything which overlaps the end of it
    Map.Entry<K, TwoTuple<Range<K>, V>> potentialVictim = underlying.ceilingEntry(resultantStart);
    while (potentialVictim != null) {
        if (key.encloses(potentialVictim.getValue().getS())) {
            // Totally enclosed; remove it
            underlying.remove(potentialVictim.getKey());
            potentialVictim = underlying.ceilingEntry(resultantStart);
        } else if (key.contains(potentialVictim.getKey())) {
            // Partial overlap
            if (potentialVictim.getValue().getT().equals(value)) {
                // Values are the same so we can coalesce.  Remove the entry and update our bounds accordingly
                resultantEnd = potentialVictim.getValue().getS().upperEndpoint();
                underlying.remove(potentialVictim.getKey());
            } else {
                // Values are different; truncate victim item
                underlying.remove(potentialVictim.getKey());
                underlying.put(resultantEnd,
                        new TwoTuple<>(
                                Range.closedOpen(resultantEnd,
                                        potentialVictim.getValue().getS().upperEndpoint()),
                                potentialVictim.getValue().getT()));
            }
            potentialVictim = null;
        } else {
            // No relationship
            potentialVictim = null;
        }
    }

    // Write out our final result
    underlying.put(resultantStart, new TwoTuple<>(Range.closedOpen(resultantStart, resultantEnd), value));
}