Java Code Examples for java.util.SortedMap#comparator()
The following examples show how to use
java.util.SortedMap#comparator() .
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: ImmutableSortedMap.java From codebuff with 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 2
Source File: EmptyNavigableMap.java From openjdk-8-source with 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 3
Source File: ImmutableSortedMap.java From codebuff with 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 File: ImmutableSortedMap.java From codebuff with 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 5
Source File: EmptyNavigableMap.java From jdk8u-dev-jdk with 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 File: EmptyNavigableMap.java From jdk8u_jdk with 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 7
Source File: EmptyNavigableMap.java From openjdk-8 with 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 File: SpliteratorCharacteristics.java From jdk8u60 with 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 File: SpliteratorCharacteristics.java From jdk8u-jdk with 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 File: SpliteratorCharacteristics.java From jdk8u-dev-jdk with 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 File: SpliteratorCharacteristics.java From jdk8u_jdk with 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 File: SpliteratorCharacteristics.java From openjdk-jdk9 with 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 File: SpliteratorCharacteristics.java From streamsupport with 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 File: SpliteratorCharacteristics.java From dragonwell8_jdk with 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 File: PersistentSortedMap.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public PersistentSortedMap(SessionImplementor session, SortedMap map) { super(session, map); comparator = map.comparator(); }
Example 16
Source File: ConcurrentSkipListMap.java From openjdk-jdk8u with 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 File: ConcurrentSkipListMap.java From j2objc with 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 18
Source File: ConcurrentSkipListMap.java From openjdk-jdk9 with 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 File: ConcurrentSkipListMap.java From openjdk-jdk8u-backup with 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 20
Source File: ConcurrentSkipListMap.java From TencentKona-8 with 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); }