本文整理匯總了Java中com.google.common.collect.HashMultiset.create方法的典型用法代碼示例。如果您正苦於以下問題:Java HashMultiset.create方法的具體用法?Java HashMultiset.create怎麽用?Java HashMultiset.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.HashMultiset
的用法示例。
在下文中一共展示了HashMultiset.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSiaSeed
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void getSiaSeed() throws Exception {
final SiaSeedService siaSeedService = new SiaSeedService(new StaticEncyptionKeyProvider("123"));
// final List<String> strings = siaSeedService.buildSiaSeed("123");
final Multiset<Long> counts;
counts = HashMultiset.create();
for (int i = 0; i < 100000; i++) {
final String secretKey = "abc123782567825784__" + i;
final List<String> words = siaSeedService.buildSiaSeed(secretKey);
final String wordsList = Joiner.on(" ").join(words);
final String errrorMessage = "secret produced unexpected length: " + secretKey + " words: " + wordsList;
counts.add((long) words.size());
// Assert.assertEquals(errrorMessage, 29, words.size());
}
counts.forEachEntry((length, count) -> System.out.println(length + " occurred " + count + " times"));
}
示例2: evaluateCorrect
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void evaluateCorrect() {
// given
ExpressionBean bean = new ExpressionBean();
List<Response> responses = Lists.newArrayList(correctResponse(), correctResponse(), correctResponse(), correctResponse(), correctResponse());
bean.setTemplate("'0'+'2'+'3'='1'+'4'");
bean.getResponses().addAll(responses);
Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
HashMultiset.create(Lists.newArrayList("answer_1", "answer_4")),
HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
bean.setCorectResponses(correctAnswerMultiSet);
// when
boolean result = testObj.evaluate(bean);
// then
assertThat(result, equalTo(true));
}
示例3: evaluateCorrect_commutated
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void evaluateCorrect_commutated() {
// given
ExpressionBean bean = new ExpressionBean();
List<Response> responses = Lists.newArrayList(response(0, 3), response(1, 4), response(2, 0), response(3, 2), (response(4, 1)));
bean.setTemplate("'0'+'2'+'3'='1'+'4'");
bean.getResponses().addAll(responses);
Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
HashMultiset.<String>create(Lists.newArrayList("answer_1", "answer_4")),
HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
bean.setCorectResponses(correctAnswerMultiSet);
// when
boolean result = testObj.evaluate(bean);
// then
assertThat(result, equalTo(true));
}
示例4: evaluateWrong_commutated
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void evaluateWrong_commutated() {
// given
ExpressionBean bean = new ExpressionBean();
List<Response> responses = Lists.newArrayList(response(0, 4), response(1, 3), response(2, 0), response(3, 2), (response(4, 1)));
bean.setTemplate("'0'+'2'+'3'='1'+'4'");
bean.getResponses().addAll(responses);
Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
HashMultiset.<String>create(Lists.newArrayList("answer_1", "answer_4")),
HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
HashMultiset.<String>create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
bean.setCorectResponses(correctAnswerMultiSet);
// when
boolean result = testObj.evaluate(bean);
// then
assertThat(result, equalTo(false));
}
示例5: expressionsAreParallel
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Returns true if {@code atLeastM} of the expressions in the given column are the same kind.
*/
private static boolean expressionsAreParallel(
List<List<ExpressionTree>> rows, int column, int atLeastM) {
Multiset<Tree.Kind> nodeTypes = HashMultiset.create();
for (List<? extends ExpressionTree> row : rows) {
if (column >= row.size()) {
continue;
}
nodeTypes.add(row.get(column).getKind());
}
for (Multiset.Entry<Tree.Kind> nodeType : nodeTypes.entrySet()) {
if (nodeType.getCount() >= atLeastM) {
return true;
}
}
return false;
}
示例6: TraceEvaluator
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Constructor. Create a new trace builder.
*
* @param traceFile
* @throws TurnusException
*/
public TraceEvaluator(Network network, File traceFile) throws TurnusException {
try {
writer = new TraceWriter(traceFile);
writer.start();
} catch (TurnusException e) {
throw e;
}
this.network = network;
lastSharedVarStore = new HashMap<>();
lastSharedVarLoad = new HashMap<>();
lastScheduledFsm = new HashMap<>();
lastVarStore = HashBasedTable.create();
lastVarLoad = HashBasedTable.create();
lastPortWrite = HashBasedTable.create();
lastPortRead = HashBasedTable.create();
actionsFirings = HashMultiset.create();
actionsIncomings = HashMultiset.create();
actionsOutgoings = HashMultiset.create();
dependenciesKind = HashMultiset.create();
}
示例7: equals
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Compare two <code>Record</code> instances ignoring the ordering of the
* values in each metric.
*
* @param r1 First <code>Record</code> instance.
* @param r2 Second <code>Record</code> instance.
* @return True if and only if <code>Record</code> instances are equal
* irregardless of the order of the values of each metric.
*/
public static boolean equals(final Record r1, final Record r2) {
if (!r1.getTime().equals(r2.getTime())
|| !r1.getAnnotations().equals(r2.getAnnotations())) {
return false;
}
for (final Map.Entry<String, ? extends Metric> entry : r1.getMetrics().entrySet()) {
if (!r2.getMetrics().containsKey(entry.getKey())) {
return false;
}
final Metric m1 = entry.getValue();
final Metric m2 = r2.getMetrics().get(entry.getKey());
if (!m1.getType().equals(m2.getType())) {
return false;
}
final Multiset<Quantity> v1 = HashMultiset.create(m1.getValues());
final Multiset<Quantity> v2 = HashMultiset.create(m2.getValues());
if (!v1.equals(v2)) {
return false;
}
}
return true;
}
示例8: equals
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Returns true iff the other object is an instance of {@code TagContext} and contains the same
* key-value pairs. Implementations are free to override this method to provide better
* performance.
*/
@Override
public boolean equals(@Nullable Object other) {
if (!(other instanceof TagContext)) {
return false;
}
TagContext otherTags = (TagContext) other;
Iterator<Tag> iter1 = getIterator();
Iterator<Tag> iter2 = otherTags.getIterator();
Multiset<Tag> tags1 =
iter1 == null
? ImmutableMultiset.<Tag>of()
: HashMultiset.create(Lists.<Tag>newArrayList(iter1));
Multiset<Tag> tags2 =
iter2 == null
? ImmutableMultiset.<Tag>of()
: HashMultiset.create(Lists.<Tag>newArrayList(iter2));
return tags1.equals(tags2);
}
示例9: logStats
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
private static void logStats(Collection<VirtualFile> otherFiles, long start) {
long time = System.currentTimeMillis() - start;
final Multiset<String> stats = HashMultiset.create();
for (VirtualFile file : otherFiles) {
//noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
stats.add(StringUtil.notNullize(file.getExtension()).toLowerCase());
}
List<String> extensions = ContainerUtil.newArrayList(stats.elementSet());
Collections.sort(extensions, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return stats.count(o2) - stats.count(o1);
}
});
String message = "Search in " + otherFiles.size() + " files with unknown types took " + time + "ms.\n" +
"Mapping their extensions to an existing file type (e.g. Plain Text) might speed up the search.\n" +
"Most frequent non-indexed file extensions: ";
for (int i = 0; i < Math.min(10, extensions.size()); i++) {
String extension = extensions.get(i);
message += extension + "(" + stats.count(extension) + ") ";
}
LOG.info(message);
}
示例10: add
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Add this set of elements to the co-occurence object.
*
* @param elements
*/
final public void add(final Set<T> elements) {
elementCount.addAll(elements);
final Multiset<UnorderedPair<T>> pairs = HashMultiset.create();
for (final T element1 : elements) {
for (final T element2 : elements) {
if (element1 != element2) {
pairs.add(UnorderedPair.createUnordered(element1, element2));
}
}
}
for (final Entry<UnorderedPair<T>> pair : pairs.entrySet()) {
checkArgument(pair.getCount() / 2 > 0);
cooccurenceCount.add(pair.getElement(), pair.getCount() / 2);
}
}
示例11: HadoopMultiFileStore
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
/**
* Creates a new {@code HadoopFileStore} storing files in the {@code FileSystem} and under the
* {@code rootPath} specified.
*
* @param fileSystem
* the file system, not null
* @param path
* the root path where to store files, possibly relative to the filesystem working
* directory; if null, the default root path {@code files} will be used
* @param numSmallFile
* the number of files to put in each zip file
* @param cleanupPeriod
* the amount of time in milliseconds between cleanup operations
*/
public HadoopMultiFileStore(final FileSystem fileSystem, @Nullable final String lucenePath,
@Nullable final String path, @Nullable final Integer numSmallFile,
@Nullable final Long cleanupPeriod) {
this.fileSystem = Preconditions.checkNotNull(fileSystem);
this.luceneFolder = new File(MoreObjects.firstNonNull(lucenePath, DEFAULT_LUCENE_PATH));
this.rootPath = new Path(MoreObjects.firstNonNull(path, DEFAULT_ROOT_PATH))
.makeQualified(this.fileSystem); // resolve wrt workdir
this.smallFilesPath = new Path(this.rootPath.toString() + File.separator
+ SMALL_FILES_PATH).makeQualified(this.fileSystem);
this.numSmallFiles = numSmallFile != null ? numSmallFile : DEFAULT_NUM_SMALL_FILES;
this.cleanupPeriod = cleanupPeriod != null ? cleanupPeriod : DEFAULT_CLEANUP_PERIOD;
this.openedFiles = HashMultiset.create();
this.lock = new ReentrantReadWriteLock(true);
this.active = new AtomicBoolean(false);
this.zipNameCounter = System.currentTimeMillis();
LOGGER.info("{} configured, paths={};{}", getClass().getSimpleName(), this.rootPath,
this.luceneFolder);
}
示例12: testForbiddenParameter
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void testForbiddenParameter() {
Multiset<Node> components = HashMultiset.create();
Parameter p = Parameter.mkInt("p");
components.add(p);
//components.add(x);
components.add(Library.ADD);
components.add(Library.ITE);
ArrayList<TestCase> testSuite = new ArrayList<>();
Map<ProgramVariable, Node> assignment1 = new HashMap<>();
assignment1.put(x, IntConst.of(10));
testSuite.add(TestCase.ofAssignment(assignment1, IntConst.of(2)));
List<Expression> forbidden = new ArrayList<>();
forbidden.add(Expression.leaf(p));
Synthesis synthesizerWithForbidden =
new Synthesis(new BoundedShape(2, forbidden), new TreeBoundedEncoder());
Optional<Pair<Expression, Map<Parameter, Constant>>> result = synthesizerWithForbidden.synthesize(testSuite, components);
assertFalse(result.isPresent());
}
示例13: testGeneralConsequent
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Test
public void testGeneralConsequent() throws Exception {
String text = "CONSTRUCT {\n"
+ " ?x ?p2 ?y"
+ "} WHERE {\n"
+ " ?x ?p1 ?y .\n"
+ " ?p1 rdfs:subPropertyOf ?p2 .\n"
+ "}";
ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
SpinConstructRule rule = new SpinConstructRule(OWL.THING, RL_PRP_SPO1, query);
Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("p1"), ac(RDFS.SUBPROPERTYOF), new Var("p2")),
new StatementPattern(new Var("x"), new Var("p1"), new Var("y"))));
Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
new StatementPattern(new Var("subject"), new Var("predicate"), new Var("object"))));
Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
Assert.assertFalse(rule.hasAnonymousConsequent());
// Basic pattern matches
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
// Narrower patterns match (constants in place of variables)
Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBPROPERTYOF), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), new Var("prop"), c(OWL.THING))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(RDFS.SUBCLASSOF), new Var("x"))));
Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), c(FOAF.PERSON))));
}
示例14: getTopDailyMessages
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Override
public List<Message> getTopDailyMessages(int threshold, int thresholdRatio, User user) {
List<Message> messages = new ArrayList<Message>();
for (SocialNetworkService sns : socialNetworkServices) {
messages.addAll(sns.getYesterdayMessages(user));
}
messages.addAll(dao.getIncomingMessages(user,
followingService.getFollowing(user.getId()),
new DateTime().minusDays(1)));
filterByImportantMessageThreshold(threshold, thresholdRatio, user, messages);
filterAndFillMetadata(user, messages, Collections.<Message>emptyList(), false, true);
// filter out messages from the same author if he has too many on the list
Multiset<String> authors = HashMultiset.create(messages.size());
for (Iterator<Message> it = messages.iterator(); it.hasNext();) {
Message msg = it.next();
if (authors.count(msg.getAuthor().getPublicId()) > MESSAGES_BY_SAME_AUTHOR_LIMIT) {
it.remove();
continue;
}
authors.add(msg.getAuthor().getPublicId());
}
return messages;
}
示例15: supplier
import com.google.common.collect.HashMultiset; //導入方法依賴的package包/類
@Override
public Supplier<HashMultiset<byte[]>> supplier() {
return new Supplier<HashMultiset<byte[]>>() {
@Override
public HashMultiset<byte[]> get() {
if (multiset == null) {
multiset = HashMultiset.create();
}
return multiset;
}
};
}