當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。