Java Code Examples for java.util.Collections#unmodifiableNavigableMap()

The following examples show how to use java.util.Collections#unmodifiableNavigableMap() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] values, Comparator<BigDecimal> comparator) {

    if (values == null) {
        return null;
    }

    NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(comparator);

    Stream.of(values)
            .filter(ArrayUtils::isNotEmpty)
            .filter(ps -> ps.length == 2)
            .filter(ps -> ps[0] != null)
            .filter(ps -> ps[1] != null)
            .forEach(ps -> map.put(ps[0], ps[1]))
    ;

    return Collections.unmodifiableNavigableMap(map);

}
 
Example 2
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] values, Comparator<BigDecimal> comparator) {

    if (values == null) {
        return null;
    }

    NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(comparator);

    Stream.of(values)
            .filter(ArrayUtils::isNotEmpty)
            .filter(ps -> ps.length == 2)
            .filter(ps -> ps[0] != null)
            .filter(ps -> ps[1] != null)
            .forEach(ps -> map.put(ps[0], ps[1]))
    ;

    return Collections.unmodifiableNavigableMap(map);

}
 
Example 3
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] values, boolean asc) {

    NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(asc ? NATURAL : REVERSE);

    if (ArrayUtils.isNotEmpty(values)) {

        Stream.of(values)
                .filter(ArrayUtils::isNotEmpty)
                .filter(ps -> ps.length == 2)
                .filter(ps -> ps[0] != null)
                .filter(ps -> ps[1] != null)
                .forEach(ps -> map.put(ps[0], ps[1]))
        ;

    }

    return Collections.unmodifiableNavigableMap(map);

}
 
Example 4
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] values, boolean asc) {

    NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(asc ? NATURAL : REVERSE);

    if (ArrayUtils.isNotEmpty(values)) {

        Stream.of(values)
                .filter(ArrayUtils::isNotEmpty)
                .filter(ps -> ps.length == 2)
                .filter(ps -> ps[0] != null)
                .filter(ps -> ps[1] != null)
                .forEach(ps -> map.put(ps[0], ps[1]))
        ;

    }

    return Collections.unmodifiableNavigableMap(map);

}
 
Example 5
Source Project: Bats   File: NameMap.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns a map containing all the entries in the map that match the given
 * name. If case-sensitive, that map will have 0 or 1 elements; if
 * case-insensitive, it may have 0 or more. */
public NavigableMap<String, V> range(String name, boolean caseSensitive) {
  Object floorKey;
  Object ceilingKey;
  if (caseSensitive) {
    floorKey = name;
    ceilingKey = name;
  } else {
    floorKey = COMPARATOR.floorKey(name);
    ceilingKey = COMPARATOR.ceilingKey(name);
  }
  NavigableMap subMap = ((NavigableMap) map).subMap(floorKey, true, ceilingKey, true);
  return Collections.unmodifiableNavigableMap((NavigableMap<String, V>) subMap);
}
 
Example 6
Source Project: Quicksql   File: NameMap.java    License: MIT License 5 votes vote down vote up
/** Returns a map containing all the entries in the map that match the given
 * name. If case-sensitive, that map will have 0 or 1 elements; if
 * case-insensitive, it may have 0 or more. */
public NavigableMap<String, V> range(String name, boolean caseSensitive) {
  Object floorKey;
  Object ceilingKey;
  if (caseSensitive) {
    floorKey = name;
    ceilingKey = name;
  } else {
    floorKey = COMPARATOR.floorKey(name);
    ceilingKey = COMPARATOR.ceilingKey(name);
  }
  NavigableMap subMap = ((NavigableMap) map).subMap(floorKey, true, ceilingKey, true);
  return Collections.unmodifiableNavigableMap((NavigableMap<String, V>) subMap);
}
 
Example 7
public CollectionFields build() {
  List<String> _strings = (strings != null) ? Collections.unmodifiableList(new ArrayList<String>(strings)) : Collections.<String>emptyList();
  Map<String, Integer> _integers = (integers != null) ? Collections.unmodifiableMap(new HashMap<String, Integer>(integers)) : Collections.<String, Integer>emptyMap();
  SortedMap<String, Integer> _sortedIntegers = (sortedIntegers != null) ? Collections.unmodifiableSortedMap(new TreeMap<String, Integer>(sortedIntegers)) : Collections.<String, Integer>emptySortedMap();
  NavigableMap<String, Integer> _navigableIntegers = (navigableIntegers != null) ? Collections.unmodifiableNavigableMap(new TreeMap<String, Integer>(navigableIntegers)) : Collections.<String, Integer>emptyNavigableMap();
  Set<Long> _numbers = (numbers != null) ? Collections.unmodifiableSet(new HashSet<Long>(numbers)) : Collections.<Long>emptySet();
  SortedSet<Long> _sortedNumbers = (sortedNumbers != null) ? Collections.unmodifiableSortedSet(new TreeSet<Long>(sortedNumbers)) : Collections.<Long>emptySortedSet();
  NavigableSet<Long> _navigableNumbers = (navigableNumbers != null) ? Collections.unmodifiableNavigableSet(new TreeSet<Long>(navigableNumbers)) : Collections.<Long>emptyNavigableSet();
  return new Value(_strings, _integers, _sortedIntegers, _navigableIntegers, _numbers, _sortedNumbers, _navigableNumbers);
}
 
Example 8
Source Project: ph-commons   File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsImmutableObject
@CodingStyleguideUnaware
public static <KEYTYPE, VALUETYPE> NavigableMap <KEYTYPE, VALUETYPE> makeUnmodifiable (@Nullable final NavigableMap <KEYTYPE, VALUETYPE> aNavigableMap)
{
  return aNavigableMap == null ? null : Collections.unmodifiableNavigableMap (aNavigableMap);
}
 
