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


Java SortedMultiset.comparator方法代码示例

本文整理汇总了Java中com.google.common.collect.SortedMultiset.comparator方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMultiset.comparator方法的具体用法?Java SortedMultiset.comparator怎么用?Java SortedMultiset.comparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.SortedMultiset的用法示例。


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

示例1: createSubMultisetSuite

import com.google.common.collect.SortedMultiset; //导入方法依赖的package包/类
private TestSuite createSubMultisetSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder, final Bound from, final Bound to) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.add(NoRecurse.SUBMULTISET);
  features.add(RESTRICTS_ELEMENTS);
  features.addAll(parentBuilder.getFeatures());

  if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(SERIALIZABLE);
  }

  SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
  final Comparator<? super E> comparator = emptyMultiset.comparator();
  SampleElements<E> samples = delegate.samples();
  @SuppressWarnings("unchecked")
  List<E> samplesList =
      Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

  Collections.sort(samplesList, comparator);
  final E firstInclusive = samplesList.get(0);
  final E lastInclusive = samplesList.get(samplesList.size() - 1);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              @SuppressWarnings("unchecked")
              // we dangerously assume E is a string
              List<E> extremeValues = (List) getExtremeValues();
              @SuppressWarnings("unchecked")
              // map generators must past entry objects
              List<E> normalValues = (List) Arrays.asList(entries);

              // prepare extreme values to be filtered out of view
              Collections.sort(extremeValues, comparator);
              E firstExclusive = extremeValues.get(1);
              E lastExclusive = extremeValues.get(2);
              if (from == Bound.NO_BOUND) {
                extremeValues.remove(0);
                extremeValues.remove(0);
              }
              if (to == Bound.NO_BOUND) {
                extremeValues.remove(extremeValues.size() - 1);
                extremeValues.remove(extremeValues.size() - 1);
              }

              // the regular values should be visible after filtering
              List<E> allEntries = new ArrayList<E>();
              allEntries.addAll(extremeValues);
              allEntries.addAll(normalValues);
              SortedMultiset<E> multiset =
                  (SortedMultiset<E>) delegate.create(allEntries.toArray());

              // call the smallest subMap overload that filters out the extreme
              // values
              if (from == Bound.INCLUSIVE) {
                multiset = multiset.tailMultiset(firstInclusive, BoundType.CLOSED);
              } else if (from == Bound.EXCLUSIVE) {
                multiset = multiset.tailMultiset(firstExclusive, BoundType.OPEN);
              }

              if (to == Bound.INCLUSIVE) {
                multiset = multiset.headMultiset(lastInclusive, BoundType.CLOSED);
              } else if (to == Bound.EXCLUSIVE) {
                multiset = multiset.headMultiset(lastExclusive, BoundType.OPEN);
              }

              return multiset;
            }
          })
      .named(parentBuilder.getName() + " subMultiset " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:79,代码来源:SortedMultisetTestSuiteBuilder.java

示例2: createSubMultisetSuite

import com.google.common.collect.SortedMultiset; //导入方法依赖的package包/类
private TestSuite createSubMultisetSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder, final Bound from,
    final Bound to) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.add(NoRecurse.SUBMULTISET);
  features.add(CollectionFeature.RESTRICTS_ELEMENTS);
  features.addAll(parentBuilder.getFeatures());

  if (!features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(CollectionFeature.SERIALIZABLE);
  }

  SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
  final Comparator<? super E> comparator = emptyMultiset.comparator();
  SampleElements<E> samples = delegate.samples();
  @SuppressWarnings("unchecked")
  List<E> samplesList =
      Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(),
          samples.e4());

  Collections.sort(samplesList, comparator);
  final E firstInclusive = samplesList.get(0);
  final E lastInclusive = samplesList.get(samplesList.size() - 1);

  return SortedMultisetTestSuiteBuilder
      .using(new ForwardingTestMultisetGenerator<E>(delegate) {
        @Override
        public SortedMultiset<E> create(Object... entries) {
          @SuppressWarnings("unchecked")
          // we dangerously assume E is a string
          List<E> extremeValues = (List) getExtremeValues();
          @SuppressWarnings("unchecked")
          // map generators must past entry objects
          List<E> normalValues = (List) Arrays.asList(entries);

          // prepare extreme values to be filtered out of view
          Collections.sort(extremeValues, comparator);
          E firstExclusive = extremeValues.get(1);
          E lastExclusive = extremeValues.get(2);
          if (from == Bound.NO_BOUND) {
            extremeValues.remove(0);
            extremeValues.remove(0);
          }
          if (to == Bound.NO_BOUND) {
            extremeValues.remove(extremeValues.size() - 1);
            extremeValues.remove(extremeValues.size() - 1);
          }

          // the regular values should be visible after filtering
          List<E> allEntries = new ArrayList<E>();
          allEntries.addAll(extremeValues);
          allEntries.addAll(normalValues);
          SortedMultiset<E> multiset =
              (SortedMultiset<E>) delegate.create(allEntries.toArray());

          // call the smallest subMap overload that filters out the extreme
          // values
          if (from == Bound.INCLUSIVE) {
            multiset =
                multiset.tailMultiset(firstInclusive, BoundType.CLOSED);
          } else if (from == Bound.EXCLUSIVE) {
            multiset = multiset.tailMultiset(firstExclusive, BoundType.OPEN);
          }

          if (to == Bound.INCLUSIVE) {
            multiset = multiset.headMultiset(lastInclusive, BoundType.CLOSED);
          } else if (to == Bound.EXCLUSIVE) {
            multiset = multiset.headMultiset(lastExclusive, BoundType.OPEN);
          }

          return multiset;
        }
      })
      .named(parentBuilder.getName() + " subMultiset " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:82,代码来源:SortedMultisetTestSuiteBuilder.java

示例3: createSubMultisetSuite

import com.google.common.collect.SortedMultiset; //导入方法依赖的package包/类
private TestSuite createSubMultisetSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder, final Bound from, final Bound to) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<>();
  features.add(NoRecurse.SUBMULTISET);
  features.add(RESTRICTS_ELEMENTS);
  features.addAll(parentBuilder.getFeatures());

  if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(SERIALIZABLE);
  }

  SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
  final Comparator<? super E> comparator = emptyMultiset.comparator();
  SampleElements<E> samples = delegate.samples();
  @SuppressWarnings("unchecked")
  List<E> samplesList =
      Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4());

  Collections.sort(samplesList, comparator);
  final E firstInclusive = samplesList.get(0);
  final E lastInclusive = samplesList.get(samplesList.size() - 1);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              @SuppressWarnings("unchecked")
              // we dangerously assume E is a string
              List<E> extremeValues = (List) getExtremeValues();
              @SuppressWarnings("unchecked")
              // map generators must past entry objects
              List<E> normalValues = (List) Arrays.asList(entries);

              // prepare extreme values to be filtered out of view
              Collections.sort(extremeValues, comparator);
              E firstExclusive = extremeValues.get(1);
              E lastExclusive = extremeValues.get(2);
              if (from == Bound.NO_BOUND) {
                extremeValues.remove(0);
                extremeValues.remove(0);
              }
              if (to == Bound.NO_BOUND) {
                extremeValues.remove(extremeValues.size() - 1);
                extremeValues.remove(extremeValues.size() - 1);
              }

              // the regular values should be visible after filtering
              List<E> allEntries = new ArrayList<E>();
              allEntries.addAll(extremeValues);
              allEntries.addAll(normalValues);
              SortedMultiset<E> multiset =
                  (SortedMultiset<E>) delegate.create(allEntries.toArray());

              // call the smallest subMap overload that filters out the extreme
              // values
              if (from == Bound.INCLUSIVE) {
                multiset = multiset.tailMultiset(firstInclusive, BoundType.CLOSED);
              } else if (from == Bound.EXCLUSIVE) {
                multiset = multiset.tailMultiset(firstExclusive, BoundType.OPEN);
              }

              if (to == Bound.INCLUSIVE) {
                multiset = multiset.headMultiset(lastInclusive, BoundType.CLOSED);
              } else if (to == Bound.EXCLUSIVE) {
                multiset = multiset.headMultiset(lastExclusive, BoundType.OPEN);
              }

              return multiset;
            }
          })
      .named(parentBuilder.getName() + " subMultiset " + from + "-" + to)
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
 
开发者ID:google,项目名称:guava,代码行数:79,代码来源:SortedMultisetTestSuiteBuilder.java


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