當前位置: 首頁>>代碼示例>>Java>>正文


Java Comparator.equals方法代碼示例

本文整理匯總了Java中java.util.Comparator.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Comparator.equals方法的具體用法?Java Comparator.equals怎麽用?Java Comparator.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Comparator的用法示例。


在下文中一共展示了Comparator.equals方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyOf

import java.util.Comparator; //導入方法依賴的package包/類
/**
 * Returns an immutable sorted multiset containing the given elements sorted by the given {@code
 * Comparator}. This method iterates over {@code elements} at most once.
 *
 * <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 {@code comparator} or any of {@code elements} is null
 */
public static <E> ImmutableSortedMultiset<E> copyOf(
    Comparator<? super E> comparator, Iterable<? extends E> elements) {
  if (elements instanceof ImmutableSortedMultiset) {
    @SuppressWarnings("unchecked") // immutable collections are always safe for covariant casts
    ImmutableSortedMultiset<E> multiset = (ImmutableSortedMultiset<E>) elements;
    if (comparator.equals(multiset.comparator())) {
      if (multiset.isPartialView()) {
        return copyOfSortedEntries(comparator, multiset.entrySet().asList());
      } else {
        return multiset;
      }
    }
  }
  elements = Lists.newArrayList(elements); // defensive copy
  TreeMultiset<E> sortedCopy = TreeMultiset.create(checkNotNull(comparator));
  Iterables.addAll(sortedCopy, elements);
  return copyOfSortedEntries(comparator, sortedCopy.entrySet());
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:29,代碼來源:ImmutableSortedMultiset.java

示例2: putAll

import java.util.Comparator; //導入方法依賴的package包/類
/**
 * Copies all of the mappings from the specified map to this map.
 * These mappings replace any mappings that this map had for any
 * of the keys currently in the specified map.
 *
 * @param  map mappings to be stored in this map
 * @throws ClassCastException if the class of a key or value in
 *         the specified map prevents it from being stored in this map
 * @throws NullPointerException if the specified map is null or
 *         the specified map contains a null key and this map does not
 *         permit null keys
 */
public void putAll(Map<? extends K, ? extends V> map) {
    int mapSize = map.size();
    if (size==0 && mapSize!=0 && map instanceof SortedMap) {
        Comparator<?> c = ((SortedMap<?,?>)map).comparator();
        if (c == comparator || (c != null && c.equals(comparator))) {
            ++modCount;
//            try {
//                buildFromSorted(mapSize, map.entrySet().iterator(), null, null);
//            } catch (java.io.IOException cannotHappen) {
//            } catch (ClassNotFoundException cannotHappen) {
//            }
            return;
        }
    }
    super.putAll(map);
}
 
開發者ID:dmcmanam,項目名稱:bbst-showdown,代碼行數:29,代碼來源:TreeMapBST.java

示例3: copyOfInternal

import java.util.Comparator; //導入方法依賴的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

示例4: copyOfInternal

import java.util.Comparator; //導入方法依賴的package包/類
private static <K, V> ImmutableSortedMap<K, V> copyOfInternal(
    Map<? extends K, ? extends V> map, Comparator<? super K> comparator) {

  if (map instanceof ImmutableSortedMap) {
    // TODO: 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;
    Comparator<?> comparator2 = kvMap.comparator();
    boolean sameComparator = (comparator2 == null)
        ? comparator == NATURAL_ORDER
        : comparator.equals(comparator2);
    if (sameComparator) {
      return kvMap;
    }
  }

  SortedMap<K, V> delegate = newModifiableDelegate(comparator);
  for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
    putEntryWithChecks(delegate, entry);
  }
  return newView(unmodifiableSortedMap(delegate), comparator);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:24,代碼來源:ImmutableSortedMap.java

示例5: addAll

import java.util.Comparator; //導入方法依賴的package包/類
/**
   * Adds all of the elements in the specified collection to this list.
   *
   * @param c elements to be added
   * @return <tt>true</tt> if this list changed as a result of the call.
   */
  @SuppressWarnings("unchecked")
public boolean addAll(Collection<? extends E> c)
  {
    if (m.size() == 0 && c.size() > 0 && c instanceof SortedList &&
      m instanceof IndexedTreeMap)
    {
      SortedList<Map.Entry<E,Object>> list = (SortedList<Map.Entry<E,Object>>)c;
      IndexedTreeMap<E,Object> map = (IndexedTreeMap<E,Object>)m;
      Comparator<? super E> cc = (Comparator<E>)list.comparator();
      Comparator<? super E> mc = map.comparator();
      if (cc == mc || (cc != null && cc.equals(mc)))
      {
        map.addAllForTreeList(list, PRESENT);
        return true;
      }
    }
    return super.addAll(c);
  }
 
開發者ID:cinnober,項目名稱:ciguan,代碼行數:25,代碼來源:TreeList.java

示例6: hasSameComparator

import java.util.Comparator; //導入方法依賴的package包/類
/**
 * Returns {@code true} if {@code elements} is a sorted collection using an ordering equivalent
 * to {@code comparator}.
 */
public static boolean hasSameComparator(Comparator<?> comparator, Iterable<?> elements) {
  checkNotNull(comparator);
  checkNotNull(elements);
  Comparator<?> comparator2;
  if (elements instanceof SortedSet) {
    comparator2 = comparator((SortedSet<?>) elements);
  } else if (elements instanceof SortedIterable) {
    comparator2 = ((SortedIterable<?>) elements).comparator();
  } else {
    return false;
  }
  return comparator.equals(comparator2);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:18,代碼來源:SortedIterables.java

示例7: copyOfInternal

import java.util.Comparator; //導入方法依賴的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

示例8: hasSameComparator

import java.util.Comparator; //導入方法依賴的package包/類
private static boolean hasSameComparator(
    Iterable<?> elements, Comparator<?> comparator) {
  if (elements instanceof SortedSet) {
    SortedSet<?> sortedSet = (SortedSet<?>) elements;
    Comparator<?> comparator2 = sortedSet.comparator();
    return (comparator2 == null)
        ? comparator == Ordering.natural()
        : comparator.equals(comparator2);
  }
  return false;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:12,代碼來源:ImmutableSortedSet.java


注:本文中的java.util.Comparator.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。