本文整理汇总了Java中com.google.common.collect.ImmutableMultiset.copyOf方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMultiset.copyOf方法的具体用法?Java ImmutableMultiset.copyOf怎么用?Java ImmutableMultiset.copyOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableMultiset
的用法示例。
在下文中一共展示了ImmutableMultiset.copyOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: count
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public Map<String, Double> count(final List<List<String>> sentences) {
if (sentences == null || sentences.size() == 0) {
return Collections.emptyMap();
}
final List<String> words = new ArrayList<>();
for (final List<String> sentence : sentences) {
words.addAll(sentence);
}
final ImmutableMultiset<String> multiset = ImmutableMultiset
.copyOf(words);
final Map<String, Double> result = new HashMap<>();
for (final String word : multiset.elementSet()) {
result.put(word, (double) multiset.count(word));
}
return result;
}
示例2: testSerialization
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public void testSerialization() {
BeanWithMultisetTypes bean = new BeanWithMultisetTypes();
List<String> list = Arrays.asList( "foo", "abc", null, "abc" );
List<String> listWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );
bean.multiset = LinkedHashMultiset.create( list );
bean.hashMultiset = HashMultiset.create( Arrays.asList( "abc", "abc" ) );
bean.linkedHashMultiset = LinkedHashMultiset.create( list );
bean.sortedMultiset = TreeMultiset.create( listWithNonNull );
bean.treeMultiset = TreeMultiset.create( listWithNonNull );
bean.immutableMultiset = ImmutableMultiset.copyOf( listWithNonNull );
bean.enumMultiset = EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) );
String expected = "{" +
"\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"hashMultiset\":[\"abc\",\"abc\"]," +
"\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"sortedMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
"\"treeMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
"\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\"]," +
"\"enumMultiset\":[\"A\",\"A\",\"B\",\"D\"]" +
"}";
assertEquals( expected, BeanWithMultisetTypesMapper.INSTANCE.write( bean ) );
}
示例3: copyOf
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public static <T> ImmutableCollection<T> copyOf(Iterable<T> iterable) {
if(iterable instanceof Set) {
return ImmutableSet.copyOf(iterable);
} else if(iterable instanceof Multiset) {
return ImmutableMultiset.copyOf(iterable);
} else {
return ImmutableList.copyOf(iterable);
}
}
示例4: fieldCardinalities
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private Multiset<Type> fieldCardinalities(ClassFile cf)
{
List<Type> t = cf.getFields().stream()
.filter(f -> !f.isStatic())
.map(f -> f.getType())
.collect(Collectors.toList());
return ImmutableMultiset.copyOf(t);
}
示例5: methodCardinalities
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private Multiset<Signature> methodCardinalities(ClassFile cf)
{
List<Signature> t = cf.getMethods().stream()
.filter(m -> !m.isStatic())
.filter(m -> !m.getName().startsWith("<"))
.map(m -> m.getDescriptor())
.collect(Collectors.toList());
return ImmutableMultiset.copyOf(t);
}
示例6: assertEqualsIgnoreOrder
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public static void assertEqualsIgnoreOrder(Iterable<?> actual, Iterable<?> expected)
{
assertNotNull(actual, "actual is null");
assertNotNull(expected, "expected is null");
ImmutableMultiset<?> actualSet = ImmutableMultiset.copyOf(actual);
ImmutableMultiset<?> expectedSet = ImmutableMultiset.copyOf(expected);
if (!actualSet.equals(expectedSet)) {
fail(format("not equal\nActual %s rows:\n %s\nExpected %s rows:\n %s\n",
actualSet.size(),
Joiner.on("\n ").join(Iterables.limit(actualSet, 100)),
expectedSet.size(),
Joiner.on("\n ").join(Iterables.limit(expectedSet, 100))));
}
}
示例7: Footprint
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
/**
* Constructs a Footprint, by specifying the number of objects,
* references, and primitives (represented as a {@link Multiset}).
*
* @param objects the number of objects
* @param references the number of references
* @param primitives the number of primitives (represented by the
* respective primitive classes, e.g. {@code int.class} etc)
*/
public Footprint(int objects, int references, Multiset<Class<?>> primitives) {
Preconditions.checkArgument(objects >= 0, "Negative number of objects");
Preconditions.checkArgument(references >= 0, "Negative number of references");
Preconditions.checkArgument(primitiveTypes.containsAll(primitives.elementSet()),
"Unexpected primitive type");
this.objects = objects;
this.references = references;
this.primitives = ImmutableMultiset.copyOf(primitives);
}
示例8: convert
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public Map<String, Double> convert(final String text) {
if (text == null || text.length() == 0) {
return Collections.emptyMap();
}
final List<String> words = new ArrayList<>();
// Break into words
final BreakIterator boundary = BreakIterator
.getWordInstance(Locale.ENGLISH);
boundary.setText(text);
int start = boundary.first();
for (int end = boundary.next(); end != BreakIterator.DONE; start = end, end = boundary
.next()) {
if (end - start >= minimalLength) {
words.add(text.substring(start, end));
}
}
// Into cardinality map
final ImmutableMultiset<String> multiset = ImmutableMultiset
.copyOf(words);
final Map<String, Double> result = new HashMap<>();
for (final String word : multiset.elementSet()) {
if (multiset.count(word) > minimalOccurrence) {
result.put(word, (double) multiset.count(word));
}
}
return result;
}
示例9: insert
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public final InsertQuery insert(Collection<? extends VarPattern> vars) {
ImmutableMultiset<VarPatternAdmin> varAdmins = ImmutableMultiset.copyOf(AdminConverter.getVarAdmins(vars));
return Queries.insert(varAdmins, admin());
}
示例10: completedTasks
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public static ImmutableMultiset<TaskId> completedTasks() {
return ImmutableMultiset.copyOf(COMPLETED_TASKS);
}
示例11: cancelledTasks
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public static ImmutableMultiset<TaskId> cancelledTasks() {
return ImmutableMultiset.copyOf(CANCELLED_TASKS);
}
示例12: reduce
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public void reduce(
final Key<CommitLogManifest> manifestKey,
ReducerInput<Boolean> canDeleteVerdicts) {
ImmutableMultiset<Boolean> canDeleteMultiset = ImmutableMultiset.copyOf(canDeleteVerdicts);
if (canDeleteMultiset.count(TRUE) > 1) {
getContext().incrementCounter("commit log manifests incorrectly mapped multiple times");
}
if (canDeleteMultiset.count(FALSE) > 1) {
getContext().incrementCounter("commit log manifests referenced multiple times");
}
if (canDeleteMultiset.contains(FALSE)) {
getContext().incrementCounter(
canDeleteMultiset.contains(TRUE)
? "old commit log manifests still referenced"
: "new (or nonexistent) commit log manifests referenced");
getContext().incrementCounter(
"EPP resource revisions handled",
canDeleteMultiset.count(FALSE));
return;
}
DeletionResult deletionResult = ofy().transactNew(() -> {
CommitLogManifest manifest = ofy().load().key(manifestKey).now();
// It is possible that the same manifestKey was run twice, if a shard had to be restarted
// or some weird failure. If this happens, we want to exit immediately.
// Note that this can never happen in dryRun.
if (manifest == null) {
return DeletionResult.create(DeletionResult.Status.ALREADY_DELETED, 0);
}
// Doing a sanity check on the date. This is the only place we use the CommitLogManifest,
// so maybe removing this test will improve performance. However, unless it's proven that
// the performance boost is significant (and we've tested this enough to be sure it never
// happens)- the safty of "let's not delete stuff we need from prod" is more important.
if (manifest.getCommitTime().isAfter(deletionThreshold)) {
return DeletionResult.create(DeletionResult.Status.AFTER_THRESHOLD, 0);
}
Iterable<Key<CommitLogMutation>> commitLogMutationKeys = ofy().load()
.type(CommitLogMutation.class)
.ancestor(manifestKey)
.keys()
.iterable();
ImmutableList<Key<?>> keysToDelete = ImmutableList.<Key<?>>builder()
.addAll(commitLogMutationKeys)
.add(manifestKey)
.build();
// Normally in a dry run we would log the entities that would be deleted, but those can
// number in the millions so we skip the logging.
if (!isDryRun) {
ofy().deleteWithoutBackup().keys(keysToDelete);
}
return DeletionResult.create(DeletionResult.Status.SUCCESS, keysToDelete.size());
});
switch (deletionResult.status()) {
case SUCCESS:
getContext().incrementCounter("old commit log manifests deleted");
getContext().incrementCounter("total entities deleted", deletionResult.numDeleted());
break;
case ALREADY_DELETED:
getContext().incrementCounter("attempts to delete an already deleted manifest");
break;
case AFTER_THRESHOLD:
logger.severefmt("Won't delete CommitLogManifest %s that is too recent.", manifestKey);
getContext().incrementCounter("manifests incorrectly assigned for deletion (SEE LOGS)");
break;
}
}
示例13: result
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public Footprint result() {
return new Footprint(objects, references, ImmutableMultiset.copyOf(primitives));
}
示例14: toSet
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
static ImmutableMultiset<String> toSet(ResultSet resultSet)
throws SQLException {
return ImmutableMultiset.copyOf(toList(resultSet));
}
示例15: keys
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public Multiset<K> keys() {
return ImmutableMultiset.copyOf(sortedKeys);
}