Java 类com.google.common.collect.SortedMultiset 实例源码

项目:guava-mock    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:guava-libraries    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createReserializedSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(CollectionFeature.SERIALIZABLE);
  features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder
      .using(new ForwardingTestMultisetGenerator<E>(delegate) {
        @Override
        public SortedMultiset<E> create(Object... entries) {
          return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
        }
      })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:codemining-treelm    文件:AbstractTSGSampler.java   
/**
 * Print statistics on stdout.
 */
protected void printStats() {
    final SortedMultiset<Integer> sizeDistribution = sampleGrammar
            .computeGrammarTreeSizeStats();
    System.out.println("Size Stats: 1-5:"
            + sizeDistribution.subMultiset(0, BoundType.CLOSED, 5,
                    BoundType.CLOSED).size()
                    + " 6-15:"
                    + sizeDistribution.subMultiset(6, BoundType.CLOSED, 15,
                            BoundType.CLOSED).size()
                            + " 16-30:"
                            + sizeDistribution.subMultiset(16, BoundType.CLOSED, 30,
                                    BoundType.CLOSED).size()
                                    + " >30:"
                                    + sizeDistribution.subMultiset(31, BoundType.CLOSED,
                                            Integer.MAX_VALUE, BoundType.CLOSED).size());

    int sumOfSizes = 0;
    for (final com.google.common.collect.Multiset.Entry<Integer> sizeEntry : sizeDistribution
            .entrySet()) {
        sumOfSizes += sizeEntry.getCount() * sizeEntry.getElement();
    }

    final double avgSize = (((double) sumOfSizes) / sizeDistribution.size());
    System.out.println("Avg Tree Size: " + String.format("%.2f", avgSize));
}
项目:codemining-treelm    文件:SuggestIdiomsGivenImports.java   
/**
 * Return the threshold for the given number of elements.
 * 
 * @param elements
 * @param proportion
 * @return
 */
private double getThreshold(final SortedMultiset<Double> elements,
        final int nElements) {
    checkArgument(elements.size() >= nElements);
    double threshold = elements.firstEntry().getElement();
    int nSeen = 0;
    for (final Entry<Double> elementEntry : elements.entrySet()) {
        if (nSeen > nElements) {
            break;
        }
        nSeen += elementEntry.getCount();
        threshold = elementEntry.getElement();
    }
    checkArgument(threshold <= elements.firstEntry().getElement(),
            "Threshold is %s but first element is %s", threshold,
            elements.firstEntry().getElement());
    return threshold;
}
项目:codemining-treelm    文件:SuggestIdiomsGivenImports.java   
/**
 * Prune the list to the given threshold.
 */
private List<Pair<SortedMultiset<Double>, SortedMultiset<Double>>> pruneToThreshold(
        final double threshold) {
    final List<Pair<SortedMultiset<Double>, SortedMultiset<Double>>> filtered = Lists
            .newArrayList();

    for (final Pair<SortedMultiset<Double>, SortedMultiset<Double>> suggestion : suggestionPrecision) {
        final SortedMultiset<Double> allFilteredSuggestions = suggestion.first
                .tailMultiset(threshold, BoundType.CLOSED);
        final SortedMultiset<Double> correctFilteredSuggestions = suggestion.second
                .tailMultiset(threshold, BoundType.CLOSED);
        final Pair<SortedMultiset<Double>, SortedMultiset<Double>> filteredPair = Pair
                .create(allFilteredSuggestions,
                        correctFilteredSuggestions);
        filtered.add(filteredPair);
    }

    return filtered;
}
项目:guava    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:guava    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createReserializedSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<>();
  features.addAll(parentBuilder.getFeatures());
  features.remove(SERIALIZABLE);
  features.remove(SERIALIZABLE_INCLUDING_VIEWS);

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
            }
          })
      .named(parentBuilder.getName() + " reserialized")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:guava-mock    文件:MultisetNavigationTester.java   
/**
 * Resets the contents of sortedMultiset to have entries a, c, for the navigation tests.
 */
