Example usage for com.google.common.collect ImmutableMultiset copyOf

List of usage examples for com.google.common.collect ImmutableMultiset copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultiset copyOf.

Prototype

public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> elements) 

Source Link

Document

Returns an immutable multiset containing the given elements, in the "grouped iteration order" described in the class documentation.

Usage

From source file:org.joda.beans.gen.ImmPerson.java

private ImmPerson(String forename, String surname, int numberOfCars, Date dateOfBirth, String[] middleNames,
        List<Address> addressList, Map<String, Address> otherAddressMap, List<List<Address>> addressesList,
        ImmAddress mainAddress, Multiset<String> codeCounts) {
    this.forename = forename;
    this.surname = surname;
    this.numberOfCars = numberOfCars;
    this.dateOfBirth = (dateOfBirth != null ? (Date) dateOfBirth.clone() : null);
    this.middleNames = (middleNames != null ? middleNames.clone() : null);
    this.addressList = (addressList != null ? ImmutableList.copyOf(addressList) : null);
    this.otherAddressMap = (otherAddressMap != null ? ImmutableMap.copyOf(otherAddressMap) : null);
    this.addressesList = (addressesList != null ? ImmutableList.copyOf(addressesList) : null);
    this.mainAddress = mainAddress;
    this.codeCounts = (codeCounts != null ? ImmutableMultiset.copyOf(codeCounts) : null);
    validate();//from w ww  .jav  a  2 s .  c om
}

From source file:com.android.tools.idea.wizard.ModuleListModel.java

private void checkForDuplicateNames() {
    Collection<ModuleToImport> modules = getSelectedModules();
    ImmutableMultiset<String> names = ImmutableMultiset
            .copyOf(Iterables.transform(modules, new Function<ModuleToImport, String>() {
                @Override//from  www  . j  a v  a  2s.c  o m
                public String apply(@Nullable ModuleToImport input) {
                    return input == null ? null : getModuleName(input);
                }
            }));
    for (ModuleToImport module : modules) {
        ModuleValidationState state = myModules.get(module);
        if (state == ModuleValidationState.OK) {
            if (names.count(getModuleName(module)) > 1) {
                myModules.put(module, ModuleValidationState.DUPLICATE_MODULE_NAME);
            }
        }
    }
}

From source file:io.prestosql.tests.QueryAssertions.java

public static void assertEqualsIgnoreOrder(Iterable<?> actual, Iterable<?> expected, String message) {
    assertNotNull(actual, "actual is null");
    assertNotNull(expected, "expected is null");

    ImmutableMultiset<?> actualSet = ImmutableMultiset.copyOf(actual);
    ImmutableMultiset<?> expectedSet = ImmutableMultiset.copyOf(expected);
    if (!actualSet.equals(expectedSet)) {
        Multiset<?> unexpectedRows = Multisets.difference(actualSet, expectedSet);
        Multiset<?> missingRows = Multisets.difference(expectedSet, actualSet);
        int limit = 100;
        fail(format(/*from   w  ww.ja va2s .c o  m*/
                "%snot equal\n" + "Actual rows (up to %s of %s extra rows shown, %s rows in total):\n    %s\n"
                        + "Expected rows (up to %s of %s missing rows shown, %s rows in total):\n    %s\n",
                message == null ? "" : (message + "\n"), limit, unexpectedRows.size(), actualSet.size(),
                Joiner.on("\n    ").join(Iterables.limit(unexpectedRows, limit)), limit, missingRows.size(),
                expectedSet.size(), Joiner.on("\n    ").join(Iterables.limit(missingRows, limit))));
    }
}

From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java

/**
 * Computes the number of occurrences of each event type in the specified
 * {@link Scenario}./*from  ww  w  .  ja v a2  s .  co m*/
 * @param s The scenario to check.
 * @return A {@link ImmutableMultiset} of event types.
 */
