当前位置: 首页>>代码示例>>Java>>正文


Java SortedMap.comparator方法代码示例

本文整理汇总了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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:30,代码来源:ImmutableSortedMap.java

示例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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:ImmutableSortedMap.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:EmptyNavigableMap.java

示例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);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:22,代码来源:ImmutableSortedMap.java

示例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);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:30,代码来源:ImmutableSortedMap.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:ImmutableSortedMap.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:SpliteratorCharacteristics.java

示例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) {
//    }
}
 
开发者ID:dmcmanam,项目名称:bbst-showdown,代码行数:18,代码来源:TreeMapBST.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:PersistentSortedMap.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:ConcurrentSkipListMap.java


注:本文中的java.util.SortedMap.comparator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。