@SuppressWarnings("unchecked")
// Needed to stop Eclipse whining
private void resetWithHole() {
  List<E> container = new ArrayList<E>();
  container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
  container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
  super.resetContainer(getSubjectGenerator().create(container.toArray()));
  sortedMultiset = (SortedMultiset<E>) getMultiset();
}
项目:guava-mock    文件:MultisetNavigationTester.java   
void expectSetCountFailure(SortedMultiset<E> multiset, Entry<E> entry) {
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()));
  } catch (IllegalArgumentException acceptable) {
  }
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()) + 1);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}
项目:guava-mock    文件:MultisetNavigationTester.java   
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
  assertTrue(multiset.isEmpty());
  assertEquals(0, multiset.size());
  assertEquals(0, multiset.toArray().length);
  assertTrue(multiset.entrySet().isEmpty());
  assertFalse(multiset.iterator().hasNext());
  assertEquals(0, multiset.entrySet().size());
  assertEquals(0, multiset.entrySet().toArray().length);
  assertFalse(multiset.entrySet().iterator().hasNext());
}
项目:guava-mock    文件:MultisetNavigationTester.java   
private void testSubMultisetEntrySet(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected, copyToList(subMultiset.entrySet()));
  }
}
项目:guava-mock    文件:MultisetNavigationTester.java   
private void testSubMultisetSize(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(totalSize(expected), subMultiset.size());
  }
}
项目:guava-mock    文件:MultisetNavigationTester.java   
private void testSubMultisetDistinctElements(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected.size(), subMultiset.entrySet().size());
    assertEquals(expected.size(), subMultiset.elementSet().size());
  }
}
项目:guava-mock    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createDescendingSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());
  if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(SERIALIZABLE);
  }

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return ((SortedMultiset<E>) super.create(entries)).descendingMultiset();
            }

            @Override
            public Iterable<E> order(List<E> insertionOrder) {
              return ImmutableList.copyOf(super.order(insertionOrder)).reverse();
            }
          })
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
/**
 * Resets the contents of sortedMultiset to have entries a, c, for the navigation tests.
 */
@SuppressWarnings("unchecked")
// Needed to stop Eclipse whining
private void resetWithHole() {
  List<E> container = new ArrayList<E>();
  container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
  container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
  super.resetContainer(getSubjectGenerator().create(container.toArray()));
  sortedMultiset = (SortedMultiset<E>) getMultiset();
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
void expectSetCountFailure(SortedMultiset<E> multiset, Entry<E> entry) {
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()));
  } catch (IllegalArgumentException acceptable) {
  }
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()) + 1);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
  assertTrue(multiset.isEmpty());
  assertEquals(0, multiset.size());
  assertEquals(0, multiset.toArray().length);
  assertTrue(multiset.entrySet().isEmpty());
  assertFalse(multiset.iterator().hasNext());
  assertEquals(0, multiset.entrySet().size());
  assertEquals(0, multiset.entrySet().toArray().length);
  assertFalse(multiset.entrySet().iterator().hasNext());
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
private void testSubMultisetEntrySet(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected, copyToList(subMultiset.entrySet()));
  }
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
private void testSubMultisetSize(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(totalSize(expected), subMultiset.size());
  }
}
项目:googles-monorepo-demo    文件:MultisetNavigationTester.java   
private void testSubMultisetDistinctElements(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected.size(), subMultiset.entrySet().size());
    assertEquals(expected.size(), subMultiset.elementSet().size());
  }
}
项目:googles-monorepo-demo    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createDescendingSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());
  if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(SERIALIZABLE);
  }

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return ((SortedMultiset<E>) super.create(entries)).descendingMultiset();
            }

            @Override
            public Iterable<E> order(List<E> insertionOrder) {
              return ImmutableList.copyOf(super.order(insertionOrder)).reverse();
            }
          })
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
/**
 * Resets the contents of sortedMultiset to have entries a, c, for the navigation tests.
 */
