Java Code Examples for java.util.SortedMap#comparator()
The following examples show how to use
java.util.SortedMap#comparator() .
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
Source Project: openjdk-8 File: EmptyNavigableMap.java License: GNU General Public License v2.0 | 6 votes |
public static final boolean isDescending(SortedMap<?,?> set) { if (null == set.comparator()) { // natural order return false; } if (Collections.reverseOrder() == set.comparator()) { // reverse natural order. return true; } if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) { // it's a Collections.reverseOrder(Comparator). return true; } throw new IllegalStateException("can't determine ordering for " + set); }
Example 2
Source Project: codebuff File: ImmutableSortedMap.java License: BSD 2-Clause "Simplified" License | 6 votes |
private static <K, V> ImmutableSortedMap<K, V> copyOfInternal(Map<? extends K, ? extends V> map, Comparator<? super K> comparator) { boolean sameComparator = false; if (map instanceof SortedMap) { SortedMap<?, ?> sortedMap = (SortedMap<?, ?>) map; Comparator<?> comparator2 = sortedMap.comparator(); sameComparator = (comparator2 == null) ? comparator == NATURAL_ORDER: comparator.equals(comparator2); } if (sameComparator && (map instanceof ImmutableSortedMap)) { // TODO(kevinb): Prove that this cast is safe, even though // Collections.unmodifiableSortedMap requires the same key type. @SuppressWarnings("unchecked") ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map; if (!kvMap.isPartialView()) { return kvMap; } } return fromEntries(comparator, sameComparator, map.entrySet()); }
Example 3
Source Project: codebuff File: ImmutableSortedMap.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns an immutable map containing the same entries as the provided sorted * map, with the same ordering. * * <p>Despite the method name, this method attempts to avoid actually copying * the data when it is safe to do so. The exact circumstances under which a * copy will or will not be performed are undocumented and subject to change. * * @throws NullPointerException if any key or value in {@code map} is null */ @SuppressWarnings("unchecked") public static <K, V> ImmutableSortedMap<K, V> copyOfSorted(SortedMap<K, ? extends V> map) { Comparator<? super K> comparator = map.comparator(); if (comparator == null) { // If map has a null comparator, the keys should have a natural ordering, // even though K doesn't explicitly implement Comparable. comparator = (Comparator<? super K>) NATURAL_ORDER; } if (map instanceof ImmutableSortedMap) { // TODO(kevinb): Prove that this cast is safe, even though // Collections.unmodifiableSortedMap requires the same key type. @SuppressWarnings("unchecked") ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map; if (!kvMap.isPartialView()) { return kvMap; } } return fromEntries(comparator, true, map.entrySet()); }
Example 4
Source Project: jdk8u-dev-jdk File: EmptyNavigableMap.java License: GNU General Public License v2.0 | 6 votes |
public static final boolean isDescending(SortedMap<?,?> set) { if (null == set.comparator()) { // natural order return false; } if (Collections.reverseOrder() == set.comparator()) { // reverse natural order. return true; } if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) { // it's a Collections.reverseOrder(Comparator). return true; } throw new IllegalStateException("can't determine ordering for " + set); }
Example 5
Source Project: jdk8u_jdk File: EmptyNavigableMap.java License: GNU General Public License v2.0 | 6 votes |
public static final boolean isDescending(SortedMap<?,?> set) { if (null == set.comparator()) { // natural order return false; } if (Collections.reverseOrder() == set.comparator()) { // reverse natural order. return true; } if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) { // it's a Collections.reverseOrder(Comparator). return true; } throw new IllegalStateException("can't determine ordering for " + set); }
Example 6
Source Project: codebuff File: ImmutableSortedMap.java License: BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns an immutable map containing the same entries as the provided sorted * map, with the same ordering. * * <p>Despite the method name, this method attempts to avoid actually copying * the data when it is safe to do so. The exact circumstances under which a * copy will or will not be performed are undocumented and subject to change. * * @throws NullPointerException if any key or value in {@code map} is null */ @SuppressWarnings("unchecked") public static <K, V> ImmutableSortedMap<K, V> copyOfSorted(SortedMap<K, ? extends V> map) { Comparator<? super K> comparator = map.comparator(); if (comparator == null) { // If map has a null comparator, the keys should have a natural ordering, // even though K doesn't explicitly implement Comparable. comparator = (Comparator<? super K>) NATURAL_ORDER; } if (map instanceof ImmutableSortedMap) { // TODO(kevinb): Prove that this cast is safe, even though // Collections.unmodifiableSortedMap requires the same key type. @SuppressWarnings("unchecked") ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map; if (!kvMap.isPartialView()) { return kvMap; } } return fromEntries(comparator, true, map.entrySet()); }
Example 7
Source Project: openjdk-8-source File: EmptyNavigableMap.java License: GNU General Public License v2.0 | 6 votes |
public static final boolean isDescending(SortedMap<?,?> set) { if (null == set.comparator()) { // natural order return false; } if (Collections.reverseOrder() == set.comparator()) { // reverse natural order. return true; } if (set.comparator().equals(Collections.reverseOrder(Collections.reverseOrder(set.comparator())))) { // it's a Collections.reverseOrder(Comparator). return true; } throw new IllegalStateException("can't determine ordering for " + set); }
Example 8
Source Project: dragonwell8_jdk File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 9
Source Project: streamsupport File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 10
Source Project: openjdk-jdk9 File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 11
Source Project: jdk8u60 File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 12
Source Project: jdk8u_jdk File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 13
Source Project: jdk8u-dev-jdk File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 14
Source Project: jdk8u-jdk File: SpliteratorCharacteristics.java License: GNU General Public License v2.0 | 5 votes |
void assertSortedMapCharacteristics(SortedMap<Integer, String> m, int keyCharacteristics) { assertMapCharacteristics(m, keyCharacteristics, Spliterator.SORTED); Set<Integer> keys = m.keySet(); if (m.comparator() != null) { assertNotNullComparator(keys); } else { assertNullComparator(keys); } assertISEComparator(m.values()); assertNotNullComparator(m.entrySet()); }
Example 15
Source Project: cacheonix-core File: PersistentSortedMap.java License: GNU Lesser General Public License v2.1 | 4 votes |
public PersistentSortedMap(SessionImplementor session, SortedMap map) { super(session, map); comparator = map.comparator(); }
Example 16
Source Project: TencentKona-8 File: ConcurrentSkipListMap.java License: GNU General Public License v2.0 | 2 votes |
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Example 17
Source Project: openjdk-jdk9 File: ConcurrentSkipListMap.java License: GNU General Public License v2.0 | 2 votes |
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Example 18
Source Project: openjdk-jdk8u File: ConcurrentSkipListMap.java License: GNU General Public License v2.0 | 2 votes |
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Example 19
Source Project: j2objc File: ConcurrentSkipListMap.java License: Apache License 2.0 | 2 votes |
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }
Example 20
Source Project: openjdk-jdk8u-backup File: ConcurrentSkipListMap.java License: GNU General Public License v2.0 | 2 votes |
/** * Constructs a new map containing the same mappings and using the * same ordering as the specified sorted map. * * @param m the sorted map whose mappings are to be placed in this * map, and whose comparator is to be used to sort this map * @throws NullPointerException if the specified sorted map or any of * its keys or values are null */ public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) { this.comparator = m.comparator(); initialize(); buildFromSorted(m); }