List of usage examples for com.google.common.collect ImmutableMultiset copyOf
public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> elements)
From source file:com.google.caliper.worker.AllocationStats.java
/** * Constructs a new {@link AllocationStats} with the given allocations and the number of * {@code reps} passed to the benchmark method. *//*from ww w . j av a 2s . c o m*/ AllocationStats(Collection<Allocation> allocations, int reps) { this(allocations.size(), Allocation.getTotalSize(allocations), reps, ImmutableMultiset.copyOf(allocations)); }
From source file:com.facebook.presto.tests.QueryAssertions.java
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)))); }//from ww w .jav a 2 s . c om }
From source file:org.tensorics.core.tensor.ImmutableTensor.java
/** * Returns a builder for an {@link ImmutableTensor}. As argument it takes set of class of coordinates which * represent the dimensions of the tensor. * * @param dimensions a set of classes that can later be used as coordinates for the tensor entries. * @return a builder for {@link ImmutableTensor} * @param <T> type of values in Tensor. *///from ww w . j a v a2s .c o m public static final <T> Builder<T> builder(Iterable<Class<?>> dimensions) { return new Builder<>(requireValidDimensions(ImmutableMultiset.copyOf(dimensions))); }
From source file:org.sonar.java.checks.RedundantAbstractMethodCheck.java
private static boolean differentThrows(JavaSymbol.MethodJavaSymbol method, JavaSymbol.MethodJavaSymbol overridee) { return !ImmutableMultiset.copyOf(method.thrownTypes()) .equals(ImmutableMultiset.copyOf(overridee.thrownTypes())); }
From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlag.java
@Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException { List<String> specifiedValues = ruleContext.attributes().get("allowed_values", STRING_LIST); ImmutableSet<String> values = ImmutableSet.copyOf(specifiedValues); Predicate<String> isValidValue = Predicates.in(values); if (values.size() != specifiedValues.size()) { ImmutableMultiset<String> groupedValues = ImmutableMultiset.copyOf(specifiedValues); ImmutableList.Builder<String> duplicates = new ImmutableList.Builder<String>(); for (Multiset.Entry<String> value : groupedValues.entrySet()) { if (value.getCount() > 1) { duplicates.add(value.getElement()); }/*from w w w. j a v a2 s.co m*/ } ruleContext.attributeError("allowed_values", "cannot contain duplicates, but contained multiple of " + Printer.repr(duplicates.build(), '\'')); } String defaultValue = ruleContext.attributes().get("default_value", STRING); if (!isValidValue.apply(defaultValue)) { ruleContext.attributeError("default_value", "must be one of " + Printer.repr(values.asList(), '\'') + ", but was " + Printer.repr(defaultValue, '\'')); } if (ruleContext.hasErrors()) { // Don't bother validating the value if the flag was already incorrectly specified without // looking at the value. return null; } String value = ruleContext.getFragment(ConfigFeatureFlagConfiguration.class) .getFeatureFlagValue(ruleContext.getOwner()).or(defaultValue); if (!isValidValue.apply(value)) { // TODO(mstaib): When configurationError is available, use that instead. ruleContext.ruleError("value must be one of " + Printer.repr(values.asList(), '\'') + ", but was " + Printer.repr(value, '\'')); return null; } ConfigFeatureFlagProvider provider = ConfigFeatureFlagProvider.create(value, isValidValue); return new RuleConfiguredTargetBuilder(ruleContext) .setFilesToBuild(NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER)) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) .addProvider(ConfigFeatureFlagProvider.class, provider).addNativeDeclaredProvider(provider).build(); }
From source file:com.google.caliper.runner.EnvironmentGetter.java
private static String describe(Multimap<String, String> cpuInfo, String s) { Collection<String> strings = cpuInfo.get(s); // TODO redo the ImmutableMultiset.toString() call so we don't get square brackets return (strings.size() == 1) ? strings.iterator().next() : ImmutableMultiset.copyOf(strings).toString(); }
From source file:org.joda.beans.gen.ImmSubSubPersonFinal.java
/** * Restricted constructor.//from ww w . j a v a 2 s . com * @param builder the builder to copy from, not null */ private ImmSubSubPersonFinal(ImmSubSubPersonFinal.Builder builder) { super(builder); this.codeCounts = (builder.codeCounts != null ? ImmutableMultiset.copyOf(builder.codeCounts) : null); }
From source file:org.xacml4j.v30.BagOfAttributeExp.java
/** * Constructs bag of attributes./*www . j a v a2s . c o m*/ * * @param type a bag attribute type * @param attributes a collection of attributes */ BagOfAttributeExp(BagOfAttributeExpType type, Iterable<AttributeExp> attributes) { for (AttributeExp attr : attributes) { assertExpressionType(attr, type); } this.type = type; this.values = ImmutableMultiset.copyOf(attributes); this.hashCode = Objects.hashCode(type, values); }
From source file:org.tensorics.core.tensor.ImmutableTensor.java
/** * Returns a builder for an {@link ImmutableTensor}. The dimensions (classes of coordinates) of the future tensor * have to be given as arguments here./*from w w w . j a v a2 s . com*/ * * @param dimensions the dimensions of the tensor to create * @return a builder for an immutable tensor * @param <T> the type of values of the tensor */ public static final <T> Builder<T> builder(Class<?>... dimensions) { return new Builder<>(requireValidDimensions(ImmutableMultiset.copyOf(dimensions))); }
From source file:de.unentscheidbar.validation.internal.Collections3.java
/** * Returns an immutable version of the given collection and tries to preserve any special * properties of that collection. Lists are converted to immutable lists, Sets are converted to * immutable sets, sorted sets to immutable sorted sets, etc. * <p>//w ww. j av a 2 s . co m * If the specialization of the given collection is not recognized, it is converted to an * immutable list. * </p> * * @param c * The collection that * @return An immutable version of the given collection or {@code null} iff {@code c} was * {@code null}. */ public static <C> Collection<C> immutableCopyOf(@Nullable Collection<C> c) { if (c == null) return null; /* Most common cases first */ if (c instanceof List<?>) { return ImmutableList.copyOf(c); } else if (c instanceof Set<?>) { return ImmutableSet.copyOf(c); } else if (c instanceof SortedSet<?>) { return ImmutableSortedSet.copyOf(c); } else if (c instanceof Multiset<?>) { return ImmutableMultiset.copyOf(c); } else { return ImmutableList.copyOf(c); } }