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:net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.AgilentCsvReadTask.java

/**
 * Reads the file.//from w  w w . ja va  2s.c om
 */
public void run() {

    setStatus(TaskStatus.PROCESSING);
    Scanner scanner;

    try {

        scanner = new Scanner(this.file);

        this.dataSource = this.getMetaData(scanner, "file name");

        String[] range = this.getMetaData(scanner, "mass range").split(",");
        newMZmineFile.setMZRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
        range = this.getMetaData(scanner, "time range").split(",");
        newMZmineFile.setRTRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
        totalScans = Integer.parseInt(this.getMetaData(scanner, "number of spectra"));

        // advance to the spectrum data...
        while (!scanner.nextLine().trim().equals("[spectra]")) {
        }

        scanner.useDelimiter(",");

        for (parsedScans = 0; parsedScans < totalScans; parsedScans++) {

            if (isCanceled()) {
                return;
            } // if the task is canceled.

            double retentionTime = scanner.nextDouble();
            int msLevel = scanner.nextInt(); // not sure about this value
            scanner.next();
            scanner.next();
            int charge = (scanner.next().equals("+") ? 1 : -1);
            scanner.next();

            int spectrumSize = scanner.nextInt();
            DataPoint[] dataPoints = new DataPoint[spectrumSize];
            for (int j = 0; j < spectrumSize; j++) {
                dataPoints[j] = new SimpleDataPoint(scanner.nextDouble(), scanner.nextDouble());
            }
            newMZmineFile.addScan(
                    new SimpleScan(null, parsedScans + 1, msLevel, retentionTime, 0.0, charge, null, dataPoints,
                            ScanUtils.detectSpectrumType(dataPoints), PolarityType.UNKNOWN, "", null));

            scanner.nextLine();
        }

        finalRawDataFile = newMZmineFile.finishWriting();
        project.addFile(finalRawDataFile);

    } catch (Exception e) {
        setErrorMessage(e.getMessage());
        this.setStatus(TaskStatus.ERROR);
        return;
    }

    this.setStatus(TaskStatus.FINISHED);

}

From source file:edu.si.sidora.tabularmetadata.spring.SpringITFramework.java

protected static Range<String> getStringRange() {
    return Range.closed("0056", "SERIAL NUMBER");
}

From source file:org.apache.calcite.chinook.PreferredGenresTableFactory.java

private Queryable<Integer> fetchPreferredGenres() {
    if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) {
        return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_GENRES).asQueryable();
    } else {// w  ww  .j a  v a  2s  .c om
        final ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID),
                DiscreteDomain.integers());
        return Linq4j.asEnumerable(set).asQueryable();
    }
}

From source file:org.apache.calcite.chinook.PreferredAlbumsTableFactory.java

private Queryable<Integer> fetchPreferredAlbums() {
    if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) {
        return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_ALBUMS).asQueryable();
    } else {// w  ww . j a  v a 2 s  . c  o  m
        final ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID),
                DiscreteDomain.integers());
        return Linq4j.asEnumerable(set).asQueryable();
    }
}

From source file:net.sf.mzmine.modules.masslistmethods.shoulderpeaksfilter.peakmodels.GaussPeak.java

/**
 * @see net.sf.mzmine.modules.masslistmethods.shoulderpeaksfilter.peakpicking.twostep.peakmodel.PeakModel#getBasePeakWidth()
 *//*  ww w . ja v  a2 s . com*/
public Range<Double> getWidth(double partialIntensity) {

    // The height value must be bigger than zero.
    if (partialIntensity <= 0)
        return Range.atLeast(0.0);

    // Using the Gaussian function we calculate the peak width at intensity
    // given (partialIntensity)

    double portion = partialIntensity / intensityMain;
    double ln = -1 * (double) Math.log(portion);

    double sideRange = (double) (Math.sqrt(part2C2 * ln));

    // This range represents the width of our peak in m/z
    Range<Double> rangePeak = Range.closed(mzMain - sideRange, mzMain + sideRange);

    return rangePeak;
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.build.validation.RobotInitFileValidator.java

private void reportProblem(final String declarationName, final AModelElement<?> element) {
    final RobotProblem problem = RobotProblem.causedBy(GeneralSettingsProblem.UNSUPPORTED_SETTING)
            .formatMessageWith(declarationName, "initialization");
    final ProblemPosition position = new ProblemPosition(element.getBeginPosition().getLine(),
            Range.closed(element.getBeginPosition().getOffset(), element.getEndPosition().getOffset()));
    reporter.handleProblem(problem, file, position);
}

From source file:dollar.api.types.DollarInfinity.java

@NotNull
@Override/*from w w  w.j  av  a  2 s .  c  om*/
public Value $as(@NotNull Type type) {
    if (type.is(Type._BOOLEAN)) {
        return DollarStatic.$(true);
    } else if (type.is(Type._STRING)) {
        return DollarStatic.$(positive ? "infinity" : "-infinity");
    } else if (type.is(Type._LIST)) {
        return DollarStatic.$(Collections.singletonList(this));
    } else if (type.is(Type._MAP)) {
        return DollarStatic.$("value", this);
    } else if (type.is(Type._DECIMAL)) {
        return DollarStatic.$(positive ? Double.MAX_VALUE : Double.MIN_VALUE);
    } else if (type.is(Type._INTEGER)) {
        return DollarStatic.$(positive ? Long.MAX_VALUE : Long.MIN_VALUE);
    } else if (type.is(Type._VOID)) {
        return DollarStatic.$void();
    } else if (type.is(Type._DATE)) {
        return this;
    } else if (type.is(Type._RANGE)) {
        return DollarFactory.fromValue(Range.closed($get(DollarStatic.$(0)), $get(DollarStatic.$(0))));
    } else {
        return DollarFactory.failure(ErrorType.INVALID_CAST, type.toString(), false);
    }
}

From source file:google.registry.model.ofy.CommitLogBucket.java

private static Range<Integer> getBucketIdRange() {
    return Range.closed(1, getCommitLogBucketCount());
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.build.validation.RobotSuiteFileValidator.java

private ProblemPosition getTestCaseTableHeaderPosition(final Optional<RobotCasesSection> section) {
    // TODO : this can be done using some nice API on parser side
    if (!section.isPresent()) {
        return new ProblemPosition(1);
    }//from   w  w w. j  ava2 s.  c  o  m
    final TestCaseTable table = section.get().getLinkedElement();
    final List<TableHeader<? extends ARobotSectionTable>> headers = table.getHeaders();
    if (!headers.isEmpty()) {
        final TableHeader<? extends ARobotSectionTable> header = headers.get(0);
        final int line = header.getBeginPosition().getLine();
        final int beginOffset = header.getBeginPosition().getOffset();
        final int endOffset = header.getEndPosition().getOffset();

        return new ProblemPosition(line, Range.closed(beginOffset, endOffset));
    }
    return new ProblemPosition(1);
}

From source file:io.horizondb.model.core.records.BlockHeaderUtils.java

/**
 * Returns the time range that contains the block.
 * /*  w  ww .  j a  v  a 2s  . c  om*/
 * @param header the block header
 * @return the time range that contains the block.
 */
public static Range<Field> getRange(Record header) throws IOException {
    return Range.closed(getFirstTimestampField(header), getLastTimestampField(header));
}