Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:com.twitter.common.metrics.JvmStats.java

/**
 * Use reflection to get optional gauges that only work in Java 1.7.
 *//*from  ww  w.  jav a  2  s .  co m*/
private static Multimap<String, AbstractGauge<Long>> buildJava17Gauges() {
    Multimap<String, AbstractGauge<Long>> gauges = ArrayListMultimap.create();

    try {
        Class<?> bufferPoolMXBean = ClassLoader.getSystemClassLoader()
                .loadClass("java.lang.management.BufferPoolMXBean");
        Method getPlatformMxBeans = ManagementFactory.class.getMethod("getPlatformMXBeans", Class.class);
        @SuppressWarnings("unchecked")
        List<Object> beans = (List<Object>) getPlatformMxBeans.invoke(null, bufferPoolMXBean);
        for (Object pool : beans) {
            @SuppressWarnings("unchecked")
            String name = (String) bufferPoolMXBean.getMethod("getName").invoke(pool);

            gauges.put(name, reflectMethodToGauge("count", bufferPoolMXBean, "getCount", pool));
            gauges.put(name, reflectMethodToGauge("used", bufferPoolMXBean, "getMemoryUsed", pool));
            gauges.put(name, reflectMethodToGauge("max", bufferPoolMXBean, "getTotalCapacity", pool));
        }
    } catch (ClassNotFoundException ex) {
        // If any of the above reflection fails, it's ok.  These gauges just won't be present.
    } catch (NoSuchMethodException ex) {
        // ditto
    } catch (IllegalAccessException ex) {
        // same
    } catch (InvocationTargetException ex) {
        // etc.
    }

    return gauges;
}

From source file:com.ardor3d.scenegraph.AbstractBufferData.java

@SuppressWarnings("unchecked")
private static final Multimap<Object, Integer> gatherGCdIds(Multimap<Object, Integer> store) {
    // Pull all expired vbos from ref queue and add to an id multimap.
    ContextIdReference<AbstractBufferData<?>> ref;
    while ((ref = (ContextIdReference<AbstractBufferData<?>>) _vboRefQueue.poll()) != null) {
        if (Constants.useMultipleContexts) {
            final Set<Object> contextObjects = ref.getContextObjects();
            for (final Object o : contextObjects) {
                // Add id to map
                final Integer id = ref.getValue(o);
                if (id != null) {
                    if (store == null) { // lazy init
                        store = ArrayListMultimap.create();
                    }//from www  . ja  v  a  2  s . c o m
                    store.put(o, id);
                }
            }
        } else {
            final Integer id = ref.getValue(null);
            if (id != null) {
                if (store == null) { // lazy init
                    store = ArrayListMultimap.create();
                }
                store.put(ContextManager.getCurrentContext().getGlContextRep(), id);
            }
        }
        ref.clear();
    }

    return store;
}

From source file:org.apache.cassandra.dht.RangeStreamer.java

/**
 * @param rangesWithSources The ranges we want to fetch (key) and their potential sources (value)
 * @param sourceFilters A (possibly empty) collection of source filters to apply. In addition to any filters given
 *                      here, we always exclude ourselves.
 * @param keyspace keyspace name//  ww w  .j  a  v  a  2  s  .c om
 * @return Map of source endpoint to collection of ranges
 */
private static Multimap<InetAddress, Range<Token>> getRangeFetchMap(
        Multimap<Range<Token>, InetAddress> rangesWithSources, Collection<ISourceFilter> sourceFilters,
        String keyspace) {
    Multimap<InetAddress, Range<Token>> rangeFetchMapMap = HashMultimap.create();
    for (Range<Token> range : rangesWithSources.keySet()) {
        boolean foundSource = false;

        outer: for (InetAddress address : rangesWithSources.get(range)) {
            if (address.equals(FBUtilities.getBroadcastAddress())) {
                // If localhost is a source, we have found one, but we don't add it to the map to avoid streaming locally
                foundSource = true;
                continue;
            }

            for (ISourceFilter filter : sourceFilters) {
                if (!filter.shouldInclude(address))
                    continue outer;
            }

            rangeFetchMapMap.put(address, range);
            foundSource = true;
            break; // ensure we only stream from one other node for each range
        }

        if (!foundSource)
            throw new IllegalStateException("unable to find sufficient sources for streaming range " + range
                    + " in keyspace " + keyspace);
    }

    return rangeFetchMapMap;
}

From source file:vazkii.botania.common.item.equipment.armor.terrasteel.ItemTerrasteeelArmor.java

@Override
public Multimap getItemAttributeModifiers() {
    Multimap map = HashMultimap.create();
    map.put(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName(),
            new AttributeModifier(new UUID(171328 /** Random number **/
                    , armorType), "Armor modifier" + armorType, getHealthBoost(), 0));
    return map;/*w ww. j  a  v  a2  s  .  co m*/
}

From source file:org.lealone.cluster.dht.RangeStreamer.java

/**
 * @param rangesWithSources The ranges we want to fetch (key) and their potential sources (value)
 * @param sourceFilters A (possibly empty) collection of source filters to apply. 
 *                      In addition to any filters given here, we always exclude ourselves.
 * @param dbName database name/*from w ww.ja  v a2  s  .com*/
 * @return Map of source endpoint to collection of ranges
 */
