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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value pairs in this multimap.

Usage

From source file:cuchaz.enigma.translation.Translator.java

default <K extends Translatable, V extends Translatable> Multimap<K, V> translate(Multimap<K, V> translatable) {
    Multimap<K, V> result = HashMultimap.create(translatable.size(), 1);
    for (Map.Entry<K, Collection<V>> entry : translatable.asMap().entrySet()) {
        result.putAll(translate(entry.getKey()), translate(entry.getValue()));
    }/*from  ww  w.ja va2 s  .  c o m*/
    return result;
}

From source file:fr.ippon.wip.http.request.AbstractRequestBuilder.java

/**
 * Copy parameters and exclude those prefixed by
 * WIPortlet.WIP_REQUEST_PARAMS_PREFIX_KEY
 * //from w  w w .j a  v a  2  s.  c o  m
 * @param parameterMap
 */
private void copyParameters(Multimap<String, String> parameterMap) {
    if (parameterMap == null || parameterMap.size() == 0)
        return;

    this.parameterMap = Multimaps.filterKeys(parameterMap, filterMapPredicate);
}

From source file:org.jclouds.aws.binders.BindMapToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override// w  w  w  . j a  v a  2  s. c om
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    if (checkNotNull(input, "input") instanceof Iterable)
        input = Maps.uniqueIndex((Iterable<String>) input, new Function<String, String>() {
            int index = 1;

            @Override
            public String apply(String input) {
                return index++ + "";
            }
        });
    checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map");
    Map<String, String> mapping = (Map<String, String>) input;

    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    int amazonOneBasedIndex = 1; // according to docs, counters must start
                                 // with 1
    for (Entry<String, String> entry : mapping.entrySet()) {
        // not null by contract
        builder.put(format(keyPattern, amazonOneBasedIndex), entry.getKey());
        builder.put(format(valuePattern, amazonOneBasedIndex), entry.getValue());
        amazonOneBasedIndex++;
    }
    Multimap<String, String> forms = Multimaps.forMap(builder.build());
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.binders.BindTableToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override//from   w ww  .  j  a v  a 2  s.c o  m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    if (checkNotNull(input, "input") instanceof Map) {
        Builder<Object, Object, Object> builder = ImmutableTable.builder();
        int index = 1;
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) input).entrySet())
            builder.put(index++, entry.getKey(), entry.getValue());
        input = builder.build();
    }
    checkArgument(checkNotNull(input, "input") instanceof Table, "this binder is only valid for Table");
    Table<?, ?, ?> table = Table.class.cast(input);

    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    int amazonOneBasedIndex = 1; // according to docs, counters must start
                                 // with 1
    for (Cell<?, ?, ?> cell : table.cellSet()) {
        // not null by contract
        builder.put(format(rowPattern, amazonOneBasedIndex), cell.getRowKey().toString());
        builder.put(format(columnPattern, amazonOneBasedIndex), cell.getColumnKey().toString());
        builder.put(format(valuePattern, amazonOneBasedIndex), cell.getValue().toString());

        amazonOneBasedIndex++;
    }
    Multimap<String, String> forms = Multimaps.forMap(builder.build());
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:com.matthewmitchell.peercoinj.wallet.KeyChainGroup.java

public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys,
        int sigsRequiredToSpend) throws UnreadableWalletException {
    checkArgument(sigsRequiredToSpend > 0);
    BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys);
    List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null);
    EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null;
    if (!chains.isEmpty())
        currentKeys = createCurrentKeysMap(chains);
    Multimap<DeterministicKey, DeterministicKeyChain> followingKeychains = extractFollowingKeychains(chains);
    if (sigsRequiredToSpend < 2 && followingKeychains.size() > 0)
        throw new IllegalArgumentException("Married KeyChainGroup requires multiple signatures to spend");
    return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, followingKeychains,
            sigsRequiredToSpend, null);/*from  w w  w.ja  v a 2 s  .c  om*/
}

From source file:com.matthewmitchell.peercoinj.wallet.KeyChainGroup.java

public static KeyChainGroup fromProtobufEncrypted(NetworkParameters params, List<Protos.Key> keys,
        int sigsRequiredToSpend, KeyCrypter crypter) throws UnreadableWalletException {
    checkArgument(sigsRequiredToSpend > 0);
    checkNotNull(crypter);/*from ww w  .j  av  a2  s .c  om*/
    BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufEncrypted(keys, crypter);
    List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, crypter);
    EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = null;
    if (!chains.isEmpty())
        currentKeys = createCurrentKeysMap(chains);
    Multimap<DeterministicKey, DeterministicKeyChain> followingKeychains = extractFollowingKeychains(chains);
    if (sigsRequiredToSpend < 2 && followingKeychains.size() > 0)
        throw new IllegalArgumentException("Married KeyChainGroup requires multiple signatures to spend");
    return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, followingKeychains,
            sigsRequiredToSpend, crypter);
}

