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.cinchapi.concourse.server.model.Ranges.java

/**
 * Return a new {@link Range} that is the merger (e.g. union) of {@code a}
 * and {@code b}. The new {@link Range} maintains both the lower and higher
 * endpoint/bound between the two inputs.
 * /* ww  w  .ja v a  2  s. c  om*/
 * @param a
 * @param b
 * @return the union of {@code a} and {@code b}
 */
public static Range<Value> merge(Range<Value> a, Range<Value> b) {
    if (a.isConnected(b)) {
        boolean aStart = compareToLower(a, b) < 0;
        boolean aEnd = compareToUpper(a, b) > 0;
        boolean lower = getLowerBoundType(aStart ? a : b) == BoundType.CLOSED;
        boolean upper = getUpperBoundType(aStart ? a : b) == BoundType.CLOSED;
        if (lower && upper) {
            return Range.closed(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else if (!lower && upper) {
            return Range.closedOpen(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else if (lower && !upper) {
            return Range.openClosed(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else {
            return Range.open(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        }
    } else {
        return null;
    }
}

From source file:de.tuberlin.uebb.jdae.transformation.Causalisation.java

public void collectEquation(final Matching matching, IntPair eqNext, final Set<GlobalVariable> blockVars,
        final TIntObjectMap<Range<Integer>> blockEqns) {
    final int i = eqNext.x;
    final int j = matching.assignment[i];

    final int c = eqNext.y;

    if (!blockEqns.containsKey(i))
        blockEqns.put(i, Range.closed(c, c));
    else {//w  w w .  j  a  v a2 s . co  m
        final Range<Integer> next = Range.closed(c, c);
        final Range<Integer> last = blockEqns.get(i);

        blockEqns.put(i, next.intersection(last));
    }

    blockVars.add(new GlobalVariable(layout[j].name, j + 1, matching.sigma(i, j) + c));
}

From source file:com.google.android.apps.forscience.whistlepunk.review.RunReviewExporter.java

public void startExport(Context context, final String experimentName, final ExperimentRun run,
        String sensorTag) {/*www .  jav a2 s.  com*/
    mStop = false;
    mRun = run;
    mSensorTag = sensorTag;
    mContext = context.getApplicationContext();
    mHandlerThread = new HandlerThread("export", Thread.MIN_PRIORITY);
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper(), this);
    mStreamConsumer = new StreamConsumer() {
        @Override
        public void addData(final long timestampMillis, final double value) {
            try {
                if (mOutputStreamWriter == null) {
                    mListener.onExportError(new IllegalStateException("Output stream closed."));
                    return;
                }
                mOutputStreamWriter.write(Long.toString(timestampMillis));
                mOutputStreamWriter.write(",");
                mOutputStreamWriter.write(Double.toString(value));
                mOutputStreamWriter.write("\n");
                mLastTimeStampWritten = timestampMillis;

            } catch (IOException e) {
                mListener.onExportError(e);
                return;
            }
        }
    };
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            File storageDir = getStorageDir(mContext);

            // Create the storage directory if it does not exist
            if (!storageDir.exists()) {
                if (!storageDir.mkdirs()) {
                    Log.e(TAG, "failed to create directory");
                    mListener.onExportError(
                            new IOException("Could not create dir " + storageDir.getAbsolutePath()));
                    return;
                }
            }

            File file = new File(storageDir.getPath(),
                    sanitizeFilename(experimentName + " " + run.getRunTitle(mContext)) + ".csv");
            mFileName = file.getName();
            FileOutputStream fs;
            try {
                fs = new FileOutputStream(file);
            } catch (FileNotFoundException e) {
                mListener.onExportError(e);
                return;
            }

            mOutputStreamWriter = new OutputStreamWriter(fs);
            try {
                mOutputStreamWriter.write("timestamp");
                mOutputStreamWriter.write(",");
                mOutputStreamWriter.write("value");
                mOutputStreamWriter.write("\n");
            } catch (IOException e) {
                mListener.onExportError(e);
                return;
            }
        }
    });

    mListener.onExportStarted();

    Range<Long> times = Range.closed(mRun.getFirstTimestamp(), mRun.getLastTimestamp());
    getReadings(TimeRange.oldest(times));
}

From source file:org.raml.yagi.framework.grammar.BaseGrammar.java

/**
 * Matches an integer greater than zero/*  www  .ja v a  2s  .co m*/
 * @return The rule
 */
public IntegerTypeRule positiveIntegerType(boolean includesZero, Long maxValue) {
    return new IntegerTypeRule(Range.closed(includesZero ? 0L : 1L, maxValue));
}

From source file:org.noroomattheinn.visibletesla.DataStore.java

protected final Range<Long> getLoadPeriod() {
    Range<Long> loadPeriod = Range.closed(Long.MIN_VALUE, Long.MAX_VALUE);

    long now = System.currentTimeMillis();
    LoadPeriod period = nameToLoadPeriod.get(appContext.prefs.loadPeriod.get());
    if (period == null) {
        period = LoadPeriod.All;/* w  ww .j a v a  2 s  .  c om*/
        appContext.prefs.loadPeriod.set(nameToLoadPeriod.inverse().get(period));
    }
    switch (period) {
    case None:
        loadPeriod = Range.closed(now + 1000, now + 1000L); // Empty Range
        break;
    case Last7:
        loadPeriod = Range.closed(now - (7 * 24 * 60 * 60 * 1000L), now);
        break;
    case Last14:
        loadPeriod = Range.closed(now - (14 * 24 * 60 * 60 * 1000L), now);
        break;
    case Last30:
        loadPeriod = Range.closed(now - (30 * 24 * 60 * 60 * 1000L), now);
        break;
    case ThisWeek:
        Range<Date> thisWeek = getThisWeek();
        loadPeriod = Range.closed(thisWeek.lowerEndpoint().getTime(), thisWeek.upperEndpoint().getTime());
        break;
    case ThisMonth:
        Range<Date> thisMonth = getThisMonth();
        loadPeriod = Range.closed(thisMonth.lowerEndpoint().getTime(), thisMonth.upperEndpoint().getTime());
        break;
    case All:
    default:
        break;

    }
    return loadPeriod;
}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java

Range<Double> getDomainRange() {
    return Range.closed(getDomainAxis().getRange().getLowerBound(), getDomainAxis().getRange().getUpperBound());
}

From source file:io.github.msdk.datamodel.impl.SimpleChromatogram.java

/** {@inheritDoc} */
@Override//from   w ww .  ja  v  a2 s  .c o m
public synchronized void setDataPoints(@Nonnull ChromatographyInfo rtValues[], @Nullable double mzValues[],
        @Nonnull float intensityValues[], @Nonnull Integer size) {

    if (dataStoreRtId != null)
        dataPointStore.removeData(dataStoreRtId);
    if (dataStoreMzId != null)
        dataPointStore.removeData(dataStoreMzId);
    if (dataStoreIntensityId != null)
        dataPointStore.removeData(dataStoreIntensityId);

    dataStoreRtId = dataPointStore.storeData(rtValues, size);
    if (mzValues != null)
        dataStoreMzId = dataPointStore.storeData(mzValues, size);
    else
        dataStoreMzId = null;
    dataStoreIntensityId = dataPointStore.storeData(intensityValues, size);
    this.numOfDataPoints = size;

    if (size > 0)
        this.rtRange = Range.closed(rtValues[0], rtValues[size - 1]);
    else
        this.rtRange = null;
}

From source file:org.pshdl.model.simulation.RangeTool.java

private static void validate(Set<Range<BigInteger>> split) {
    System.out.println("Result:" + split);
    Range<BigInteger> last = Range.closed(BigInteger.valueOf(-1), BigInteger.valueOf(-1));
    for (final Range<BigInteger> range : split) {
        if (range.isConnected(last))
            throw new IllegalArgumentException("Ranges are connected:" + last + " and " + range);
        last = range;/*from  w ww.j a  v a  2  s .c om*/
    }
}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java

Range<Double> getAxisRange() {
    return Range.closed(getRangeAxis().getRange().getLowerBound(), getRangeAxis().getRange().getUpperBound());
}

From source file:com.google.android.apps.forscience.whistlepunk.GraphPopulator.java

private Range<Long> getEffectiveAddedRange(TimeRange requested, Range<Long> returned) {
    if (returned == null) {
        return requested.getTimes().canonical(DiscreteDomain.longs());
    }/*from  www.  j ava2  s .co  m*/

    switch (requested.getOrder()) {
    case NEWEST_FIRST:
        return Range.closed(returned.lowerEndpoint(), requested.getTimes().upperEndpoint());
    case OLDEST_FIRST:
        return Range.closed(requested.getTimes().lowerEndpoint(), returned.upperEndpoint());
    default:
        throw new IllegalArgumentException("Unexpected value for enum: " + requested.getOrder());
    }
}