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.arbeitspferde.groningen.experimentdb.jvmflags.JvmFlag.java

/**
 * Construct a new boolean flag./*from ww  w.j  a  va 2  s  .  c om*/
 *
 * @param name The name of the flag.
 * @param hotSpotFlagType The type of the flag.
 */
private JvmFlag(final String name, final HotSpotFlagType hotSpotFlagType) {
    this.name = Preconditions.checkNotNull(name, "name may not be null.");
    this.hotSpotFlagType = Preconditions.checkNotNull(hotSpotFlagType, "hotSpotFlagType may not be null.");

    formatter = Formatters.BOOLEAN_FORMATTER;
    floorValue = 0L;
    ceilingValue = 1L;
    stepSize = 1L;
    dataSize = DataSize.NONE;
    valueSeparator = ValueSeparator.NONE;
    acceptableValueRange = Range.closed(0L, 1L);
}

From source file:com.google.devtools.build.lib.runtime.BlazeWorkspace.java

void recordLastExecutionTime(long commandStartTime) {
    long currentTimeMillis = runtime.getClock().currentTimeMillis();
    lastExecutionRange = currentTimeMillis >= commandStartTime
            ? Range.closed(commandStartTime, currentTimeMillis)
            : null;/*from  w  w  w .j  av a 2 s .  c  om*/
}

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

public void startPlayback(ChartController chartController, final DataController dataController,
        long firstTimestamp, long lastTimestamp, long xMinToLoad, final String sensorId) {
    if (!chartController.hasDrawnChart() || mPlaybackStatus != PLAYBACK_STATUS_NOT_PLAYING) {
        return;/*from   w ww  .  ja v  a2 s.  co  m*/
    }

    final double yMin = chartController.getRenderedYMin();
    final double yMax = chartController.getRenderedYMax();
    final long xMax = lastTimestamp;
    final List<ChartData.DataPoint> audioData = new ArrayList<>();

    if (xMinToLoad == RunReviewOverlay.NO_TIMESTAMP_SELECTED) {
        xMinToLoad = firstTimestamp;
    } else {
        if ((xMax - xMinToLoad) < .05 * (xMax - firstTimestamp)) {
            // If we are 95% or more towards the end, start at the beginning.
            // This allows for some slop.
            xMinToLoad = firstTimestamp;
        }
    }
    long xMaxToLoad = Math.min(xMinToLoad + DURATION_MS_PER_AUDIO_PLAYBACK_LOAD, xMax);
    final boolean fullyLoaded = xMaxToLoad == xMax;

    mHandler = new Handler();
    mPlaybackRunnable = new Runnable() {
        boolean mFullyLoaded = fullyLoaded;

        @Override
        public void run() {
            if (audioData.size() == 0) {
                stopPlayback();
                return;
            }

            // Every time we play a data point, we remove it from the list.
            ChartData.DataPoint point = audioData.remove(0);
            long timestamp = point.getX();

            // Load more data when needed, i.e. when we are within a given duration away from
            // the last loaded timestamp, and we aren't fully loaded yet.
            long lastTimestamp = audioData.size() == 0 ? timestamp : audioData.get(audioData.size() - 1).getX();
            if (timestamp + DURATION_MS_PER_AUDIO_PLAYBACK_LOAD / 2 > lastTimestamp && !mFullyLoaded) {
                long xMaxToLoad = Math.min(lastTimestamp + DURATION_MS_PER_AUDIO_PLAYBACK_LOAD, xMax);
                mFullyLoaded = xMaxToLoad == xMax;
                dataController.getScalarReadings(sensorId, /* tier 0 */ 0,
                        TimeRange.oldest(Range.openClosed(lastTimestamp, xMaxToLoad)),
                        DATAPOINTS_PER_AUDIO_PLAYBACK_LOAD, new MaybeConsumer<ScalarReadingList>() {
                            @Override
                            public void success(ScalarReadingList list) {
                                audioData.addAll(list.asDataPoints());
                            }

                            @Override
                            public void fail(Exception e) {
                                Log.e(TAG, "Error loading audio playback data");
                                stopPlayback();
                            }
                        });
            }

            // Now play the tone, and get set up for the next callback, if one is needed.
            try {
                mAudioGenerator.addData(timestamp, point.getY(), yMin, yMax);
                mAudioPlaybackListener.onTimestampUpdated(timestamp);
            } finally {
                // If this is the second to last point, some special handling
                // needs to be done to determine when to make the last tone.
                if (audioData.size() > 0) {
                    // Play the next note after the time between this point and the
                    // next point has elapsed.
                    // mPlaybackIndex is now the index of the next point.
                    mHandler.postDelayed(mPlaybackRunnable, audioData.get(0).getX() - timestamp);
                } else {
                    // The last note gets some duration.
                    mHandler.postDelayed(mPlaybackRunnable, LAST_TONE_DURATION_MS);
                }
            }
        }
    };

    // Load the first set of scalar readings, and start playing as soon as they are loaded.
    dataController.getScalarReadings(sensorId, /* tier 0 */ 0,
            TimeRange.oldest(Range.closed(xMinToLoad, xMaxToLoad)), DATAPOINTS_PER_AUDIO_PLAYBACK_LOAD,
            new MaybeConsumer<ScalarReadingList>() {
                @Override
                public void success(ScalarReadingList list) {
                    audioData.addAll(list.asDataPoints());
                    mAudioGenerator.startPlaying();
                    mPlaybackRunnable.run();
                    mPlaybackStatus = PLAYBACK_STATUS_PLAYING;
                    mAudioPlaybackListener.onAudioPlaybackStarted();
                }

                @Override
                public void fail(Exception e) {
                    if (Log.isLoggable(TAG, Log.ERROR)) {
                        Log.e(TAG, "Error loading audio playback data");
                        stopPlayback();
                    }
                }
            });

    mPlaybackStatus = PLAYBACK_STATUS_LOADING;
}

