Example usage for com.google.common.collect ImmutableMultimap.Builder put

List of usage examples for com.google.common.collect ImmutableMultimap.Builder put

Introduction

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

Prototype

@Deprecated
@Override
public boolean put(K key, V value) 

Source Link

Document

Guaranteed to throw an exception and leave the multimap unmodified.

Usage

From source file:com.outerspacecat.icalendar.Component.java

/**
 * Returns the sub-components of this component excluding those whose name is
 * specified in {@code names}./* www.j a v a  2s. c  o m*/
 * 
 * @param names the names of the sub-components to exclude. Must be non
 *        {@code null}.
 * @return the sub-components of this component excluding those whose name is
 *         specified in {@code names}. Never {@code null}, contains zero or
 *         more entries.
 */
public ImmutableMultimap<String, Component> getComponentsExcept(final Set<String> names) {
    Preconditions.checkNotNull(names, "names required");

    ImmutableMultimap.Builder<String, Component> ret = ImmutableMultimap.builder();

    for (Component comp : getComponents().values()) {
        if (!names.contains(comp.getName()))
            ret.put(comp.getName(), comp);
    }

    return ret.build();
}

From source file:io.prestosql.execution.MockRemoteTaskFactory.java

public MockRemoteTask createTableScanTask(TaskId taskId, Node newNode, List<Split> splits,
        PartitionedSplitCountTracker partitionedSplitCountTracker) {
    Symbol symbol = new Symbol("column");
    PlanNodeId sourceId = new PlanNodeId("sourceId");
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId("test"),
            new TableScanNode(sourceId, new TableHandle(new ConnectorId("test"), new TestingTableHandle()),
                    ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column"))),
            ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(sourceId),
            new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()),
                    ImmutableList.of(symbol)),
            ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());

    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    for (Split sourceSplit : splits) {
        initialSplits.put(sourceId, sourceSplit);
    }//from ww  w. j  a v  a  2  s.  co  m
    return createRemoteTask(TEST_SESSION, taskId, newNode, testFragment, initialSplits.build(),
            OptionalInt.empty(), createInitialEmptyOutputBuffers(BROADCAST), partitionedSplitCountTracker,
            true);
}

From source file:com.outerspacecat.icalendar.Component.java

/**
 * Returns the properties of this component excluding those whose name is
 * specified in {@code names}./* www  .j a  v  a 2  s.c om*/
 * 
 * @param names the names of the properties to exclude. Must be non
 *        {@code null}.
 * @return the properties of this component excluding those whose name is
 *         specified in {@code names}. Never {@code null}, contains zero or
 *         more entries.
 */
public ImmutableMultimap<String, Property> getPropertiesExcept(final Set<String> names) {
    Preconditions.checkNotNull(names, "names required");

    ImmutableMultimap.Builder<String, Property> ret = ImmutableMultimap.builder();

    for (Property prop : getProperties().values()) {
        if (!names.contains(prop.getName().getName()))
            ret.put(prop.getName().getName(), prop);
    }

    return ret.build();
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.BaseImmutableMultimapJsonDeserializer.java

/**
 * Build the {@link ImmutableMultimap} using the given builder.
 *
 * @param reader {@link JsonReader} used to read the JSON input
 * @param ctx Context for the full deserialization process
 * @param params Parameters for this deserialization
 * @param builder {@link ImmutableMultimap.Builder} used to collect the entries
 *///from   w w  w. ja  v a2s  .c om
protected void buildMultimap(JsonReader reader, JsonDeserializationContext ctx,
        JsonDeserializerParameters params, ImmutableMultimap.Builder<K, V> builder) {
    reader.beginObject();
    while (JsonToken.END_OBJECT != reader.peek()) {
        String name = reader.nextName();
        K key = keyDeserializer.deserialize(name, ctx);
        reader.beginArray();
        while (JsonToken.END_ARRAY != reader.peek()) {
            V value = valueDeserializer.deserialize(reader, ctx, params);
            builder.put(key, value);
        }
        reader.endArray();
    }
    reader.endObject();
}

From source file:com.github.fge.jsonschema.keyword.validator.common.DependenciesValidator.java

public DependenciesValidator(final JsonNode digest) {
    super("dependencies");

    /*/*from  w  ww.  j  a va  2 s  .c om*/
     * Property dependencies
     */
    final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder();
    final Map<String, JsonNode> map = JacksonUtils.asMap(digest.get("propertyDeps"));

    String key;
    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        key = entry.getKey();
        for (final JsonNode element : entry.getValue())
            mapBuilder.put(key, element.textValue());
    }

    propertyDeps = mapBuilder.build();

    /*
     * Schema dependencies
     */
    final ImmutableSet.Builder<String> setBuilder = ImmutableSet.builder();

    for (final JsonNode node : digest.get("schemaDeps"))
        setBuilder.add(node.textValue());

    schemaDeps = setBuilder.build();
}

From source file:com.ning.arecibo.dashboard.resources.HostsStore.java

private void start() {
    service.scheduleWithFixedDelay(new Runnable() {
        @Override//w  w w.ja v a2 s  .c  o m
        public void run() {
            final ImmutableMultimap.Builder<String, Map<String, String>> builder = new ImmutableMultimap.Builder<String, Map<String, String>>();
            final Iterable<String> hosts = client.getHosts();

            for (final String hostName : hosts) {
                final String coreType = Strings.nullToEmpty(galaxyStatusManager.getCoreType(hostName));
                builder.put(coreType, ImmutableMap.<String, String>of("hostName", hostName, "globalZone",
                        Strings.nullToEmpty(galaxyStatusManager.getGlobalZone(hostName)), "configPath",
                        Strings.nullToEmpty(galaxyStatusManager.getConfigPath(hostName)), "configSubPath",
                        Strings.nullToEmpty(galaxyStatusManager.getConfigSubPath(hostName)), "coreType",
                        coreType));
            }

            updateCacheIfNeeded(builder.build());
        }
    }, config.getSampleKindsUpdaterDelay().getMillis(), config.getSampleKindsUpdaterDelay().getMillis(),
            TimeUnit.MILLISECONDS);
    // We give an initial delay for the Galaxy manager to query the Gonsole first

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            service.shutdownNow();
        }
    });
}