Example 9
Source Project: ph-commons   File: CollectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@ReturnsImmutableObject
@CodingStyleguideUnaware
public static <KEYTYPE extends Comparable <? super KEYTYPE>, VALUETYPE> NavigableMap <KEYTYPE, VALUETYPE> makeUnmodifiableNotNull (@Nullable final NavigableMap <KEYTYPE, VALUETYPE> aNavigableMap)
{
  return aNavigableMap == null ? Collections.emptyNavigableMap ()
                               : Collections.unmodifiableNavigableMap (aNavigableMap);
}
 
Example 10
Source Project: ph-commons   File: ICommonsNavigableMap.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@CodingStyleguideUnaware
default NavigableMap <KEYTYPE, VALUETYPE> getAsUnmodifiable ()
{
  return Collections.unmodifiableNavigableMap (this);
}
 
Example 11
Source Project: calcite   File: NameMap.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns a map containing all the entries in the map that match the given
 * name. If case-sensitive, that map will have 0 or 1 elements; if
 * case-insensitive, it may have 0 or more. */
public NavigableMap<String, V> range(String name, boolean caseSensitive) {
  Object floorKey;
  Object ceilingKey;
  if (caseSensitive) {
    floorKey = name;
    ceilingKey = name;
  } else {
    floorKey = COMPARATOR.floorKey(name);
    ceilingKey = COMPARATOR.ceilingKey(name);
  }
  NavigableMap subMap = ((NavigableMap) map).subMap(floorKey, true, ceilingKey, true);
  return Collections.unmodifiableNavigableMap((NavigableMap<String, V>) subMap);
}
 
Example 12
public NavigableMap<Double, RoboTaxiPlanEntry> getPlans() {
    return Collections.unmodifiableNavigableMap(plans);
}
 
Example 13
Source Project: Diorite   File: ConfigPropertyTemplateImpl.java    License: MIT License 4 votes vote down vote up
@Nullable
@Override
public T get(ConfigPropertyValue<T> propertyValue)
{
    T rawValue = propertyValue.getRawValue();
    if (rawValue == null)
    {
        return null;
    }
    if (this.returnUnmodifiableCollections)
    {
        if (rawValue instanceof Collection)
        {
            if (rawValue instanceof Set)
            {
                if (rawValue instanceof NavigableSet)
                {
                    return (T) Collections.unmodifiableNavigableSet((NavigableSet<?>) rawValue);
                }
                if (rawValue instanceof SortedSet)
                {
                    return (T) Collections.unmodifiableSortedSet((SortedSet<?>) rawValue);
                }
                return (T) Collections.unmodifiableSet((Set<?>) rawValue);
            }
            if (rawValue instanceof List)
            {
                return (T) Collections.unmodifiableList((List<?>) rawValue);
            }
            return (T) Collections.unmodifiableCollection((Collection<?>) rawValue);
        }
        else if (rawValue instanceof Map)
        {
            if (rawValue instanceof NavigableMap)
            {
                return (T) Collections.unmodifiableNavigableMap((NavigableMap<?, ?>) rawValue);
            }
            if (rawValue instanceof SortedMap)
            {
                return (T) Collections.unmodifiableSortedMap((SortedMap<?, ?>) rawValue);
            }
            return (T) Collections.unmodifiableMap((Map<?, ?>) rawValue);
        }
    }
    return rawValue;
}
 
Example 14
UnitImpl(NavigableMap<String, IExpr> navigableMap) {
	this.navigableMap = Collections.unmodifiableNavigableMap(navigableMap);
}
 
Example 15
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> getSfdTable() {

    String value = StringUtils.trimToEmpty(getStringProperty(KEY_SFD_TBL, null));

    NavigableMap<BigDecimal, BigDecimal> table = sfdCache.getIfPresent(value);

    if (table == null) {

        try {

            NavigableMap<BigDecimal, BigDecimal> m = new TreeMap<>();

            for (String entry : StringUtils.split(value, '|')) {

                String[] kv = StringUtils.split(entry, ':');

                BigDecimal k = new BigDecimal(kv[0]);

                BigDecimal v = new BigDecimal(kv[1]);

                m.put(k, v);

            }

            table = m.isEmpty() ? SFD : Collections.unmodifiableNavigableMap(m);

        } catch (Exception e) {

            table = SFD;

        }

        sfdCache.put(value, table);

    }

    return table;

}
 
Example 16
@VisibleForTesting
NavigableMap<BigDecimal, BigDecimal> convert(BigDecimal[][] quotes, Comparator<BigDecimal> c) {

    NavigableMap<BigDecimal, BigDecimal> map = new TreeMap<>(c);

    if (ArrayUtils.isNotEmpty(quotes)) {

        for (BigDecimal[] quote : quotes) {

            if (quote.length != 2) {
                continue;
            }

            if (quote[0] == null || quote[0].signum() == 0) {
                continue;
            }

            if (quote[1] == null || quote[1].signum() == 0) {
                continue;
            }

            map.put(quote[0], quote[1]);

        }

    }

    return Collections.unmodifiableNavigableMap(map);

}
 
Example 17
Source Project: pravega   File: StreamSegments.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of the StreamSegments class.
 *
 * @param segments Segments of a stream, keyed by the largest key in their key range.
 *                 i.e. If there are two segments split evenly, the first should have a value of 0.5 and the second 1.0.
 * @param delegationToken Delegation token to access the segments in the segmentstore
 */
public StreamSegments(NavigableMap<Double, SegmentWithRange> segments, String delegationToken) {
    this.segments = Collections.unmodifiableNavigableMap(segments);
    this.delegationToken = delegationToken;
    verifySegments();
}