当前位置: 首页>>代码示例>>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;未经允许,请勿转载。