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:org.jclouds.rds.options.ListSecurityGroupsOptions.java

@Override
public Multimap<String, String> buildFormParameters() {
    Multimap<String, String> params = super.buildFormParameters();
    if (marker != null)
        params.put("Marker", marker.toString());
    return params;
}

From source file:de.ellpeck.actuallyadditions.mod.items.ItemKnife.java

@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
    Multimap<String, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
    if (slot == EntityEquipmentSlot.MAINHAND) {
        map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(),
                new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Knife Modifier", 3, 0));
    }/*from   w  ww  .  j a va2s  .  co m*/
    return map;
}

From source file:com.rackspacecloud.blueflood.io.AbstractMetricsRW.java

/**
 * Convert a collection of {@link com.rackspacecloud.blueflood.types.IMetric}
 * to a {@link com.google.common.collect.Multimap}
 *
 * @param metrics//from www .  j a v  a 2 s .com
 * @return
 */
protected Multimap<Locator, IMetric> asMultimap(Collection<IMetric> metrics) {
    Multimap<Locator, IMetric> map = LinkedListMultimap.create();
    for (IMetric metric : metrics)
        map.put(metric.getLocator(), metric);
    return map;
}

From source file:org.lanternpowered.server.network.vanilla.message.processor.play.ProcessorPlayOutTabListEntries.java

@Override
public void process(CodecContext context, MessagePlayOutTabListEntries message, List<Message> output)
        throws CodecException {
    final Multimap<Class<?>, Entry> entriesByType = HashMultimap.create();
    for (Entry entry : message.getEntries()) {
        entriesByType.put(entry.getClass(), entry);
    }/*from   ww  w  . jav a2s.co m*/
    if (entriesByType.isEmpty()) {
        return;
    }
    if (entriesByType.keySet().size() == 1) {
        output.add(message);
    } else {
        for (java.util.Map.Entry<Class<?>, Collection<Entry>> en : entriesByType.asMap().entrySet()) {
            output.add(new MessagePlayOutTabListEntries(en.getValue()));
        }
    }
}

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

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

From source file:org.obm.sync.client.setting.SettingClient.java

@Override
public void setEmailForwarding(AccessToken token, ForwardingSettings fs) throws ServerFault {
    Multimap<String, String> params = initParams(token);
    params.put("enabled", "" + fs.isEnabled());
    if (fs.getEmail() != null && fs.isEnabled()) {
        params.put("email", fs.getEmail());
    }/* ww w.j  a v  a 2 s  . c o m*/
    params.put("localCopy", "" + fs.isLocalCopy());
    Document doc = execute(token, "/setting/setEmailForwarding", params);
    exceptionFactory.checkServerFaultException(doc);
}

From source file:com.google.devtools.build.lib.analysis.config.ConfigurationResolver.java

/**
 * Variation of {@link Multimap#put} that triggers an exception if a value already exists.
 *///from w  ww.j  a v a 2  s .  c  om
@VisibleForTesting
public static <K, V> void putOnlyEntry(Multimap<K, V> map, K key, V value) {
    // Performance note: while "Verify.verify(!map.containsKey(key, value), String.format(...)))"
    // is simpler code, profiling shows a substantial performance penalty to that approach
    // (~10% extra analysis phase time on a simple cc_binary). Most of that is from the cost of
    // evaluating value.toString() on every call. This approach essentially eliminates the overhead.
    if (map.containsKey(key)) {
        throw new VerifyException(
                String.format("couldn't insert %s: map already has key %s", value.toString(), key.toString()));
    }
    map.put(key, value);
}

From source file:org.jclouds.sqs.options.SendMessageOptions.java

@Override
public Multimap<String, String> buildFormParameters() {
    Multimap<String, String> params = super.buildFormParameters();
    if (delaySeconds != null)
        params.put("DelaySeconds", delaySeconds.toString());
    return params;
}

From source file:it.units.malelab.ege.cfggp.operator.StandardTreeCrossover.java

private void populateMultimap(Node<T> node, Multimap<T, Node<T>> multimap) {
    if (node.getChildren().isEmpty()) {
        return;//from ww  w.j a  v  a  2 s. c  om
    }
    multimap.put(node.getContent(), node);
    for (Node<T> child : node.getChildren()) {
        populateMultimap(child, multimap);
    }

}

From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java

/**
 * Update the accounts in the login and config files
 *
 * @throws ManageUsersException//from   w ww .  j  a  va2  s.  com
 */
private static void updateAccounts(final PublicKey pubKey, final UserInfo userInfo, final String loginFilePath,
        final String groupFilePath, final Action action, final String sourceLoginFile,
        final String sourceGroupFile) throws ManageUsersException {
    try {
        Properties destinationLoginProps = new Properties();
        try (InputStreamReader stream = new InputStreamReader(new FileInputStream(loginFilePath))) {
            destinationLoginProps.load(stream);
        } catch (Exception e) {
            exitWithErrorMessage("could not read login file : " + loginFilePath, null, e);
        }

        Multimap<String, String> destinationGroupsMap = loadGroups(groupFilePath);

        Properties sourceLoginProps = new Properties();
        if (sourceLoginFile != null) {
            try (InputStreamReader stream = new InputStreamReader(new FileInputStream(sourceLoginFile))) {
                sourceLoginProps.load(stream);
            } catch (Exception e) {
                exitWithErrorMessage("could not read source login file : " + sourceLoginFile, null, e);
            }
        } else if (userInfo != null) {
            if (userInfo.getPassword() == null) {
                // password can be null in case of account deletion
                sourceLoginProps.put(userInfo.getLogin(), "");
            } else {
                sourceLoginProps.put(userInfo.getLogin(), userInfo.getPassword());
            }
        }

        Multimap<String, String> sourceGroupsMap = null;

        if (sourceGroupFile != null) {
            sourceGroupsMap = loadGroups(sourceGroupFile);
        } else {
            sourceGroupsMap = TreeMultimap.create();
            if (userInfo != null && !userInfo.getGroups().isEmpty()) {
                for (String group : userInfo.getGroups()) {
                    sourceGroupsMap.put(userInfo.getLogin(), group);
                }
            }
        }
        Collection<String> sourceLoginNames = sourceLoginProps.stringPropertyNames();
        if (sourceLoginNames.isEmpty()) {
            sourceLoginNames = sourceGroupsMap.keySet();
        }

        boolean bulkMode = sourceLoginNames.size() > 1;

        for (String user : sourceLoginNames) {
            UserInfo sourceUserInfo = new UserInfo();
            sourceUserInfo.setLogin(user);
            sourceUserInfo.setPassword((String) sourceLoginProps.get(user));
            if (sourceGroupsMap.containsKey(user)) {
                sourceUserInfo.setGroups(sourceGroupsMap.get(user));
            }

            switch (action) {
            case CREATE:
                createAccount(pubKey, sourceUserInfo, loginFilePath, groupFilePath, destinationLoginProps,
                        destinationGroupsMap);
                break;
            case UPDATE:
                updateAccount(pubKey, sourceUserInfo, loginFilePath, destinationLoginProps,
                        destinationGroupsMap, bulkMode);
                break;
            case DELETE:
                deleteAccount(sourceUserInfo, loginFilePath, groupFilePath, destinationLoginProps,
                        destinationGroupsMap);
                break;
            }
        }

        storeLoginFile(loginFilePath, destinationLoginProps);

        storeGroups(groupFilePath, destinationGroupsMap);

    } catch (Throwable t) {
        exitWithErrorMessage("Unexpected error", null, t);
    }
}