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


Java Equivalence类代码示例

本文整理汇总了Java中com.google.common.base.Equivalence的典型用法代码示例。如果您正苦于以下问题:Java Equivalence类的具体用法?Java Equivalence怎么用?Java Equivalence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Equivalence类属于com.google.common.base包,在下文中一共展示了Equivalence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testToImmutableSortedMap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableSortedMap() {
  Collector<Entry<String, Integer>, ?, ImmutableSortedMap<String, Integer>> collector =
      ImmutableSortedMap.toImmutableSortedMap(
          String.CASE_INSENSITIVE_ORDER, Entry::getKey, Entry::getValue);
  BiPredicate<ImmutableSortedMap<String, Integer>, ImmutableSortedMap<String, Integer>>
      equivalence =
          Equivalence.equals().onResultOf(ImmutableSortedMap<String, Integer>::comparator)
              .and(Equivalence.equals().onResultOf(map -> map.entrySet().asList()))
              .and(Equivalence.equals());
  ImmutableSortedMap<String, Integer> expected =
      ImmutableSortedMap.<String, Integer>orderedBy(String.CASE_INSENSITIVE_ORDER)
          .put("one", 1)
          .put("three", 3)
          .put("two", 2)
          .build();
  CollectorTester.of(collector, equivalence)
      .expectCollects(expected, mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:ImmutableSortedMapTest.java

示例2: testToImmutableTable

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableTable() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 2)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:ImmutableTableTest.java

示例3: addNonShadowed

import com.google.common.base.Equivalence; //导入依赖的package包/类
private <T extends PresortedComparable<T>, S extends KeyedDexItem<T>> void addNonShadowed(
    Iterator<S> items,
    HashMap<Wrapper<T>, S> map,
    Equivalence<T> equivalence,
    Set<Wrapper<T>> existing,
    BiFunction<S, S, S> onConflict) {
  while (items.hasNext()) {
    S item = items.next();
    if (item == null) {
      // This item was filtered out by a preprocessing.
      continue;
    }
    Wrapper<T> wrapped = equivalence.wrap(item.getKey());
    if (existing.contains(wrapped)) {
      S resolved = onConflict.apply(map.get(wrapped), item);
      wrapped = equivalence.wrap(resolved.getKey());
      map.put(wrapped, resolved);
    } else {
      map.put(wrapped, item);
    }
  }
}
 
开发者ID:inferjay,项目名称:r8,代码行数:23,代码来源:SimpleClassMerger.java

示例4: testLogicalKeyEquality

import com.google.common.base.Equivalence; //导入依赖的package包/类
private void testLogicalKeyEquality(
    MapMakerInternalMap.Strength keyStrength) {

  ConcurrentMap<String, AtomicInteger> map =
      new MapMaker().setKeyStrength(keyStrength).keyEquivalence(Equivalence.equals()).makeMap();

  ConcurrentHashMultiset<String> multiset = ConcurrentHashMultiset.create(map);

  String s1 = new String("a");
  String s2 = new String("a");
  assertEquals(s1, s2); // Stating the obvious.

  multiset.add(s1);
  assertTrue(multiset.contains(s1));
  assertTrue(multiset.contains(s2));
  assertEquals(1, multiset.count(s1));
  assertEquals(1, multiset.count(s2));

  multiset.add(s2, 3);
  assertEquals(4, multiset.count(s1));
  assertEquals(4, multiset.count(s2));

  multiset.remove(s1);
  assertEquals(3, multiset.count(s1));
  assertEquals(3, multiset.count(s2));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:27,代码来源:ConcurrentHashMultisetTest.java

示例5: testToMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToMultimap() {
  Collector<Entry<String, Integer>, ?, TreeMultimap<String, Integer>> collector =
      Multimaps.toMultimap(Entry::getKey, Entry::getValue, TreeMultimap::create);
  BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
          .and(Equivalence.equals());
  TreeMultimap<String, Integer> empty = TreeMultimap.create();
  TreeMultimap<String, Integer> filled = TreeMultimap.create();
  filled.put("a", 1);
  filled.put("a", 2);
  filled.put("b", 2);
  filled.put("c", 3);
  CollectorTester.of(collector, equivalence)
      .expectCollects(empty)
      .expectCollects(
          filled, mapEntry("a", 1), mapEntry("a", 2), mapEntry("b", 2), mapEntry("c", 3));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:MultimapsTest.java

示例6: testFlatteningToMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testFlatteningToMultimap() {
  Collector<String, ?, ListMultimap<Character, Character>> collector =
      Multimaps.flatteningToMultimap(
          str -> str.charAt(0),
          str -> str.substring(1).chars().mapToObj(c -> (char) c),
          MultimapBuilder.linkedHashKeys().arrayListValues()::build);
  BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
          .and(Equivalence.equals());
  ListMultimap<Character, Character> empty =
      MultimapBuilder.linkedHashKeys().arrayListValues().build();
  ListMultimap<Character, Character> filled =
      MultimapBuilder.linkedHashKeys().arrayListValues().build();
  filled.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'));
  filled.putAll('a', Arrays.asList('p', 'p', 'l', 'e'));
  filled.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'));
  filled.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'));
  filled.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'));
  CollectorTester.of(collector, equivalence)
      .expectCollects(empty)
      .expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:24,代码来源:MultimapsTest.java

示例7: testSetKeyEquivalence

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testSetKeyEquivalence() {
  Equivalence<Object> testEquivalence = new Equivalence<Object>() {
    @Override
    protected boolean doEquivalent(Object a, Object b) {
      return false;
    }

    @Override
    protected int doHash(Object t) {
      return 0;
    }
  };

  MapMakerInternalMap<Object, Object, ?, ?> map =
      makeMap(createMapMaker().keyEquivalence(testEquivalence));
  assertSame(testEquivalence, map.keyEquivalence);
  assertSame(map.valueStrength().defaultEquivalence(), map.valueEquivalence());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:MapMakerInternalMapTest.java

示例8: testToImmutableListMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableListMultimap() {
  Collector<Entry<String, Integer>, ?, ImmutableListMultimap<String, Integer>> collector =
      ImmutableListMultimap.toImmutableListMultimap(Entry::getKey, Entry::getValue);
  BiPredicate<ImmutableListMultimap<?, ?>, ImmutableListMultimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf((ImmutableListMultimap<?, ?> mm) -> mm.asMap().entrySet().asList())
          .and(Equivalence.equals());
  CollectorTester.of(collector, equivalence)
      .expectCollects(ImmutableListMultimap.of())
      .expectCollects(
          ImmutableListMultimap.of("a", 1, "b", 2, "a", 3, "c", 4),
          mapEntry("a", 1),
          mapEntry("b", 2),
          mapEntry("a", 3),
          mapEntry("c", 4));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:ImmutableListMultimapTest.java

示例9: testFlatteningToImmutableListMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testFlatteningToImmutableListMultimap() {
  Collector<String, ?, ImmutableListMultimap<Character, Character>> collector =
      ImmutableListMultimap.flatteningToImmutableListMultimap(
          str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c));
  BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
          .and(Equivalence.equals());
  ImmutableListMultimap<Character, Character> empty = ImmutableListMultimap.of();
  ImmutableListMultimap<Character, Character> filled =
      ImmutableListMultimap.<Character, Character>builder()
          .putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'))
          .putAll('a', Arrays.asList('p', 'p', 'l', 'e'))
          .putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'))
          .putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'))
          .putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'))
          .build();
  CollectorTester.of(collector, equivalence)
      .expectCollects(empty)
      .expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:ImmutableListMultimapTest.java

示例10: testToImmutableTableMerging

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableTableMerging() {
  Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector =
      ImmutableTable.toImmutableTable(
          Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum);
  Equivalence<ImmutableTable<String, String, Integer>> equivalence =
      Equivalence.equals()
          .<Cell<String, String, Integer>>pairwise()
          .onResultOf(ImmutableTable::cellSet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          new ImmutableTable.Builder<String, String, Integer>()
              .put("one", "uno", 1)
              .put("two", "dos", 6)
              .put("three", "tres", 3)
              .build(),
          Tables.immutableCell("one", "uno", 1),
          Tables.immutableCell("two", "dos", 2),
          Tables.immutableCell("three", "tres", 3),
          Tables.immutableCell("two", "dos", 4));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:ImmutableTableTest.java

示例11: testToImmutableSetMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableSetMultimap() {
  Collector<Entry<String, Integer>, ?, ImmutableSetMultimap<String, Integer>> collector =
      ImmutableSetMultimap.toImmutableSetMultimap(Entry::getKey, Entry::getValue);
  BiPredicate<ImmutableSetMultimap<?, ?>, ImmutableSetMultimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf(
              (ImmutableSetMultimap<?, ?> mm)
                  -> ImmutableListMultimap.copyOf(mm).asMap().entrySet().asList())
          .and(Equivalence.equals());
  CollectorTester.of(collector, equivalence)
      .expectCollects(ImmutableSetMultimap.of())
      .expectCollects(
          ImmutableSetMultimap.of("a", 1, "b", 2, "a", 3, "c", 4),
          mapEntry("a", 1),
          mapEntry("b", 2),
          mapEntry("a", 3),
          mapEntry("c", 4));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:ImmutableSetMultimapTest.java

示例12: testToImmutableSortedMapMerging

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testToImmutableSortedMapMerging() {
  Collector<Entry<String, Integer>, ?, ImmutableSortedMap<String, Integer>> collector =
      ImmutableSortedMap.toImmutableSortedMap(
          Comparator.naturalOrder(), Entry::getKey, Entry::getValue, Integer::sum);
  Equivalence<ImmutableMap<String, Integer>> equivalence =
      Equivalence.equals()
          .<Entry<String, Integer>>pairwise()
          .onResultOf(ImmutableMap::entrySet);
  CollectorTester.of(collector, equivalence)
      .expectCollects(
          ImmutableSortedMap.of("one", 1, "three", 3, "two", 4),
          mapEntry("one", 1),
          mapEntry("two", 2),
          mapEntry("three", 3),
          mapEntry("two", 2));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:ImmutableSortedMapTest.java

示例13: testFlatteningToImmutableSetMultimap

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testFlatteningToImmutableSetMultimap() {
  Collector<String, ?, ImmutableSetMultimap<Character, Character>> collector =
      ImmutableSetMultimap.flatteningToImmutableSetMultimap(
          str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c));
  BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence =
      Equivalence.equals()
          .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet()))
          .and(Equivalence.equals());
  ImmutableSetMultimap<Character, Character> empty = ImmutableSetMultimap.of();
  ImmutableSetMultimap<Character, Character> filled =
      ImmutableSetMultimap.<Character, Character>builder()
          .putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a'))
          .putAll('a', Arrays.asList('p', 'p', 'l', 'e'))
          .putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't'))
          .putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's'))
          .putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y'))
          .build();
  CollectorTester.of(collector, equivalence)
      .expectCollects(empty)
      .expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry");
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:22,代码来源:ImmutableSetMultimapTest.java

示例14: testSetKeyEquivalence

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testSetKeyEquivalence() {
  Equivalence<Object> testEquivalence = new Equivalence<Object>() {
    @Override
    protected boolean doEquivalent(Object a, Object b) {
      return false;
    }

    @Override
    protected int doHash(Object t) {
      return 0;
    }
  };

  LocalCache<Object, Object> map =
      makeLocalCache(createCacheBuilder().keyEquivalence(testEquivalence));
  assertSame(testEquivalence, map.keyEquivalence);
  assertSame(map.valueStrength.defaultEquivalence(), map.valueEquivalence);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:LocalCacheTest.java

示例15: testSetValueEquivalence

import com.google.common.base.Equivalence; //导入依赖的package包/类
public void testSetValueEquivalence() {
  Equivalence<Object> testEquivalence = new Equivalence<Object>() {
    @Override
    protected boolean doEquivalent(Object a, Object b) {
      return false;
    }

    @Override
    protected int doHash(Object t) {
      return 0;
    }
  };

  LocalCache<Object, Object> map =
      makeLocalCache(createCacheBuilder().valueEquivalence(testEquivalence));
  assertSame(testEquivalence, map.valueEquivalence);
  assertSame(map.keyStrength.defaultEquivalence(), map.keyEquivalence);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:LocalCacheTest.java


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