Java Code Examples for com.google.common.collect.SortedMultiset

The following are top voted examples for showing how to use com.google.common.collect.SortedMultiset. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 2
Project: googles-monorepo-demo   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 3
Project: guava-libraries   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 4
Project: codemining-treelm   File: AbstractTSGSampler.java   Source Code and License 6 votes vote down vote up
/**
 * 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));
}
 
Example 5
Project: codemining-treelm   File: SuggestIdiomsGivenImports.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Project: codemining-treelm   File: SuggestIdiomsGivenImports.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Project: guava   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 8
Project: guava   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 9
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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) {
  }
}
 
Example 11
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
}
 
Example 12
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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()));
  }
}
 
Example 13
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 14
Project: guava-mock   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 15
Project: guava-mock   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 16
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 17
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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) {
  }
}
 
Example 18
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
}
 
Example 19
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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()));
  }
}
 
Example 20
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 21
Project: googles-monorepo-demo   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 22
Project: googles-monorepo-demo   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 23
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 24
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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) {}
}
 
Example 25
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
}
 
Example 26
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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()));
  }
}
 
Example 27
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 28
Project: guava-libraries   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 29
Project: guava-libraries   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
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();
}
 
Example 30
Project: presto   File: Validator.java   Source Code and License 5 votes vote down vote up
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;
    }
}
 
Example 31
Project: codemining-treelm   File: TSGrammar.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 32
Project: codemining-treelm   File: SuggestIdiomsGivenImports.java   Source Code and License 5 votes vote down vote up
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));
	}

}
 
Example 33
Project: codemining-treelm   File: SuggestIdiomsGivenImports.java   Source Code and License 5 votes vote down vote up
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();
	}
}
 
Example 34
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
/** 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();
}
 
Example 35
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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) {
  }
}
 
Example 36
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
}
 
Example 37
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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()));
  }
}
 
Example 38
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 39
Project: guava   File: MultisetNavigationTester.java   Source Code and License 5 votes vote down vote up
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());
  }
}
 
Example 40
Project: guava   File: SortedMultisetTestSuiteBuilder.java   Source Code and License 5 votes vote down vote up
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();
}