From source file:org.jclouds.cloudstack.binders.BindAccountSecurityGroupPairsToIndexedQueryParams.java

@SuppressWarnings("unchecked")
@Override//from  ww  w.  j  a  va 2s  .  c  o  m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(input instanceof Multimap<?, ?>, "this binder is only valid for Multimaps!");
    Multimap<String, String> pairs = (Multimap<String, String>) checkNotNull(input, "account group pairs");
    checkArgument(pairs.size() > 0, "you must specify at least one account, group pair");

    Multimap<String, String> existingParams = queryParser().apply(request.getEndpoint().getQuery());
    Builder<String, String> map = ImmutableMultimap.<String, String>builder().putAll(existingParams);
    int i = 0;
    for (Entry<String, String> entry : pairs.entries())
        map.put(String.format("usersecuritygrouplist[%d].account", i), entry.getKey())
                .put(String.format("usersecuritygrouplist[%d].group", i++), entry.getValue());
    URI endpoint = uriBuilder(request.getEndpoint()).query(map.build()).build();
    return (R) request.toBuilder().endpoint(endpoint).build();
}

From source file:com.github.kryptohash.kryptohashj.wallet.KeyChainGroup.java

public static KeyChainGroup fromProtobufUnencrypted(NetworkParameters params, List<Protos.Key> keys,
        int sigsRequiredToSpend) throws UnreadableWalletException {
    checkArgument(sigsRequiredToSpend > 0);
    BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufUnencrypted(keys);
    List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, null);
    EnumMap<KeyChain.KeyPurpose, DeterministicEd25519Key> currentKeys = null;
    if (!chains.isEmpty())
        currentKeys = createCurrentKeysMap(chains);
    Multimap<DeterministicEd25519Key, DeterministicKeyChain> followingKeychains = extractFollowingKeychains(
            chains);//  w  w w  .  j a v  a 2s  .  c o  m
    if (sigsRequiredToSpend < 2 && followingKeychains.size() > 0)
        throw new IllegalArgumentException("Married KeyChainGroup requires multiple signatures to spend");
    return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, followingKeychains,
            sigsRequiredToSpend, null);
}

From source file:com.github.kryptohash.kryptohashj.wallet.KeyChainGroup.java

public static KeyChainGroup fromProtobufEncrypted(NetworkParameters params, List<Protos.Key> keys,
        int sigsRequiredToSpend, KeyCrypter crypter) throws UnreadableWalletException {
    checkArgument(sigsRequiredToSpend > 0);
    checkNotNull(crypter);//from www .j  a va2  s.  com
    BasicKeyChain basicKeyChain = BasicKeyChain.fromProtobufEncrypted(keys, crypter);
    List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(keys, crypter);
    EnumMap<KeyChain.KeyPurpose, DeterministicEd25519Key> currentKeys = null;
    if (!chains.isEmpty())
        currentKeys = createCurrentKeysMap(chains);
    Multimap<DeterministicEd25519Key, DeterministicKeyChain> followingKeychains = extractFollowingKeychains(
            chains);
    if (sigsRequiredToSpend < 2 && followingKeychains.size() > 0)
        throw new IllegalArgumentException("Married KeyChainGroup requires multiple signatures to spend");
    return new KeyChainGroup(params, basicKeyChain, chains, currentKeys, followingKeychains,
            sigsRequiredToSpend, crypter);
}

From source file:com.googlesource.gerrit.plugins.auditsl4j.AuditRendererToCsv.java

private Object getFormattedAuditList(Multimap<String, ?> params) {
    if (params == null || params.size() == 0) {
        return "[]";
    }/* w  w  w. j  a  v a2  s  .  c  om*/

    StringBuilder formattedOut = new StringBuilder("[");

    Set<String> paramNames = new TreeSet<>(params.keySet());

    int numParams = 0;
    for (String paramName : paramNames) {
        if (numParams++ > 0) {
            formattedOut.append(",");
        }
        formattedOut.append(paramName);
        formattedOut.append("=");
        formattedOut.append(getFormattedAudit(params.get(paramName)));
    }

    formattedOut.append(']');

    return formattedOut.toString();
}