@SuppressWarnings("unchecked")
// Needed to stop Eclipse whining
private void resetWithHole() {
  List<E> container = new ArrayList<E>();
  container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
  container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
  super.resetContainer(getSubjectGenerator().create(container.toArray()));
  sortedMultiset = (SortedMultiset<E>) getMultiset();
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
void expectSetCountFailure(SortedMultiset<E> multiset, Entry<E> entry) {
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()));
  } catch (IllegalArgumentException acceptable) {}
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()) + 1);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {}
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
  assertTrue(multiset.isEmpty());
  assertEquals(0, multiset.size());
  assertEquals(0, multiset.toArray().length);
  assertTrue(multiset.entrySet().isEmpty());
  assertFalse(multiset.iterator().hasNext());
  assertEquals(0, multiset.entrySet().size());
  assertEquals(0, multiset.entrySet().toArray().length);
  assertFalse(multiset.entrySet().iterator().hasNext());
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
private void testSubMultisetEntrySet(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected, copyToList(subMultiset.entrySet()));
  }
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
private void testSubMultisetSize(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(totalSize(expected), subMultiset.size());
  }
}
项目:guava-libraries    文件:MultisetNavigationTester.java   
private void testSubMultisetDistinctElements(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected.size(), subMultiset.entrySet().size());
    assertEquals(expected.size(), subMultiset.elementSet().size());
  }
}
项目:guava-libraries    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createDescendingSuite(
    SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<Feature<?>>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());
  if (!features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(CollectionFeature.SERIALIZABLE);
  }

  return SortedMultisetTestSuiteBuilder
      .using(new ForwardingTestMultisetGenerator<E>(delegate) {
        @Override
        public SortedMultiset<E> create(Object... entries) {
          return ((SortedMultiset<E>) super.create(entries))
              .descendingMultiset();
        }

        @Override
        public Iterable<E> order(List<E> insertionOrder) {
          return ImmutableList.copyOf(super.order(insertionOrder)).reverse();
        }
      })
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}
项目:presto    文件:Validator.java   
private static boolean resultsMatch(QueryResult controlResult, QueryResult testResult, int precision)
{
    SortedMultiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResult.getResults());
    SortedMultiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(precision), testResult.getResults());
    try {
        return control.equals(test);
    }
    catch (TypesDoNotMatchException e) {
        return false;
    }
}
项目:codemining-treelm    文件:TSGrammar.java   
@Override
public SortedMultiset<Integer> computeGrammarTreeSizeStats() {
    // Get tree size distribution.
    final SortedMultiset<Integer> treeSizes = TreeMultiset.create();
    for (final Entry<T, ConcurrentHashMultiset<TreeNode<T>>> entry : grammar
            .entrySet()) {
        for (final Multiset.Entry<TreeNode<T>> rule : entry.getValue()
                .entrySet()) {
            treeSizes.add(rule.getElement().getTreeSize(), rule.getCount());
        }
    }
    return treeSizes;
}
项目:codemining-treelm    文件:SuggestIdiomsGivenImports.java   
public void printPrecisionStats() {
    // Find actual thresholds for split positions
    final double[] thresholds = findThreshold();

    for (final double threshold : thresholds) {
        // Get the pruned lists
        final List<Pair<SortedMultiset<Double>, SortedMultiset<Double>>> pruned = pruneToThreshold(threshold);
        // Count stats
        long sizeSum = 0;
        double precisionSum = 0;
        int nGivenSuggestion = 0;
        for (final Pair<SortedMultiset<Double>, SortedMultiset<Double>> suggestionList : pruned) {
            sizeSum += suggestionList.first.size();
            final double precision = ((double) suggestionList.second
                    .size()) / suggestionList.first.size();
            if (!Double.isNaN(precision)) {
                nGivenSuggestion++;
                precisionSum += precision;
            }
        }

        final double avgSize = ((double) sizeSum) / pruned.size();
        final double avgPrecision = precisionSum / nGivenSuggestion;
        final double pctFilesSuggestionGiven = ((double) nGivenSuggestion)
                / pruned.size();

        // Print stats
        System.out.println(String.format("%.2E",
                pctFilesSuggestionGiven)
                + ","
                + String.format("%.2E", avgSize)
                + ","
                + String.format("%.2E", avgPrecision));
    }

}
项目:codemining-treelm    文件:SuggestIdiomsGivenImports.java   
public void printRecallStats() {
    System.out.println(Arrays.toString(SUGGESTION_FREQUENCY_VALUES));
    for (final int k : RANK_K_VALUES) {
        System.out.print(k);
        final SortedMultiset<Double> suggestionValues = suggestionsValuesAtRank
                .get(k);
        final SortedMultiset<Double> suggestionCorrectValues = correctSuggestionsValuesAtRank
                .get(k);
        for (final double suggestionFrequency : SUGGESTION_FREQUENCY_VALUES) {

            final int nSuggestionsToBeMade = (int) Math
                    .ceil(suggestionFrequency * suggestionValues.size());

            // Compute threshold
            final double threshold = getThreshold(
                    suggestionValues.descendingMultiset(),
                    nSuggestionsToBeMade);
            final int nCorrectSuggestionsMade = suggestionCorrectValues
                    .tailMultiset(threshold, BoundType.CLOSED).size();
            final int nSuggestionsMade = suggestionValues.tailMultiset(
                    threshold, BoundType.CLOSED).size();
            checkArgument(
                    nCorrectSuggestionsMade <= nSuggestionsMade,
                    "Made %s suggestions, out of which %s were correct",
                    nSuggestionsMade, nCorrectSuggestionsMade);
            final double recall = ((double) nCorrectSuggestionsMade)
                    / nSuggestionsMade;
            System.out.print("," + String.format("%.4E", recall));
        }
        System.out.println();
    }
}
项目:guava    文件:MultisetNavigationTester.java   
/** Resets the contents of sortedMultiset to have entries a, c, for the navigation tests. */
@SuppressWarnings("unchecked")
// Needed to stop Eclipse whining
private void resetWithHole() {
  List<E> container = new ArrayList<E>();
  container.addAll(Collections.nCopies(a.getCount(), a.getElement()));
  container.addAll(Collections.nCopies(c.getCount(), c.getElement()));
  super.resetContainer(getSubjectGenerator().create(container.toArray()));
  sortedMultiset = (SortedMultiset<E>) getMultiset();
}
项目:guava    文件:MultisetNavigationTester.java   
void expectSetCountFailure(SortedMultiset<E> multiset, Entry<E> entry) {
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()));
  } catch (IllegalArgumentException acceptable) {
  }
  try {
    multiset.setCount(entry.getElement(), multiset.count(entry.getElement()) + 1);
    fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
  }
}
项目:guava    文件:MultisetNavigationTester.java   
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
  assertTrue(multiset.isEmpty());
  assertEquals(0, multiset.size());
  assertEquals(0, multiset.toArray().length);
  assertTrue(multiset.entrySet().isEmpty());
  assertFalse(multiset.iterator().hasNext());
  assertEquals(0, multiset.entrySet().size());
  assertEquals(0, multiset.entrySet().toArray().length);
  assertFalse(multiset.entrySet().iterator().hasNext());
}
项目:guava    文件:MultisetNavigationTester.java   
private void testSubMultisetEntrySet(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected, copyToList(subMultiset.entrySet()));
  }
}
项目:guava    文件:MultisetNavigationTester.java   
private void testSubMultisetSize(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(totalSize(expected), subMultiset.size());
  }
}
项目:guava    文件:MultisetNavigationTester.java   
private void testSubMultisetDistinctElements(SubMultisetSpec spec) {
  List<Entry<E>> entries = copyToList(sortedMultiset.entrySet());
  for (int i = 0; i < entries.size(); i++) {
    List<Entry<E>> expected = spec.expectedEntries(i, entries);
    SortedMultiset<E> subMultiset = spec.subMultiset(sortedMultiset, entries, i);
    assertEquals(expected.size(), subMultiset.entrySet().size());
    assertEquals(expected.size(), subMultiset.elementSet().size());
  }
}
项目:guava    文件:SortedMultisetTestSuiteBuilder.java   
private TestSuite createDescendingSuite(SortedMultisetTestSuiteBuilder<E> parentBuilder) {
  final TestMultisetGenerator<E> delegate =
      (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();

  Set<Feature<?>> features = new HashSet<>();
  features.add(NoRecurse.DESCENDING);
  features.addAll(parentBuilder.getFeatures());
  if (!features.remove(SERIALIZABLE_INCLUDING_VIEWS)) {
    features.remove(SERIALIZABLE);
  }

  return SortedMultisetTestSuiteBuilder.using(
          new ForwardingTestMultisetGenerator<E>(delegate) {
            @Override
            public SortedMultiset<E> create(Object... entries) {
              return ((SortedMultiset<E>) super.create(entries)).descendingMultiset();
            }

            @Override
            public Iterable<E> order(List<E> insertionOrder) {
              return ImmutableList.copyOf(super.order(insertionOrder)).reverse();
            }
          })
      .named(parentBuilder.getName() + " descending")
      .withFeatures(features)
      .suppressing(parentBuilder.getSuppressedTests())
      .createTestSuite();
}