Example usage for com.google.common.collect RangeMap getEntry

List of usage examples for com.google.common.collect RangeMap getEntry

Introduction

In this page you can find the example usage for com.google.common.collect RangeMap getEntry.

Prototype

@Nullable
Map.Entry<Range<K>, V> getEntry(K key);

Source Link

Document

Returns the range containing this key and its associated value, if such a range is present in the range map, or null otherwise.

Usage

From source file:org.jpmml.evaluator.DiscretizationUtil.java

static public String discretize(Discretize discretize, double value) {
    RangeMap<Double, String> binRanges = CacheUtil.getValue(discretize, DiscretizationUtil.binRangeCache);

    Map.Entry<Range<Double>, String> entry = binRanges.getEntry(value);
    if (entry != null) {
        return entry.getValue();
    }/*from w  w w  .ja v  a  2s  . c  o  m*/

    return discretize.getDefaultValue();
}

From source file:radsoft.syntaxhighlighter.SyntaxHighlighter.java

private static void addMatch(RangeMap<Integer, String> matches, int start, int end, String styleKey) {
    if (styleKey == null)
        throw new NullPointerException("argument 'styleKey' cannot be null");
    Map.Entry<Range<Integer>, String> e = matches.getEntry(start);
    if (e == null || start < e.getKey().lowerEndpoint()) {
        if (e != null)
            matches.remove(e.getKey());/*from w ww. ja v  a 2  s . co  m*/
        e = matches.getEntry(end - 1);
        if (e != null)
            matches.remove(e.getKey());

        Range<Integer> r = Range.closedOpen(start, end);
        matches.put(r, styleKey);
    }
}

From source file:org.waveprotocol.box.server.persistence.blocks.impl.BlockIndexImpl.java

@Override
public synchronized void update(Fragment fragment) {
    RangeMap<RangeValue, String> ranges = getRanges(fragment.getSegmentId());
    Map.Entry<Range<RangeValue>, String> entry = ranges.getEntry(RangeValue.of(fragment.getStartVersion()));
    if (entry != null) {
        Preconditions.checkArgument(entry.getValue().equals(fragment.getBlock().getBlockId()),
                "New range overlaps an existing by block Id");
        Preconditions.checkArgument(fragment.getStartVersion() == entry.getKey().lowerEndpoint().get(),
                "New range overlaps an existing by start version");
        entry.getKey().upperEndpoint()/*  ww w .  j a  v  a2  s  . c  o m*/
                .set(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion());
    } else {
        ranges.put(
                Range.closed(RangeValue.of(fragment.getStartVersion()),
                        RangeValue.of(fragment.isLast() ? Long.MAX_VALUE : fragment.getLastModifiedVersion())),
                fragment.getBlock().getBlockId());
    }
}