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

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

Introduction

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

Prototype

int size

To view the source code for com.google.common.collect ImmutableMultimap size.

Click Source Link

Usage

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexStringArrayToFormValuesWithPrefix(R request, String prefix,
        Object input) {//from w  ww .  j  ava  2 s  .  co m
    checkArgument(checkNotNull(input, "input") instanceof String[],
            "this binder is only valid for String[] : " + input.getClass());
    String[] values = (String[]) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    for (int i = 0; i < values.length; i++) {
        builder.put(prefix + "." + (i + 1), checkNotNull(values[i], prefix.toLowerCase() + "s[" + i + "]"));
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexStringArrayToFormValuesWithStringFormat(R request, String format,
        Object input) {/*w  w  w  . ja  va 2  s  . c  om*/
    checkArgument(checkNotNull(input, "input") instanceof String[],
            "this binder is only valid for String[] : " + input.getClass());
    String[] values = (String[]) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    for (int i = 0; i < values.length; i++) {
        builder.put(String.format(format, i + 1),
                checkNotNull(values[i], format.toLowerCase() + "s[" + i + "]"));
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexIterableToFormValuesWithPrefix(R request, String prefix,
        Object input) {/*from  www . ja v a  2  s. com*/
    checkArgument(checkNotNull(input, "input") instanceof Iterable<?>,
            "this binder is only valid for Iterable<?>: " + input.getClass());
    Iterable<?> values = (Iterable<?>) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 0;
    for (Object o : values) {
        builder.put(prefix + "." + (i++ + 1),
                checkNotNull(o.toString(), prefix.toLowerCase() + "s[" + i + "]"));
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexMapToFormValuesWithPrefix(R request, String prefix,
        String keySuffix, String valueSuffix, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Map<?, ?>,
            "this binder is only valid for Map<?,?>: " + input.getClass());
    Map<?, ?> map = (Map<?, ?>) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 1;//from ww  w  .j  a  v  a 2 s  .c  om
    for (Map.Entry<?, ?> e : map.entrySet()) {
        builder.put(prefix + "." + i + "." + keySuffix,
                checkNotNull(e.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
        if (e.getValue() != null) {
            builder.put(prefix + "." + i + "." + valueSuffix, e.getValue().toString());
        }
        i++;
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexMultimapToFormValuesWithPrefix(R request, String prefix,
        String keySuffix, String valueSuffix, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Multimap<?, ?>,
            "this binder is only valid for Multimap<?,?>: " + input.getClass());
    Multimap<Object, Object> map = (Multimap<Object, Object>) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 1;/*ww  w.ja  va 2s .c  o m*/
    for (Map.Entry<Object, Collection<Object>> entry : map.asMap().entrySet()) {
        builder.put(prefix + "." + i + "." + keySuffix,
                checkNotNull(entry.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
        int j = 1;
        for (Object v : entry.getValue()) {
            builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
            j++;
        }
        i++;
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.aws.util.AWSUtils.java

public static <R extends HttpRequest> R indexMapOfIterableToFormValuesWithPrefix(R request, String prefix,
        String keySuffix, String valueSuffix, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Map<?, ?>,
            "this binder is only valid for Map<?,Iterable<?>>: " + input.getClass());
    Map<Object, Iterable<Object>> map = (Map<Object, Iterable<Object>>) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 1;/*from w w w.j  a va2 s  .  co m*/
    for (Map.Entry<Object, Iterable<Object>> entry : map.entrySet()) {
        builder.put(prefix + "." + i + "." + keySuffix,
                checkNotNull(entry.getKey().toString(), keySuffix.toLowerCase() + "s[" + i + "]"));
        Iterable<Object> iterable = entry.getValue();
        if (!Iterables.isEmpty(iterable)) {
            int j = 1;
            for (Object v : iterable) {
                builder.put(prefix + "." + i + "." + valueSuffix + "." + j, v.toString());
                j++;
            }
        }
        i++;
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.ec2.binders.BindIpPermissionsToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override//from  w w  w .  j av  a 2 s.  c om
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Iterable,
            "this binder is only valid for Iterable<IpPermission>");
    Builder<String, String> formBuilder = ImmutableMultimap.builder();
    int index = 0;
    for (IpPermission perm : (Iterable<IpPermission>) input)
        formBuilder.putAll(IpPermissions.buildFormParametersForIndex(index++, perm));
    ImmutableMultimap<String, String> forms = formBuilder.build();
    return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build();
}

From source file:org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override/* w  ww .  j a  va 2s.c o  m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    Iterable<?> values = Iterable.class.cast(checkNotNull(input, "attributeNames"));
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 0;
    for (Object o : values) {
        builder.put("AttributeName." + (i++ + 1), o.toString());
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return (R) (forms.size() == 0 ? request : request.toBuilder().replaceFormParams(forms).build());
}

From source file:org.jclouds.elb.binders.BindInstanceIdsToIndexedFormParams.java

@SuppressWarnings("unchecked")
@Override//  w  ww.j a  v  a  2 s.c o m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    Iterable<?> values = Iterable.class.cast(checkNotNull(input, "instanceIds"));
    Builder<String, String> builder = ImmutableMultimap.builder();
    int i = 0;
    for (Object o : values) {
        builder.put("Instances.member." + (i++ + 1) + ".InstanceId", o.toString());
    }
    ImmutableMultimap<String, String> forms = builder.build();
    return (R) (forms.size() == 0 ? request : request.toBuilder().replaceFormParams(forms).build());
}

From source file:org.jclouds.simpledb.binders.BindAttributesToIndexedFormParams.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Item, "this binder is only valid for AttributeMap");
    Item attributeMap = (Item) input;/*w w  w .java2s. com*/

    Builder<String, String> builder = ImmutableMultimap.builder();
    int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
    for (String itemName : attributeMap.getAttributes().keySet()) {

        Collection<AttributePair> c = attributeMap.getAttributes().get(itemName);
        Iterator<AttributePair> it = c.iterator();
        while (it.hasNext()) {
            AttributePair attr = it.next();
            // not null by contract

            String value = attr.getValue();

            if (value != null) {
                builder.put(format(attributeName, amazonOneBasedIndex), attr.getKey());
                builder.put(format(attributeValue, amazonOneBasedIndex), value);
                builder.put(format(attributeReplace, amazonOneBasedIndex), String.valueOf(attr.isReplace()));

            }
            amazonOneBasedIndex++;
        }

    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
}