From source file:org.jclouds.gogrid.binders.BindRealIpPortPairsToQueryParams.java

@SuppressWarnings({ "unchecked" })
@Override/*from  w w  w.  j a  v  a 2s  .co m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input is null") instanceof List,
            "this binder is only valid for a List argument");

    List<IpPortPair> ipPortPairs = (List<IpPortPair>) input;
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.<String, String>builder();

    int i = 0;
    for (IpPortPair ipPortPair : ipPortPairs) {
        checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
        checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
        checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");

        builder.put(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp());
        builder.put(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair.getPort()));
        i++;
    }
    return (R) request.toBuilder().replaceQueryParams(builder.build()).build();
}

From source file:org.apache.beam.runners.flink.translation.functions.FlinkBatchSideInputHandlerFactory.java

private <T, W extends BoundedWindow> SideInputHandler<T, W> forIterableSideInput(
        List<WindowedValue<T>> broadcastVariable, Coder<T> elementCoder, Coder<W> windowCoder) {
    ImmutableMultimap.Builder<Object, T> windowToValuesBuilder = ImmutableMultimap.builder();
    for (WindowedValue<T> windowedValue : broadcastVariable) {
        for (BoundedWindow boundedWindow : windowedValue.getWindows()) {
            @SuppressWarnings("unchecked")
            W window = (W) boundedWindow;
            windowToValuesBuilder.put(windowCoder.structuralValue(window), windowedValue.getValue());
        }//from  w w  w .  j av a  2s.c o  m
    }
    ImmutableMultimap<Object, T> windowToValues = windowToValuesBuilder.build();

    return new SideInputHandler<T, W>() {
        @Override
        public Iterable<T> get(byte[] key, W window) {
            return windowToValues.get(windowCoder.structuralValue(window));
        }

        @Override
        public Coder<T> resultCoder() {
            return elementCoder;
        }
    };
}

From source file:com.outerspacecat.icalendar.Component.java

/**
 * Creates a new component.//from w  ww  .j  a  v a  2 s  . c o  m
 * 
 * @param name the component name. Must be non {@code null} and return
 *        {@code true} for {@link #isValidName(CharSequence)}.
 * @param properties the component properties. Must be non {@code null} and
 *        all elements must be non {@code null}.
 * @param components the component sub-components. Must be non {@code null}
 *        and all elements must be non {@code null}.
 */
public Component(final CharSequence name, final Iterable<Property> properties,
        final Iterable<Component> components) {
    Preconditions.checkNotNull(name, "name required");
    Preconditions.checkArgument(isValidName(name.toString().toUpperCase()), "invalid name: " + name);
    Preconditions.checkNotNull(properties, "properties required");
    Preconditions.checkNotNull(components, "components required");

    this.name = name.toString().toUpperCase();

    ImmutableMultimap.Builder<String, Property> propBuilder = new ImmutableMultimap.Builder<String, Property>();
    for (Property prop : properties) {
        Preconditions.checkNotNull(prop, "properties must each be non null");
        propBuilder.put(prop.getName().getName(), prop);
    }
    this.properties = propBuilder.build();

    ImmutableMultimap.Builder<String, Component> compBuilder = new ImmutableMultimap.Builder<String, Component>();
    for (Component comp : components) {
        Preconditions.checkNotNull(comp, "components must each be non null");
        compBuilder.put(comp.getName(), comp);
    }
    this.components = compBuilder.build();
}

From source file:foo.domaintest.http.HttpApiModule.java

@Provides
@Singleton//www. j a va  2 s.  c o  m
Multimap<String, String> provideParameterMap(@RequestData("queryString") String queryString,
        @RequestData("postBody") Lazy<String> lazyPostBody, @RequestData("charset") String requestCharset,
        FileItemIterator multipartIterator) {
    // Calling request.getParameter() or request.getParameterMap() etc. consumes the POST body. If
    // we got the "postpayload" param we don't want to parse the body, so use only the query params.
    // Note that specifying both "payload" and "postpayload" will result in the "payload" param
    // being honored and the POST body being completely ignored.
    ImmutableMultimap.Builder<String, String> params = new ImmutableMultimap.Builder<>();
    Multimap<String, String> getParams = parseQuery(queryString);
    params.putAll(getParams);
    if (getParams.containsKey("postpayload")) {
        // Treat the POST body as if it was the "payload" param.
        return params.put("payload", nullToEmpty(lazyPostBody.get())).build();
    }
    // No "postpayload" so it's safe to consume the POST body and look for params there.
    if (multipartIterator == null) { // Handle GETs and form-urlencoded POST requests.
        params.putAll(parseQuery(nullToEmpty(lazyPostBody.get())));
    } else { // Handle multipart/form-data requests.
        try {
            while (multipartIterator != null && multipartIterator.hasNext()) {
                FileItemStream item = multipartIterator.next();
                try (InputStream stream = item.openStream()) {
                    params.put(item.isFormField() ? item.getFieldName() : item.getName(),
                            CharStreams.toString(new InputStreamReader(stream, requestCharset)));
                }
            }
        } catch (FileUploadException | IOException e) {
            // Ignore the failure and fall through to return whatever params we managed to parse.
        }
    }
    return params.build();
}