public static ImmutableMultiset<Class<?>> getEventTypeCounts(Scenario s) {
    final Multiset<Class<?>> set = LinkedHashMultiset.create();
    for (final TimedEvent te : s.getEvents()) {
        set.add(te.getClass());
    }
    final List<Class<?>> toMove = new ArrayList<>();
    for (final Class<?> c : set.elementSet()) {
        if (!Modifier.isPublic(c.getModifiers()) && TimedEvent.class.isAssignableFrom(c.getSuperclass())
                && !set.contains(c.getSuperclass())) {
            toMove.add(c);
        }
    }
    for (final Class<?> c : toMove) {
        set.add(c.getSuperclass(), set.count(c));
        set.remove(c, set.count(c));
    }
    return ImmutableMultiset.copyOf(set);
}

From source file:com.palantir.atlasdb.keyvalue.impl.SweepStatsKeyValueService.java

private Runnable createFlushTask() {
    return new Runnable() {
        @Override// www. j  a v a 2 s.  c  o  m
        public void run() {
            try {
                if (totalModifications.get() >= WRITE_THRESHOLD && flushLock.tryLock()) {
                    try {
                        if (totalModifications.get() >= WRITE_THRESHOLD) {
                            // snapshot current values while holding the lock and flush
                            totalModifications.set(0);
                            Multiset<String> localWritesByTable = ImmutableMultiset.copyOf(writesByTable);
                            writesByTable.clear();
                            Set<String> localClearedTables = ImmutableSet.copyOf(clearedTables);
                            clearedTables.clear();

                            // apply back pressure by only allowing one flush at a time
                            flushWrites(localWritesByTable, localClearedTables);
                        }
                    } finally {
                        flushLock.unlock();
                    }
                }
            } catch (Throwable t) {
                log.error("Error occurred while flushing sweep stats: {}", t, t);
            }
        }
    };
}

From source file:io.airlift.testing.Assertions.java

public static void assertEqualsIgnoreOrder(Iterable<?> actual, Iterable<?> expected, String message) {
    assertNotNull(actual, "actual is null");
    assertNotNull(expected, "expected is null");

    ImmutableMultiset<?> actualSet = ImmutableMultiset.copyOf(actual);
    ImmutableMultiset<?> expectedSet = ImmutableMultiset.copyOf(expected);
    if (!actualSet.equals(expectedSet)) {
        Joiner joiner = Joiner.on("\n      ");
        fail("%sexpected: collections to be equal (ignoring order).%nActual:%n      %s%nExpected:%n      %s",
                toMessageString(message), joiner.join(actual), joiner.join(expected));
    }//ww w  .  j a va 2  s .  co m
}

From source file:com.google.devtools.build.lib.collect.ImmutableSortedKeyListMultimap.java

@Override
public Multiset<K> keys() {
    return ImmutableMultiset.copyOf(sortedKeys);
}

From source file:net.hydromatic.optiq.test.OptiqAssert.java

static ImmutableMultiset<String> toSet(ResultSet resultSet) throws SQLException {
    return ImmutableMultiset.copyOf(toStringList(resultSet, new ArrayList<String>()));
}

From source file:org.joda.beans.gen.ImmGuava.java

/**
 * Creates an instance.//from  www. j av a 2 s  .c  om
 * @param collection  the value of the property, not null
 * @param list  the value of the property, not null
 * @param set  the value of the property, not null
 * @param sortedSet  the value of the property, not null
 * @param map  the value of the property, not null
 * @param sortedMap  the value of the property, not null
 * @param biMap  the value of the property, not null
 * @param multimap  the value of the property, not null
 * @param listMultimap  the value of the property, not null
 * @param setMultimap  the value of the property, not null
 * @param multiset  the value of the property, not null
 * @param sortedMultiset  the value of the property, not null
 * @param collectionInterface  the value of the property, not null
 * @param listInterface  the value of the property, not null
 * @param setInterface  the value of the property, not null
 * @param sortedSetInterface  the value of the property, not null
 * @param mapInterface  the value of the property, not null
 * @param sortedMapInterface  the value of the property, not null
 * @param biMapInterface  the value of the property, not null
 * @param multimapInterface  the value of the property, not null
 * @param listMultimapInterface  the value of the property, not null
 * @param setMultimapInterface  the value of the property, not null
 * @param multisetInterface  the value of the property, not null
 * @param sortedMultisetInterface  the value of the property, not null
 * @param listWildExtendsT  the value of the property, not null
 * @param listWildExtendsNumber  the value of the property, not null
 * @param listWildExtendsComparable  the value of the property, not null
 * @param setWildExtendsT  the value of the property, not null
 * @param setWildExtendsNumber  the value of the property, not null
 * @param setWildExtendsComparable  the value of the property, not null
 * @param listWildBuilder1  the value of the property, not null
 * @param listWildBuilder2  the value of the property, not null
 * @param mapWildBuilder1  the value of the property, not null
 */
