com.google.common.collect.Maps.orNaturalOrder()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中com.google.common.collect.Maps.orNaturalOrder()方法的一些代码示例,展示了Maps.orNaturalOrder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Maps.orNaturalOrder()方法的具体详情如下:
包路径:com.google.common.collect.Maps
类名称:Maps
方法名:orNaturalOrder

Maps.orNaturalOrder介绍

[英]Returns the specified comparator if not null; otherwise returns Ordering.natural(). This method is an abomination of generics; the only purpose of this method is to contain the ugly type-casting in one place.
[中]如果不为空,则返回指定的比较器;否则返回订单。自然的。这种方法是对仿制药的厌恶;这种方法的唯一目的是在一个地方容纳丑陋的类型铸件。

代码示例

代码示例来源:origin: google/guava

/**
 * Computes the difference between two sorted maps, using the comparator of the left map, or
 * {@code Ordering.natural()} if the left map uses the natural ordering of its elements. This
 * difference is an immutable snapshot of the state of the maps at the time this method is called.
 * It will never change, even if the maps change at a later time.
 *
 * <p>Since this method uses {@code TreeMap} instances internally, the keys of the right map must
 * all compare as distinct according to the comparator of the left map.
 *
 * <p><b>Note:</b>If you only need to know whether two sorted maps have the same mappings, call
 * {@code left.equals(right)} instead of this method.
 *
 * @param left the map to treat as the "left" map for purposes of comparison
 * @param right the map to treat as the "right" map for purposes of comparison
 * @return the difference between the two maps
 * @since 11.0
 */
public static <K, V> SortedMapDifference<K, V> difference(
  SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right) {
 checkNotNull(left);
 checkNotNull(right);
 Comparator<? super K> comparator = orNaturalOrder(left.comparator());
 SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
 SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);
 onlyOnRight.putAll(right); // will whittle it down
 SortedMap<K, V> onBoth = Maps.newTreeMap(comparator);
 SortedMap<K, MapDifference.ValueDifference<V>> differences = Maps.newTreeMap(comparator);
 doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences);
 return new SortedMapDifferenceImpl<>(onlyOnLeft, onlyOnRight, onBoth, differences);
}

代码示例来源:origin: google/j2objc

private enum EntryFunction implements Function<Entry<?, ?>, Object> {
 KEY {
  @Override
  @NullableDecl
  public Object apply(Entry<?, ?> entry) {
   return entry.getKey();
  }
 },
 VALUE {
  @Override
  @NullableDecl
  public Object apply(Entry<?, ?> entry) {
   return entry.getValue();
  }
 };
}

代码示例来源:origin: wildfly/wildfly

/**
 * Computes the difference between two sorted maps, using the comparator of the left map, or
 * {@code Ordering.natural()} if the left map uses the natural ordering of its elements. This
 * difference is an immutable snapshot of the state of the maps at the time this method is called.
 * It will never change, even if the maps change at a later time.
 *
 * <p>Since this method uses {@code TreeMap} instances internally, the keys of the right map must
 * all compare as distinct according to the comparator of the left map.
 *
 * <p><b>Note:</b>If you only need to know whether two sorted maps have the same mappings, call
 * {@code left.equals(right)} instead of this method.
 *
 * @param left the map to treat as the "left" map for purposes of comparison
 * @param right the map to treat as the "right" map for purposes of comparison
 * @return the difference between the two maps
 * @since 11.0
 */
public static <K, V> SortedMapDifference<K, V> difference(
  SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right) {
 checkNotNull(left);
 checkNotNull(right);
 Comparator<? super K> comparator = orNaturalOrder(left.comparator());
 SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
 SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);
 onlyOnRight.putAll(right); // will whittle it down
 SortedMap<K, V> onBoth = Maps.newTreeMap(comparator);
 SortedMap<K, MapDifference.ValueDifference<V>> differences = Maps.newTreeMap(comparator);
 doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences);
 return new SortedMapDifferenceImpl<>(onlyOnLeft, onlyOnRight, onBoth, differences);
}

代码示例来源:origin: Nextdoor/bender

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: org.hudsonci.lib.guava/guava

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Computes the difference between two sorted maps, using the comparator of the left map, or
 * {@code Ordering.natural()} if the left map uses the natural ordering of its elements. This
 * difference is an immutable snapshot of the state of the maps at the time this method is called.
 * It will never change, even if the maps change at a later time.
 *
 * <p>Since this method uses {@code TreeMap} instances internally, the keys of the right map must
 * all compare as distinct according to the comparator of the left map.
 *
 * <p><b>Note:</b>If you only need to know whether two sorted maps have the same mappings, call
 * {@code left.equals(right)} instead of this method.
 *
 * @param left the map to treat as the "left" map for purposes of comparison
 * @param right the map to treat as the "right" map for purposes of comparison
 * @return the difference between the two maps
 * @since 11.0
 */
public static <K, V> SortedMapDifference<K, V> difference(
  SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right) {
 checkNotNull(left);
 checkNotNull(right);
 Comparator<? super K> comparator = orNaturalOrder(left.comparator());
 SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
 SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);
 onlyOnRight.putAll(right); // will whittle it down
 SortedMap<K, V> onBoth = Maps.newTreeMap(comparator);
 SortedMap<K, MapDifference.ValueDifference<V>> differences = Maps.newTreeMap(comparator);
 doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences);
 return new SortedMapDifferenceImpl<>(onlyOnLeft, onlyOnRight, onBoth, differences);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Computes the difference between two sorted maps, using the comparator of the left map, or
 * {@code Ordering.natural()} if the left map uses the natural ordering of its elements. This
 * difference is an immutable snapshot of the state of the maps at the time this method is called.
 * It will never change, even if the maps change at a later time.
 *
 * <p>Since this method uses {@code TreeMap} instances internally, the keys of the right map must
 * all compare as distinct according to the comparator of the left map.
 *
 * <p><b>Note:</b>If you only need to know whether two sorted maps have the same mappings, call
 * {@code left.equals(right)} instead of this method.
 *
 * @param left the map to treat as the "left" map for purposes of comparison
 * @param right the map to treat as the "right" map for purposes of comparison
 * @return the difference between the two maps
 * @since 11.0
 */
public static <K, V> SortedMapDifference<K, V> difference(
  SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right) {
 checkNotNull(left);
 checkNotNull(right);
 Comparator<? super K> comparator = orNaturalOrder(left.comparator());
 SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
 SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);
 onlyOnRight.putAll(right); // will whittle it down
 SortedMap<K, V> onBoth = Maps.newTreeMap(comparator);
 SortedMap<K, MapDifference.ValueDifference<V>> differences = Maps.newTreeMap(comparator);
 doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences);
 return new SortedMapDifferenceImpl<>(onlyOnLeft, onlyOnRight, onBoth, differences);
}

代码示例来源:origin: com.diffplug.guava/guava-collect

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: com.google.guava/guava-jdk5

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: org.sonatype.sisu/sisu-guava

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);

相关文章