當前位置: 首頁>>代碼示例>>Java>>正文


Java ImmutableMultiset.copyOf方法代碼示例

本文整理匯總了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;
}
 
開發者ID:jsubercaze,項目名稱:simhashdb,代碼行數:18,代碼來源:SimpleCounting.java

示例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 ) );
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:27,代碼來源:MultisetGwtTest.java

示例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);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:10,代碼來源:IterableUtils.java

示例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);
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:10,代碼來源:ClassMapper.java

示例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);
}
 
開發者ID:runelite,項目名稱:runelite,代碼行數:11,代碼來源:ClassMapper.java

示例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))));
    }
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:16,代碼來源:QueryAssertions.java

示例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);
}
 
開發者ID:DimitrisAndreou,項目名稱:memory-measurer,代碼行數:19,代碼來源:ObjectGraphMeasurer.java

示例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;
}
 
開發者ID:jsubercaze,項目名稱:simhashdb,代碼行數:29,代碼來源:NaiveMethod.java

示例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());
}
 
開發者ID:graknlabs,項目名稱:grakn,代碼行數:6,代碼來源:AbstractMatch.java

示例10: completedTasks

import com.google.common.collect.ImmutableMultiset; //導入方法依賴的package包/類
public static ImmutableMultiset<TaskId> completedTasks() {
    return ImmutableMultiset.copyOf(COMPLETED_TASKS);
}
 
開發者ID:graknlabs,項目名稱:grakn,代碼行數:4,代碼來源:MockBackgroundTask.java

示例11: cancelledTasks

import com.google.common.collect.ImmutableMultiset; //導入方法依賴的package包/類
public static ImmutableMultiset<TaskId> cancelledTasks() {
    return ImmutableMultiset.copyOf(CANCELLED_TASKS);
}
 
開發者ID:graknlabs,項目名稱:grakn,代碼行數:4,代碼來源:MockBackgroundTask.java

示例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;
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:69,代碼來源:DeleteOldCommitLogsAction.java

示例13: result

import com.google.common.collect.ImmutableMultiset; //導入方法依賴的package包/類
public Footprint result() {
  return new Footprint(objects, references, ImmutableMultiset.copyOf(primitives));
}
 
開發者ID:DimitrisAndreou,項目名稱:memory-measurer,代碼行數:4,代碼來源:ObjectGraphMeasurer.java

示例14: toSet

import com.google.common.collect.ImmutableMultiset; //導入方法依賴的package包/類
static ImmutableMultiset<String> toSet(ResultSet resultSet)
    throws SQLException {
  return ImmutableMultiset.copyOf(toList(resultSet));
}
 
開發者ID:apache,項目名稱:calcite,代碼行數:5,代碼來源:CalciteAssert.java

示例15: keys

import com.google.common.collect.ImmutableMultiset; //導入方法依賴的package包/類
@Override
public Multiset<K> keys() {
  return ImmutableMultiset.copyOf(sortedKeys);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:5,代碼來源:ImmutableSortedKeyListMultimap.java


注:本文中的com.google.common.collect.ImmutableMultiset.copyOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。