From source file:org.eclipse.fx.ui.controls.styledtext.internal.VFlow.java

private void onNumberOfLinesChange(Observable x, Number o, Number n) {
    if (n.intValue() > o.intValue()) {
        RangeSet<Integer> toUpdate = TreeRangeSet.create();
        toUpdate.add(Range.closedOpen(Integer.valueOf(o.intValue()), Integer.valueOf(n.intValue())));
        triggerUpdate(toUpdate);//from  w w  w . ja  v  a2 s . c  om
    } else if (n.intValue() < o.intValue()) {
        RangeSet<Integer> toRelease = TreeRangeSet.create();
        toRelease.add(Range.closed(Integer.valueOf(n.intValue()), Integer.valueOf(o.intValue())));
        triggerRelease(toRelease);
    }
}

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

private void removeRunSensorData(final ExperimentRun run) {
    mSensorDataThread.execute(new Runnable() {

        @Override//from  w  ww  .ja  v a  2 s  .c o  m
        public void run() {
            TimeRange times = TimeRange.oldest(Range.closed(run.getFirstTimestamp(), run.getLastTimestamp()));
            for (String tag : run.getSensorTags()) {
                mSensorDatabase.deleteScalarReadings(tag, times);
            }
        }
    });
}

From source file:garmintools.sections.SectionManager.java

private static Map<Integer, SectionFactory<?>> createSectionFactories() {
    Set<Integer> allIds = new HashSet<>(
            ContiguousSet.create(Range.closed(0, Ids.MAX_SECTION_NUMBER), DiscreteDomain.integers()));

    ImmutableMap.Builder<Integer, SectionFactory<?>> builder = ImmutableMap.builder();
    for (SectionFactory<?> sectionFactory : SECTION_FACTORIES_LIST) {
        builder.put(sectionFactory.getSectionNumber(), sectionFactory);
        allIds.remove(sectionFactory.getSectionNumber());
    }//from  www.  j  a v a  2  s  .c  o m
    for (int unparsedSectionNumber : UNPARSED_SECTIONS) {
        builder.put(unparsedSectionNumber, new UnparsedSection.Factory(unparsedSectionNumber));
        allIds.remove(unparsedSectionNumber);
    }
    Preconditions.checkState(allIds.isEmpty(), "Unbound section(s): " + allIds);
    return builder.build();
}

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.druid.DruidIntervalUtils.java

