Example usage for com.google.common.collect ImmutableListMultimap builder

List of usage examples for com.google.common.collect ImmutableListMultimap builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableListMultimap builder.

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Document

Returns a new builder.

Usage

From source file:co.paralleluniverse.comsat.webactors.undertow.HttpRequestWrapper.java

static ImmutableListMultimap<String, String> extractHeaders(HeaderMap headers) {
    if (headers != null) {
        final ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
        for (final HttpString n : headers.getHeaderNames())
            builder.putAll(n.toString(), headers.get(n));
        return builder.build();
    }/*from  w w w .  j  a  v  a  2 s  . c o m*/
    return null;
}

From source file:org.dcache.nfs.ExportFile.java

private static ImmutableMultimap<Integer, FsExport> parse(URI exportFile) throws IOException {

    ImmutableListMultimap.Builder<Integer, FsExport> exportsBuilder = ImmutableListMultimap.builder();

    for (String line : Files.readAllLines(Paths.get(exportFile))) {

        line = line.trim();//from w ww .  j  a  v a2  s. c o  m
        if (line.length() == 0) {
            continue;
        }

        if (line.charAt(0) == '#') {
            continue;
        }

        if (line.charAt(0) != '/') {
            _log.warn("Ignoring entry with non absolute export path: " + line);
            continue;
        }

        int pathEnd = line.indexOf(' ');

        String path;
        if (pathEnd < 0) {
            FsExport export = new FsExport.FsExportBuilder().build(line);
            exportsBuilder.put(export.getIndex(), export);
            continue;
        } else {
            path = line.substring(0, pathEnd);
        }

        Splitter splitter = Splitter.on(' ').omitEmptyStrings().trimResults();

        for (String hostAndOptions : splitter.split(line.substring(pathEnd + 1))) {

            try {
                FsExport.FsExportBuilder exportBuilder = new FsExport.FsExportBuilder();

                Iterator<String> s = Splitter.on(CharMatcher.anyOf("(,)")).omitEmptyStrings().trimResults()
                        .split(hostAndOptions).iterator();

                String host = s.next();

                exportBuilder.forClient(host);
                while (s.hasNext()) {
                    String option = s.next();

                    if (option.equals("rw")) {
                        exportBuilder.rw();
                        continue;
                    }

                    if (option.equals("ro")) {
                        exportBuilder.ro();
                        continue;
                    }

                    if (option.equals("root_squash")) {
                        exportBuilder.notTrusted();
                        continue;
                    }

                    if (option.equals("no_root_squash")) {
                        exportBuilder.trusted();
                        continue;
                    }

                    if (option.equals("acl")) {
                        exportBuilder.withAcl();
                        continue;
                    }

                    if (option.equals("noacl") || option.equals("no_acl")) {
                        exportBuilder.withoutAcl();
                        continue;
                    }

                    if (option.equals("all_squash")) {
                        exportBuilder.allSquash();
                        continue;
                    }

                    if (option.startsWith("sec=")) {
                        String secFlavor = option.substring(4);
                        exportBuilder.withSec(FsExport.Sec.valueOf(secFlavor.toUpperCase()));
                        continue;
                    }

                    if (option.startsWith("anonuid=")) {
                        int anonuid = Integer.parseInt(option.substring(8));
                        exportBuilder.withAnonUid(anonuid);
                        continue;
                    }

                    if (option.startsWith("anongid=")) {
                        int anongid = Integer.parseInt(option.substring(8));
                        exportBuilder.withAnonGid(anongid);
                        continue;
                    }

                    if (option.equals("dcap")) {
                        exportBuilder.withDcap();
                        continue;
                    }

                    if (option.equals("no_dcap")) {
                        exportBuilder.withoutDcap();
                        continue;
                    }

                    if (option.equals("all_root")) {
                        exportBuilder.withAllRoot();
                        continue;
                    }

                    if (option.equals("pnfs")) {
                        exportBuilder.withPnfs();
                        continue;
                    }

                    if (option.equals("nopnfs") || option.equals("no_pnfs")) {
                        exportBuilder.withoutPnfs();
                        continue;
                    }

                    throw new IllegalArgumentException("Unsupported option: " + option);
                }
                FsExport export = exportBuilder.build(path);
                exportsBuilder.put(export.getIndex(), export);
            } catch (IllegalArgumentException e) {
                _log.error("Invalid export entry [" + hostAndOptions + "] : " + e.getMessage());
            }
        }
    }

    /*
     * sort in reverse order to get smallest network first
     */
    return exportsBuilder
            .orderValuesBy(Ordering.from(HostEntryComparator::compare).onResultOf(FsExport::client).reverse())
            .build();
}

From source file:at.ac.univie.isc.asio.engine.CommandBuilder.java

private CommandBuilder() {
    accepted = ImmutableList.builder();
    arguments = ImmutableListMultimap.builder();
}

From source file:co.paralleluniverse.comsat.webactors.undertow.UndertowHttpRequest.java