public ImmGuava(Collection<T> collection, List<T> list, Set<T> set, SortedSet<T> sortedSet, Map<T, String> map,
        SortedMap<T, String> sortedMap, BiMap<T, String> biMap, Multimap<T, String> multimap,
        ListMultimap<T, String> listMultimap, SetMultimap<T, String> setMultimap, Multiset<T> multiset,
        SortedMultiset<T> sortedMultiset, Collection<T> collectionInterface, List<T> listInterface,
        Set<T> setInterface, SortedSet<T> sortedSetInterface, Map<T, String> mapInterface,
        SortedMap<T, String> sortedMapInterface, BiMap<T, String> biMapInterface,
        Multimap<T, String> multimapInterface, ListMultimap<T, String> listMultimapInterface,
        SetMultimap<T, String> setMultimapInterface, Multiset<T> multisetInterface,
        SortedMultiset<T> sortedMultisetInterface, List<? extends T> listWildExtendsT,
        List<? extends Number> listWildExtendsNumber, List<? extends Comparable<?>> listWildExtendsComparable,
        Set<? extends T> setWildExtendsT, Set<? extends Number> setWildExtendsNumber,
        Set<? extends Comparable<?>> setWildExtendsComparable, List<?> listWildBuilder1,
        List<? extends Address> listWildBuilder2, Map<String, ? extends Address> mapWildBuilder1) {
    JodaBeanUtils.notNull(collection, "collection");
    JodaBeanUtils.notNull(list, "list");
    JodaBeanUtils.notNull(set, "set");
    JodaBeanUtils.notNull(sortedSet, "sortedSet");
    JodaBeanUtils.notNull(map, "map");
    JodaBeanUtils.notNull(sortedMap, "sortedMap");
    JodaBeanUtils.notNull(biMap, "biMap");
    JodaBeanUtils.notNull(multimap, "multimap");
    JodaBeanUtils.notNull(listMultimap, "listMultimap");
    JodaBeanUtils.notNull(setMultimap, "setMultimap");
    JodaBeanUtils.notNull(multiset, "multiset");
    JodaBeanUtils.notNull(sortedMultiset, "sortedMultiset");
    JodaBeanUtils.notNull(collectionInterface, "collectionInterface");
    JodaBeanUtils.notNull(listInterface, "listInterface");
    JodaBeanUtils.notNull(setInterface, "setInterface");
    JodaBeanUtils.notNull(sortedSetInterface, "sortedSetInterface");
    JodaBeanUtils.notNull(mapInterface, "mapInterface");
    JodaBeanUtils.notNull(sortedMapInterface, "sortedMapInterface");
    JodaBeanUtils.notNull(biMapInterface, "biMapInterface");
    JodaBeanUtils.notNull(multimapInterface, "multimapInterface");
    JodaBeanUtils.notNull(listMultimapInterface, "listMultimapInterface");
    JodaBeanUtils.notNull(setMultimapInterface, "setMultimapInterface");
    JodaBeanUtils.notNull(multisetInterface, "multisetInterface");
    JodaBeanUtils.notNull(sortedMultisetInterface, "sortedMultisetInterface");
    JodaBeanUtils.notNull(listWildExtendsT, "listWildExtendsT");
    JodaBeanUtils.notNull(listWildExtendsNumber, "listWildExtendsNumber");
    JodaBeanUtils.notNull(listWildExtendsComparable, "listWildExtendsComparable");
    JodaBeanUtils.notNull(setWildExtendsT, "setWildExtendsT");
    JodaBeanUtils.notNull(setWildExtendsNumber, "setWildExtendsNumber");
    JodaBeanUtils.notNull(setWildExtendsComparable, "setWildExtendsComparable");
    JodaBeanUtils.notNull(listWildBuilder1, "listWildBuilder1");
    JodaBeanUtils.notNull(listWildBuilder2, "listWildBuilder2");
    JodaBeanUtils.notNull(mapWildBuilder1, "mapWildBuilder1");
    this.collection = ImmutableList.copyOf(collection);
    this.list = ImmutableList.copyOf(list);
    this.set = ImmutableSet.copyOf(set);
    this.sortedSet = ImmutableSortedSet.copyOfSorted(sortedSet);
    this.map = ImmutableMap.copyOf(map);
    this.sortedMap = ImmutableSortedMap.copyOfSorted(sortedMap);
    this.biMap = ImmutableBiMap.copyOf(biMap);
    this.multimap = ImmutableMultimap.copyOf(multimap);
    this.listMultimap = ImmutableListMultimap.copyOf(listMultimap);
    this.setMultimap = ImmutableSetMultimap.copyOf(setMultimap);
    this.multiset = ImmutableMultiset.copyOf(multiset);
    this.sortedMultiset = ImmutableSortedMultiset.copyOfSorted(sortedMultiset);
    this.collectionInterface = ImmutableList.copyOf(collectionInterface);
    this.listInterface = ImmutableList.copyOf(listInterface);
    this.setInterface = ImmutableSet.copyOf(setInterface);
    this.sortedSetInterface = ImmutableSortedSet.copyOfSorted(sortedSetInterface);
    this.mapInterface = ImmutableMap.copyOf(mapInterface);
    this.sortedMapInterface = ImmutableSortedMap.copyOfSorted(sortedMapInterface);
    this.biMapInterface = ImmutableBiMap.copyOf(biMapInterface);
    this.multimapInterface = ImmutableMultimap.copyOf(multimapInterface);
    this.listMultimapInterface = ImmutableListMultimap.copyOf(listMultimapInterface);
    this.setMultimapInterface = ImmutableSetMultimap.copyOf(setMultimapInterface);
    this.multisetInterface = ImmutableMultiset.copyOf(multisetInterface);
    this.sortedMultisetInterface = ImmutableSortedMultiset.copyOfSorted(sortedMultisetInterface);
    this.listWildExtendsT = ImmutableList.copyOf(listWildExtendsT);
    this.listWildExtendsNumber = ImmutableList.copyOf(listWildExtendsNumber);
    this.listWildExtendsComparable = ImmutableList.copyOf(listWildExtendsComparable);
    this.setWildExtendsT = ImmutableSet.copyOf(setWildExtendsT);
    this.setWildExtendsNumber = ImmutableSet.copyOf(setWildExtendsNumber);
    this.setWildExtendsComparable = ImmutableSet.copyOf(setWildExtendsComparable);
    this.listWildBuilder1 = ImmutableList.copyOf(listWildBuilder1);
    this.listWildBuilder2 = ImmutableList.copyOf(listWildBuilder2);
    this.mapWildBuilder1 = ImmutableMap.copyOf(mapWildBuilder1);
}

From source file:com.proofpoint.http.client.MediaType.java

private Map<String, ImmutableMultiset<String>> parametersAsMap() {
    return Maps.transformValues(parameters.asMap(),
            new Function<Collection<String>, ImmutableMultiset<String>>() {
                @Override/*from ww  w.  j  a  va  2 s  . c  o  m*/
                public ImmutableMultiset<String> apply(Collection<String> input) {
                    return ImmutableMultiset.copyOf(input);
                }
            });
}