下面列出了怎么用com.google.common.collect.ImmutableSortedMultiset的API类实例代码及写法,或者点击链接到github查看源代码。
/** @return Tokens with their count, sorted by frequency decreasing, then lexicographically ascending */
private ImmutableMultiset<String> filterAndSort(final Multiset<String> counts) {
// This isn't terribly efficient, but it is deterministic
// Unfortunately, Guava's multiset doesn't give us a clean way to order both by count and element
return Multisets.copyHighestCountFirst(
ImmutableSortedMultiset.copyOf(
Multisets.filter(
counts,
new Predicate<String>() {
@Override
public boolean apply(String s) {
return counts.count(s) >= minFrequency;
}
}
)
)
);
}
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;
}
}
public String getResultsComparison(int precision)
{
List<List<Object>> controlResults = controlResult.getResults();
List<List<Object>> testResults = testResult.getResults();
if (valid() || (controlResults == null) || (testResults == null)) {
return "";
}
Multiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResults);
Multiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(precision), testResults);
try {
Iterable<ChangedRow> diff = ImmutableSortedMultiset.<ChangedRow>naturalOrder()
.addAll(Iterables.transform(Multisets.difference(control, test), row -> new ChangedRow(Changed.REMOVED, row, precision)))
.addAll(Iterables.transform(Multisets.difference(test, control), row -> new ChangedRow(Changed.ADDED, row, precision)))
.build();
diff = Iterables.limit(diff, 100);
StringBuilder sb = new StringBuilder();
sb.append(format("Control %s rows, Test %s rows%n", control.size(), test.size()));
if (verboseResultsComparison) {
Joiner.on("\n").appendTo(sb, diff);
}
else {
sb.append("RESULTS DO NOT MATCH\n");
}
return sb.toString();
}
catch (TypesDoNotMatchException e) {
return e.getMessage();
}
}
@Override
protected Builder<Object> createBuilder() {
/* This is suboptimal. See the considerations in ImmutableSortedSetDeserializer. */
@SuppressWarnings({ "rawtypes", "unchecked" })
Builder<Object> builder = (Builder) ImmutableSortedMultiset.naturalOrder();
return builder;
}
@Override
protected ImmutableSortedMultiset<Object> _createWithSingleElement(DeserializationContext ctxt,
Object value) throws IOException {
return (ImmutableSortedMultiset<Object>) createBuilder()
.add(value)
.build();
}
@Override
public GuavaCollectionDeserializer<ImmutableSortedMultiset<Object>> withResolved(JsonDeserializer<?> valueDeser, TypeDeserializer typeDeser,
NullValueProvider nuller, Boolean unwrapSingle) {
return new ImmutableSortedMultisetDeserializer(_containerType,
valueDeser, typeDeser, nuller, unwrapSingle);
}
@Override
protected ImmutableSortedMultiset<Object> _createEmpty(DeserializationContext ctxt) throws IOException {
return ImmutableSortedMultiset.of();
}
@Value.ReverseOrder
ImmutableSortedMultiset<Elem> getElemMultiset();
@Value.ReverseOrder
ImmutableSortedMultiset<ImmutableElem> getImmutableElemMultiset();