本文整理匯總了Java中com.google.common.collect.ImmutableMultiset類的典型用法代碼示例。如果您正苦於以下問題:Java ImmutableMultiset類的具體用法?Java ImmutableMultiset怎麽用?Java ImmutableMultiset使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ImmutableMultiset類屬於com.google.common.collect包,在下文中一共展示了ImmutableMultiset類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assertErrorsOnLines
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
/**
* Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
* on the given lines of the given file. If there should be multiple errors on a line, the line
* number must appear multiple times. There may not be any errors in any other file.
*/
public void assertErrorsOnLines(String file,
List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
String message = diagnostic.getMessage(Locale.US);
// The source may be null, e.g. for diagnostics about command-line flags
assertNotNull(message, diagnostic.getSource());
String sourceName = diagnostic.getSource().getName();
assertEquals(
"unexpected error in source file " + sourceName + ": " + message,
file, sourceName);
actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());
// any errors from the compiler that are not related to this checker should fail
assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
}
assertEquals(
ImmutableMultiset.copyOf(Longs.asList(lines)),
ImmutableMultiset.copyOf(actualErrors.get(file)));
}
示例2: should_stop_success_demo_first
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void should_stop_success_demo_first() throws Throwable {
cleanFolder("flowCliE");
CountDownLatch countDownLatch = new CountDownLatch(1);
applicationEventMulticaster.addApplicationListener((ApplicationListener<PluginStatusChangeEvent>) event -> {
if (ImmutableMultiset.of(PluginStatus.INSTALLING).contains(event.getPluginStatus())) {
countDownLatch.countDown();
}
});
pluginService.install("flowCliE");
countDownLatch.await(30, TimeUnit.SECONDS);
pluginService.stop("flowCliE");
Plugin plugin = pluginDao.get("flowCliE");
Assert.assertEquals(PluginStatus.PENDING, plugin.getStatus());
Assert.assertEquals(false, plugin.getStopped());
}
示例3: identifyDuplicates
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
private void identifyDuplicates(List<ModContainer> mods)
{
TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
for (ModContainer mc : mods)
{
if (mc.getSource() != null)
{
dupsearch.put(mc, mc.getSource());
}
}
ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
for (Entry<ModContainer> e : duplist.entrySet())
{
if (e.getCount() > 1)
{
FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement()));
dupes.putAll(e.getElement(),dupsearch.get(e.getElement()));
}
}
if (!dupes.isEmpty())
{
throw new DuplicateModsFoundException(dupes);
}
}
示例4: create
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@VisibleForTesting
static AttributeAggregate create(Supplier<Iterable<IAttribute>> attributes) {
Supplier<Multiset<Pair<String, String>>> aggregator = Suppliers.compose(
attributes1 -> {
ImmutableMultiset.Builder<Pair<String, String>> builder = ImmutableMultiset.builder();
for (IAttribute attribute : attributes1) {
for (String value : attribute.getValues()) {
builder.add(Pair.of(attribute.getName(), value));
}
}
return builder.build();
},
attributes
);
return new AttributeAggregate(aggregator);
}
示例5: testLotsOfRandomInserts
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void testLotsOfRandomInserts() {
int lots = 50000;
final FibonacciQueue<Integer> queue = FibonacciQueue.create();
// Insert lots of random numbers.
final ImmutableMultiset.Builder<Integer> insertedBuilder = ImmutableMultiset.builder();
final Random random = new Random();
for (int i = 0; i < lots; i++) {
int r = random.nextInt();
insertedBuilder.add(r);
queue.add(r);
}
final Multiset<Integer> inserted = insertedBuilder.build();
assertEquals(lots, queue.size());
// Ensure it contains the same multiset of values that we put in
assertEquals(inserted, ImmutableMultiset.copyOf(queue));
// Ensure the numbers come out in increasing order.
final List<Integer> polled = Lists.newLinkedList();
while (!queue.isEmpty()) {
polled.add(queue.poll());
}
assertTrue(Ordering.<Integer>natural().isOrdered(polled));
// Ensure the same multiset of values came out that we put in
assertEquals(inserted, ImmutableMultiset.copyOf(polled));
assertEquals(0, queue.size());
}
示例6: equals
import com.google.common.collect.ImmutableMultiset; //導入依賴的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);
}
示例7: create
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Override
public Optional<MultisetProperty> create(Config config) {
DeclaredType type = maybeDeclared(config.getProperty().getType()).orNull();
if (type == null || !erasesToAnyOf(type, Multiset.class, ImmutableMultiset.class)) {
return Optional.absent();
}
TypeMirror elementType = upperBound(config.getElements(), type.getTypeArguments().get(0));
Optional<TypeMirror> unboxedType = maybeUnbox(elementType, config.getTypes());
boolean needsSafeVarargs = needsSafeVarargs(unboxedType.or(elementType));
boolean overridesSetCountMethod =
hasSetCountMethodOverride(config, unboxedType.or(elementType));
boolean overridesVarargsAddMethod =
hasVarargsAddMethodOverride(config, unboxedType.or(elementType));
return Optional.of(new MultisetProperty(
config.getMetadata(),
config.getProperty(),
needsSafeVarargs,
overridesSetCountMethod,
overridesVarargsAddMethod,
elementType,
unboxedType));
}
示例8: testImmutableSetProperty
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void testImmutableSetProperty() {
behaviorTester
.with(new Processor(features))
.with(new SourceBuilder()
.addLine("package com.example;")
.addLine("@%s", FreeBuilder.class)
.addLine("public abstract class DataType {")
.addLine(" public abstract %s<%s> items();", ImmutableMultiset.class, String.class)
.addLine("")
.addLine(" public static class Builder extends DataType_Builder {}")
.addLine(" public static Builder builder() {")
.addLine(" return new Builder();")
.addLine(" }")
.addLine("}")
.build())
.with(testBuilder()
.addLine("DataType value = new DataType.Builder()")
.addLine(" .addItems(\"one\")")
.addLine(" .addItems(\"two\")")
.addLine(" .build();")
.addLine("assertThat(value.items()).iteratesAs(\"one\", \"two\");")
.build())
.runTest();
}
示例9: testImmutableSetProperty
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void testImmutableSetProperty() {
behaviorTester
.with(new Processor(features))
.with(new SourceBuilder()
.addLine("package com.example;")
.addLine("@%s", FreeBuilder.class)
.addLine("public abstract class DataType {")
.addLine(" public abstract %s<%s> getItems();", ImmutableMultiset.class, String.class)
.addLine("")
.addLine(" public static class Builder extends DataType_Builder {}")
.addLine(" public static Builder builder() {")
.addLine(" return new Builder();")
.addLine(" }")
.addLine("}")
.build())
.with(new TestBuilder()
.addLine("com.example.DataType value = new com.example.DataType.Builder()")
.addLine(" .addItems(\"one\")")
.addLine(" .addItems(\"two\")")
.addLine(" .build();")
.addLine("assertThat(value.getItems()).iteratesAs(\"one\", \"two\");")
.build())
.runTest();
}
示例10: testGetIdentifier
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void testGetIdentifier() throws Exception {
MathTag tagX = new MathTag(1, "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mi>x</mi></mrow></math>", WikiTextUtils.MathMarkUpType.MATHML);
assertEquals(ImmutableSet.of("x"), tagX.getIdentifier(true, true).elementSet());
assertEquals(ImmutableSet.of("x"), tagX.getIdentifier(false, true).elementSet());
MathTag schrödinger = new MathTag(1, getTestResource("com/formulasearchengine/mathosphere/mlp/schrödinger_eq.xml"), WikiTextUtils.MathMarkUpType.MATHML);
//MathTag schrödingerTex = new MathTag(1,"i\\hbar\\frac{\\partial}{\\partial t}\\Psi(\\mathbb{r},\\,t)=-\\frac{\\hbar^{2}}{2m}" +
// "\\nabla^{2}\\Psi(\\mathbb{r},\\,t)+V(\\mathbb{r})\\Psi(\\mathbb{r},\\,t).", WikiTextUtils.MathMarkUpType.LATEX);
ImmutableMultiset<String> lIds = ImmutableMultiset.of("i",
"\\hbar", "\\hbar",
"t", "t", "t", "t",
"\\Psi", "\\Psi", "\\Psi",
"\\mathbb{r}", "\\mathbb{r}", "\\mathbb{r}", "\\mathbb{r}",
"V",
"m");
assertEquals(lIds, schrödinger.getIdentifier(true, false));
}
示例11: check
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
final void check() {
runTester()
.assertNonNullValues(
Gender.MALE,
Integer.valueOf(0),
0,
"",
"",
ImmutableList.of(),
ImmutableList.of(),
ImmutableMap.of(),
ImmutableMap.of(),
ImmutableSet.of(),
ImmutableSet.of(),
ImmutableSortedSet.of(),
ImmutableSortedSet.of(),
ImmutableMultiset.of(),
ImmutableMultiset.of(),
ImmutableMultimap.of(),
ImmutableMultimap.of(),
ImmutableTable.of(),
ImmutableTable.of());
}
示例12: data
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Parameters(name = "{index}:immutable={1}")
public static Collection<Object[]> data() {
return ImmutableList.of(
//Mutable collections
new Object[]{Lists.newArrayList(1, 2, 3), false},
new Object[]{Sets.newHashSet("1", "2"), false},
new Object[]{Collection.class.cast(Lists.newArrayList(true, false)), false},
//Immutable collections
new Object[]{ImmutableList.of(1, 2, 3), true},
new Object[]{ImmutableSet.of("1", "2"), true},
new Object[]{ImmutableSortedSet.of(1, 2, 3), true},
new Object[]{ImmutableMultiset.of(1, 2, 3), true},
new Object[]{Collection.class.cast(ImmutableList.of(true, false)), true},
new Object[]{Collections.unmodifiableList(Lists.newArrayList(1, 2, 3)), true},
new Object[]{Collections.unmodifiableSet(Sets.newHashSet("1", "2")), true},
new Object[]{Collections.unmodifiableCollection(Lists.newArrayList(true, false)), true}
);
}
示例13: 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;
}
示例14: testTransform
import com.google.common.collect.ImmutableMultiset; //導入依賴的package包/類
@Test
public void testTransform()
{
List<String> lines = Arrays.asList("#Comment line", "#Another comment line",
"11\t47359281\t.\tC\tG\t.\t.\tCADD_SCALED=33.0", "11\t47359281\tC\tCC\t2.3\t33.0",
"11\t47359281\t.\tC\tCG\t.\t.\tCADD_SCALED=33.0", "11\t47359281\t.\tCG\tC\t.\t.\tCADD_SCALED=33.0");
Multiset<LineType> expected = ImmutableMultiset.of(COMMENT, COMMENT, VCF, CADD, INDEL_NOCADD, INDEL_NOCADD);
Assert.assertEquals(lineParser.transformLines(lines.stream(), output, error), expected);
verify(output).accept("##fileformat=VCFv4.0");
verify(output).accept("#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO");
verify(output).accept("11\t47359281\t.\tC\tG\t.\t.\t.");
verify(output).accept("11\t47359281\t.\tC\tCC\t.\t.\tCADD=2.3;CADD_SCALED=33.0");
verify(error).accept("Line 5:\t11\t47359281\t.\tC\tCG\t.\t.\tCADD_SCALED=33.0");
verify(error).accept("Line 6:\t11\t47359281\t.\tCG\tC\t.\t.\tCADD_SCALED=33.0");
}
示例15: 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 ) );
}