protected static List<Range> leafToRanges(RelDataType type, RexCall call, boolean withNot) {
    switch (call.getKind()) {
    case EQUALS://w  w w. j  av a2  s .  co  m
    case LESS_THAN:
    case LESS_THAN_OR_EQUAL:
    case GREATER_THAN:
    case GREATER_THAN_OR_EQUAL: {
        RexLiteral literal = null;
        if (call.getOperands().get(0) instanceof RexInputRef
                && call.getOperands().get(1) instanceof RexLiteral) {
            literal = extractLiteral(call.getOperands().get(1));
        } else if (call.getOperands().get(0) instanceof RexInputRef
                && call.getOperands().get(1).getKind() == SqlKind.CAST) {
            literal = extractLiteral(call.getOperands().get(1));
        } else if (call.getOperands().get(1) instanceof RexInputRef
                && call.getOperands().get(0) instanceof RexLiteral) {
            literal = extractLiteral(call.getOperands().get(0));
        } else if (call.getOperands().get(1) instanceof RexInputRef
                && call.getOperands().get(0).getKind() == SqlKind.CAST) {
            literal = extractLiteral(call.getOperands().get(0));
        }
        if (literal == null) {
            return null;
        }
        Comparable value = literalToType(literal, type);
        if (value == null) {
            return null;
        }
        if (call.getKind() == SqlKind.LESS_THAN) {
            return Arrays.<Range>asList(withNot ? Range.atLeast(value) : Range.lessThan(value));
        } else if (call.getKind() == SqlKind.LESS_THAN_OR_EQUAL) {
            return Arrays.<Range>asList(withNot ? Range.greaterThan(value) : Range.atMost(value));
        } else if (call.getKind() == SqlKind.GREATER_THAN) {
            return Arrays.<Range>asList(withNot ? Range.atMost(value) : Range.greaterThan(value));
        } else if (call.getKind() == SqlKind.GREATER_THAN_OR_EQUAL) {
            return Arrays.<Range>asList(withNot ? Range.lessThan(value) : Range.atLeast(value));
        } else { //EQUALS
            if (!withNot) {
                return Arrays.<Range>asList(Range.closed(value, value));
            }
            return Arrays.<Range>asList(Range.lessThan(value), Range.greaterThan(value));
        }
    }
    case BETWEEN: {
        RexLiteral literal1 = extractLiteral(call.getOperands().get(2));
        if (literal1 == null) {
            return null;
        }
        RexLiteral literal2 = extractLiteral(call.getOperands().get(3));
        if (literal2 == null) {
            return null;
        }
        Comparable value1 = literalToType(literal1, type);
        Comparable value2 = literalToType(literal2, type);
        if (value1 == null || value2 == null) {
            return null;
        }
        boolean inverted = value1.compareTo(value2) > 0;
        if (!withNot) {
            return Arrays.<Range>asList(inverted ? Range.closed(value2, value1) : Range.closed(value1, value2));
        }
        return Arrays.<Range>asList(Range.lessThan(inverted ? value2 : value1),
                Range.greaterThan(inverted ? value1 : value2));
    }
    case IN: {
        List<Range> ranges = Lists.newArrayList();
        for (int i = 1; i < call.getOperands().size(); i++) {
            RexLiteral literal = extractLiteral(call.getOperands().get(i));
            if (literal == null) {
                return null;
            }
            Comparable element = literalToType(literal, type);
            if (element == null) {
                return null;
            }
            if (withNot) {
                ranges.addAll(Arrays.<Range>asList(Range.lessThan(element), Range.greaterThan(element)));
            } else {
                ranges.add(Range.closed(element, element));
            }
        }
        return ranges;
    }
    default:
        return null;
    }
}

From source file:org.apache.kylin.common.util.RangeUtil.java

public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) {
    ArrayList<Range<Integer>> ranges = Lists.newArrayList();

    if (values == null || values.isEmpty())
        return ranges;

    Iterator<Integer> iter = values.iterator();
    int lastBegin = iter.next();
    int lastEnd = lastBegin;
    int temp = 0;
    for (int index = 1; index < values.size(); index++) {
        temp = iter.next();// w w  w  . j a  v  a  2 s . co  m
        if (temp - lastEnd != 1) {
            ranges.add(Range.closed(lastBegin, lastEnd));
            lastBegin = temp;
        }
        lastEnd = temp;
    }
    ranges.add(Range.closed(lastBegin, lastEnd));
    return ranges;
}

From source file:com.yahoo.gondola.container.AdminClient.java

private Range<Integer> lookupMergeRange(String fromShardId, String toShardId) {
    // TODO: implement
    return Range.closed(1, 5);
}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsBottomPanel.java

/**
 * Returns a peak list with the top peaks defined by the parameter
 * "threshold"/*from   ww w  .ja  v a  2 s.  c  o  m*/
 */
PeakList getTopThresholdPeakList(int threshold) {

    PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
    if (selectedPeakList == null)
        return null;
    SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());

    Vector<PeakListRow> peakRows = new Vector<PeakListRow>();

    Range<Double> mzRange = selectedPeakList.getRowsMZRange();
    Range<Double> rtRange = selectedPeakList.getRowsRTRange();

    PeakThresholdMode selectedPeakOption = (PeakThresholdMode) thresholdCombo.getSelectedItem();
    if (selectedPeakOption == PeakThresholdMode.TOP_PEAKS_AREA) {
        XYPlot xyPlot = masterFrame.getPlot().getXYPlot();
        org.jfree.data.Range yAxis = xyPlot.getRangeAxis().getRange();
        org.jfree.data.Range xAxis = xyPlot.getDomainAxis().getRange();
        rtRange = Range.closed(xAxis.getLowerBound(), xAxis.getUpperBound());
        mzRange = Range.closed(yAxis.getLowerBound(), yAxis.getUpperBound());
    }

    for (PeakListRow peakRow : selectedPeakList.getRows()) {
        if (mzRange.contains(peakRow.getAverageMZ()) && rtRange.contains(peakRow.getAverageRT())) {
            peakRows.add(peakRow);
        }
    }

    Collections.sort(peakRows, new PeakListRowSorter(SortingProperty.Intensity, SortingDirection.Descending));

    if (threshold > peakRows.size())
        threshold = peakRows.size();
    for (int i = 0; i < threshold; i++) {
        newList.addRow(peakRows.elementAt(i));
    }
    return newList;
}