本文整理汇总了Java中java.util.SortedMap.comparator方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.comparator方法的具体用法?Java SortedMap.comparator怎么用?Java SortedMap.comparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedMap
的用法示例。
在下文中一共展示了SortedMap.comparator方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyOfSorted
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* 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());
}
示例2: copyOfInternal
import java.util.SortedMap; //导入方法依赖的package包/类
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());
}
示例3: isDescending
import java.util.SortedMap; //导入方法依赖的package包/类
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);
}
示例4: copyOfSorted
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* 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;
}
return copyOfInternal(map, comparator);
}
示例5: copyOfInternal
import java.util.SortedMap; //导入方法依赖的package包/类
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;
}
}
// "adding" type params to an array of a raw type should be safe as
// long as no one can ever cast that same array instance back to a
// raw type.
@SuppressWarnings("unchecked")
Entry<K, V>[] entries = map.entrySet().toArray(new Entry[0]);
return fromEntries(comparator, sameComparator, entries.length, entries);
}
示例6: copyOfSorted
import java.util.SortedMap; //导入方法依赖的package包/类
public static <K, V> ImmutableSortedMap<K, V> copyOfSorted(
SortedMap<K, ? extends V> map) {
// If map has a null comparator, the keys should have a natural ordering,
// even though K doesn't explicitly implement Comparable.
@SuppressWarnings("unchecked")
Comparator<? super K> comparator =
(map.comparator() == null) ? NATURAL_ORDER : map.comparator();
return copyOfInternal(map, comparator);
}
示例7: assertSortedMapCharacteristics
import java.util.SortedMap; //导入方法依赖的package包/类
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());
}
示例8: TreeMapBST
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Constructs a new tree map containing the same mappings and
* using the same ordering as the specified sorted map. This
* method runs in linear time.
*
* @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 map is null
*/
public TreeMapBST(SortedMap<K, ? extends V> m) {
comparator = m.comparator();
// try {
// buildFromSorted(m.size(), m.entrySet().iterator(), null, null);
// } catch (java.io.IOException cannotHappen) {
// } catch (ClassNotFoundException cannotHappen) {
// }
}
示例9: PersistentSortedMap
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Constructs a PersistentSortedMap.
*
* @param session The session
* @param map The underlying map data
*/
public PersistentSortedMap(SessionImplementor session, SortedMap map) {
super( session, map );
comparator = map.comparator();
}
示例10: ConcurrentSkipListMap
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* 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);
}