本文整理汇总了Java中com.google.common.collect.SortedMultiset类的典型用法代码示例。如果您正苦于以下问题:Java SortedMultiset类的具体用法?Java SortedMultiset怎么用?Java SortedMultiset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SortedMultiset类属于com.google.common.collect包,在下文中一共展示了SortedMultiset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createReserializedSuite
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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();
}
示例2: printStats
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
/**
* 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));
}
示例3: createReserializedSuite
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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();
}
示例4: getThreshold
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
/**
* 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;
}
示例5: pruneToThreshold
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
/**
* 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;
}
示例6: createReserializedSuite
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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();
}
示例7: resetWithHole
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
/**
* 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();
}
示例8: expectSetCountFailure
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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) {
}
}
示例9: testEmptyRangeSubMultiset
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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());
}
示例10: testSubMultisetEntrySet
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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()));
}
}
示例11: testSubMultisetSize
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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());
}
}
示例12: testSubMultisetDistinctElements
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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());
}
}
示例13: createDescendingSuite
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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();
}
示例14: expectSetCountFailure
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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) {}
}
示例15: createDescendingSuite
import com.google.common.collect.SortedMultiset; //导入依赖的package包/类
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();
}