static ImmutableListMultimap<String, String> extractHeaders(HeaderMap headers) {
    if (headers != null) {
        final ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
        for (final HttpString n : headers.getHeaderNames())
            // Normalize header names by their conversion to lower case
            builder.putAll(n.toString().toLowerCase(Locale.ENGLISH), headers.get(n));
        return builder.build();
    }// ww w .jav  a2  s .  co m
    return null;
}

From source file:com.kolich.curacao.mappers.request.types.body.EncodedRequestBodyMapper.java

private static final Multimap<String, String> parse(final String body, final String encodingCharset)
        throws Exception {
    final ImmutableMultimap.Builder<String, String> result = ImmutableListMultimap.builder();
    // <https://github.com/markkolich/curacao/issues/12>
    // Only bother parsing the POST body if there's actually something there to parse.
    if (!StringUtils.isEmpty(body)) {
        final StringBuffer buffer = new StringBuffer(body);
        final Cursor cursor = new Cursor(0, buffer.length());
        while (!cursor.atEnd()) {
            final Map.Entry<String, String> entry = getNextNameValuePair(buffer, cursor);
            if (!entry.getKey().isEmpty()) {
                result.put(decode(entry.getKey(), encodingCharset), decode(entry.getValue(), encodingCharset));
            }/*ww w .j a v  a 2 s.co  m*/
        }
    }
    return result.build();
}

From source file:com.cisco.oss.foundation.http.jetty.JettyHttpResponse.java

@Override
public Map<String, Collection<String>> getHeaders() {
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();

    HttpFields headers = httpResponse.getHeaders();
    for (HttpField header : headers) {
        builder.put(header.getName(), header.getValue());
    }/*from w  ww .j a v  a  2 s  . c o  m*/
    return builder.build().asMap();
}

From source file:org.lenskit.data.entities.GenericEntityIndexBuilder.java

/**
 * Construct a new index builder.
 * @param name The attribute name to index.
 */
GenericEntityIndexBuilder(TypedName<?> name) {
    attributeName = name;
    builder = ImmutableListMultimap.builder();
}

From source file:de.metas.ui.web.window.datatypes.LookupValuesList.java

/**
 * Collects {@link LookupValue}s and builds a {@link LookupValuesList} with those values, having given <code>debugProperties</code>
 *
 * @param debugProperties optional debug properties, <code>null</code> is also OK.
 *//*from  w  ww .  j a va 2  s . c o m*/
public static final Collector<LookupValue, ?, LookupValuesList> collect(
        final Map<String, String> debugProperties) {
    final Supplier<ImmutableListMultimap.Builder<Object, LookupValue>> supplier = ImmutableListMultimap.Builder::new;
    final BiConsumer<ImmutableListMultimap.Builder<Object, LookupValue>, LookupValue> accumulator = (builder,
            item) -> builder.put(item.getId(), item);
    final BinaryOperator<ImmutableListMultimap.Builder<Object, LookupValue>> combiner = (builder1,
            builder2) -> builder1.putAll(builder2.build());
    final Function<ImmutableListMultimap.Builder<Object, LookupValue>, LookupValuesList> finisher = (
            builder) -> build(builder, debugProperties);
    return Collector.of(supplier, accumulator, combiner, finisher);
}

From source file:org.immutables.metainf.processor.Metaservices.java

ListMultimap<String, String> allMetaservices() {
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();

    for (Element element : round().getElementsAnnotatedWith(Metainf.Service.class)) {
        @Nullable/*from  ww w.  j  a  va2s .  c o  m*/
        TypeElement typeElement = validated(element);
        if (typeElement == null) {
            continue;
        }
        Set<String> interfaceNames = extractServiceInterfaceNames(typeElement);
        builder.putAll(typeElement.getQualifiedName().toString(), interfaceNames);
    }

    return builder.build();
}

From source file:org.gradle.model.internal.manage.schema.extract.ModelSchemaUtils.java

/**
 * Returns all candidate methods for schema generation declared by the given type and its super-types indexed by name.
 *
 * <p>Overriding methods are <em>not</em> folded like in the case of {@link Class#getMethods()}. This allows
 * the caller to identify annotations declared at different levels in the hierarchy, and also to identify all
 * the classes declaring a certain method.</p>
 *
 * <p>Method candidates exclude:</p>
 * <ul>/*from   w  w  w.  j a  v  a  2  s .  c  om*/
 *     <li>methods defined by {@link Object} and their overrides</li>
 *     <li>methods defined by {@link GroovyObject} and their overrides</li>
 *     <li>synthetic methods</li>
 * </ul>
 *
 * <p>Methods are returned in the order of their specialization, most specialized methods first.</p>
 */
public static <T> ListMultimap<String, Method> getCandidateMethods(Class<T> clazz) {
    final ImmutableListMultimap.Builder<String, Method> methodsBuilder = ImmutableListMultimap.builder();
    walkTypeHierarchy(clazz, new TypeVisitor<T>() {
        @Override
        public void visitType(Class<? super T> type) {
            for (Method method : type.getDeclaredMethods()) {
                if (isIgnoredMethod(method)) {
                    continue;
                }

                methodsBuilder.put(method.getName(), method);
            }
        }
    });
    return methodsBuilder.build();
}