private static Multimap<InetAddress, Range<Token>> getRangeFetchMap(
        Multimap<Range<Token>, InetAddress> rangesWithSources, Collection<ISourceFilter> sourceFilters,
        String dbName) {
    Multimap<InetAddress, Range<Token>> rangeFetchMapMap = HashMultimap.create();
    for (Range<Token> range : rangesWithSources.keySet()) {
        boolean foundSource = false;

        outer: for (InetAddress address : rangesWithSources.get(range)) {
            if (address.equals(Utils.getBroadcastAddress())) {
                // If localhost is a source, we have found one, but we don't add it to the map to avoid streaming
                // locally
                foundSource = true;
                continue;
            }

            for (ISourceFilter filter : sourceFilters) {
                if (!filter.shouldInclude(address))
                    continue outer;
            }

            rangeFetchMapMap.put(address, range);
            foundSource = true;
            break; // ensure we only stream from one other node for each range
        }

        if (!foundSource)
            throw new IllegalStateException("unable to find sufficient sources for streaming range " + range
                    + " in database " + dbName);
    }

    return rangeFetchMapMap;
}

From source file:org.jclouds.rest.internal.RestAnnotationProcessor.java

private static void addHeader(Multimap<String, String> headers, Headers header,
        Multimap<String, ?> tokenValues) {
    for (int i = 0; i < header.keys().length; i++) {
        String value = header.values()[i];
        value = replaceTokens(value, tokenValues);
        headers.put(header.keys()[i], value);
    }/*from w w  w .ja  v a 2 s.co  m*/
}

From source file:com.googlesource.gerrit.plugins.cookbook.DeployedOnIncludedInExtension.java

@Override
public Multimap<String, String> getIncludedIn(String project, String commit, Collection<String> tags,
        Collection<String> branches) {
    Multimap<String, String> m = ArrayListMultimap.create();
    m.put(PROD, "A");
    m.put(PROD, "B");
    m.put(PROD, "C");
    m.put(STAGING, "X");
    m.put(STAGING, "Y");
    m.put(STAGING, "Z");
    return m;//from  w  ww  . j a  va2s . c om
}

From source file:com.android.tools.idea.gradle.variant.view.ModuleVariantsInfoDialog.java

@NotNull
private static JTree createDependenciesTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {
        @Override//from w w w . j  av a  2  s .  c o m
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            if (value instanceof DefaultMutableTreeNode) {
                Object data = ((DefaultMutableTreeNode) value).getUserObject();
                if (data instanceof String) {
                    appendVariant((String) data);
                } else if (data instanceof DependencyTreeElement) {
                    DependencyTreeElement dependency = (DependencyTreeElement) data;
                    appendModule(dependency.myModule, dependency.myVariant);
                }
            }
        }
    };

    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);

    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;

    Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();

    for (Variant variant : androidProject.getVariants()) {
        for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
            String gradlePath = library.getProject();
            if (gradlePath == null) {
                continue;
            }
            Module dependency = GradleUtil.findModuleByGradlePath(module.getProject(), gradlePath);
            if (dependency != null) {
                DependencyTreeElement element = new DependencyTreeElement(dependency,
                        library.getProjectVariant());
                dependenciesByVariant.put(variant.getName(), element);
            }
        }
    }

    // Consolidate variants. This means if "debug" and "release" have the same dependencies, we show only one node as "debug, release".
    List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet());
    Collections.sort(variantNames);

    List<String> consolidatedVariants = Lists.newArrayList();
    List<String> variantsToSkip = Lists.newArrayList();

    int variantCount = variantNames.size();
    for (int i = 0; i < variantCount; i++) {
        String variant1 = variantNames.get(i);
        if (variantsToSkip.contains(variant1)) {
            continue;
        }

        Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1);
        for (int j = i + 1; j < variantCount; j++) {
            String variant2 = variantNames.get(j);
            Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2);

            if (set1.equals(set2)) {
                variantsToSkip.add(variant2);
                if (!consolidatedVariants.contains(variant1)) {
                    consolidatedVariants.add(variant1);
                }
                consolidatedVariants.add(variant2);
            }
        }

        String variantName = variant1;
        if (!consolidatedVariants.isEmpty()) {
            variantName = Joiner.on(", ").join(consolidatedVariants);
        }

        DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
        root.add(variantNode);

        List<DependencyTreeElement> dependencies = Lists.newArrayList(set1);
        Collections.sort(dependencies);

        for (DependencyTreeElement dependency : dependencies) {
            variantNode.add(new DefaultMutableTreeNode(dependency));
        }

        consolidatedVariants.clear();
    }

    CheckboxTree tree = new CheckboxTree(renderer, root);
    tree.setRootVisible(false);
    TreeUtil.expandAll(tree);

    return tree;
}

From source file:com.shinoow.abyssalcraft.common.items.ItemCudgel.java

@Override
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
public Multimap getItemAttributeModifiers() {
    Multimap multimap = super.getItemAttributeModifiers();
    multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(),
            new AttributeModifier(field_111210_e, "Weapon modifier", 20, 0));
    return multimap;
}

From source file:eumetsat.pn.common.AbstractApp.java

/**
 * Parse a filter string in the form of key1:val1,val2#key2:val3,val4#
 *
 * @param filterString//from w w w . ja  v a 2s  . c  om
 * @return
 */
protected static Multimap<String, String> parseFiltersTerms(String filterString) {
    Multimap<String, String> filterTermsMap = HashMultimap.create();
    //parse only when there is something to return
    if (filterString != null && filterString.length() > 0) {
        // Do not use a regexpr for the moment but should do
        String[] elems = filterString.split("[\\+, ]");
        for (String elem : elems) {
            // ignore empty elements
            if (elem.length() > 0) {
                String[] dummy = elem.split(":");
                if (dummy.length < 2) {
                    throw new RuntimeException(
                            "Error filterTermsMap incorrectly formatted. map content = " + elem);
                }
                filterTermsMap.put(dummy[0], dummy[1]);
            }
        }
    }
    return filterTermsMap;
}