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

The following examples show how to use java.util.Collections#unmodifiableNavigableMap() . 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
Source File: FiscoDepth.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@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
Source File: ZaifDepth.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@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
Source File: QuoinexBook.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@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
Source File: BtcboxDepth.java    From cryptotrader with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 File: NameMap.java    From Quicksql with 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 6
Source File: NameMap.java    From calcite with 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 7
Source File: ICommonsNavigableMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@CodingStyleguideUnaware
default NavigableMap <KEYTYPE, VALUETYPE> getAsUnmodifiable ()
{
  return Collections.unmodifiableNavigableMap (this);
}
 
Example 8
Source File: CollectionHelper.java    From ph-commons with 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 9
Source File: CollectionHelper.java    From ph-commons with 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 10
Source File: CollectionFieldsBuilder.java    From auto-matter with Apache License 2.0 5 votes vote down vote up
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 11
Source File: NameMap.java    From Bats with 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
Source File: ConfigPropertyTemplateImpl.java    From Diorite with 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 13
Source File: RoboTaxiPlan.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
public NavigableMap<Double, RoboTaxiPlanEntry> getPlans() {
    return Collections.unmodifiableNavigableMap(plans);
}
 
Example 14
Source File: UnitImpl.java    From symja_android_library with GNU General Public License v3.0 4 votes vote down vote up
UnitImpl(NavigableMap<String, IExpr> navigableMap) {
	this.navigableMap = Collections.unmodifiableNavigableMap(navigableMap);
}
 
Example 15
Source File: BitbankDepth.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 16
Source File: BitflyerAdviser.java    From cryptotrader with GNU Affero General Public License v3.0 3 votes vote down vote up
@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 17
Source File: StreamSegments.java    From pravega with 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();
}