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:org.jdbi.v3.guava.GuavaCollectors.java

/**
 * Returns a {@code Collector} that accumulates {@code Map.Entry<K, V>} input elements into an
 * {@code ImmutableListMultimap<K, V>}.
 *
 * @param <K> the type of map keys
 * @param <V> the type of map values
 * @return a {@code Collector} which collects map entry elements into an {@code ImmutableListMultimap},
 * in encounter order.// w ww .java  2s .  c  om
 */
public static <K, V> Collector<Map.Entry<K, V>, ?, ImmutableListMultimap<K, V>> toImmutableListMultimap() {
    return Collector.of(ImmutableListMultimap::<K, V>builder, ImmutableListMultimap.Builder::put,
            GuavaCollectors::combine, ImmutableListMultimap.Builder::build);
}

From source file:org.immutables.sequence.Entries.java

public ImmutableListMultimap<K, V> toMultimap() {
    ImmutableListMultimap.Builder<K, V> builder = ImmutableListMultimap.builder();
    forEach(e -> builder.put(e));
    return builder.build();
}

From source file:com.opengamma.strata.loader.csv.RatesCurvesCsvLoader.java

/**
 * Parses one or more CSV format curve files for all available dates.
 * <p>//  w w  w  .j  a v  a 2 s. c  om
 * A predicate is specified that is used to filter the dates that are returned.
 * This could match a single date, a set of dates or all dates.
 * <p>
 * If the files contain a duplicate entry an exception will be thrown.
 *
 * @param datePredicate  the predicate used to select the dates
 * @param groupsCharSource  the curve groups CSV character source
 * @param settingsCharSource  the curve settings CSV character source
 * @param curveValueCharSources  the CSV character sources for curves
 * @return the loaded curves, mapped by date and identifier
 * @throws IllegalArgumentException if the files contain a duplicate entry
 */
public static ImmutableListMultimap<LocalDate, CurveGroup> parse(Predicate<LocalDate> datePredicate,
        CharSource groupsCharSource, CharSource settingsCharSource,
        Collection<CharSource> curveValueCharSources) {

    List<CurveGroupDefinition> curveGroups = CurveGroupDefinitionCsvLoader
            .parseCurveGroupDefinitions(groupsCharSource);
    Map<LocalDate, Map<CurveName, Curve>> curves = parseCurves(datePredicate, settingsCharSource,
            curveValueCharSources);
    ImmutableListMultimap.Builder<LocalDate, CurveGroup> builder = ImmutableListMultimap.builder();

    for (CurveGroupDefinition groupDefinition : curveGroups) {
        for (Map.Entry<LocalDate, Map<CurveName, Curve>> entry : curves.entrySet()) {
            CurveGroup curveGroup = CurveGroup.ofCurves(groupDefinition, entry.getValue().values());
            builder.put(entry.getKey(), curveGroup);
        }
    }
    return builder.build();
}

From source file:com.opengamma.strata.loader.csv.LegalEntityRatesCurvesCsvLoader.java

/**
 * Parses one or more CSV format curve files for all available dates.
 * <p>/*  w ww.j  a  v  a 2 s .  c o m*/
 * A predicate is specified that is used to filter the dates that are returned.
 * This could match a single date, a set of dates or all dates.
 * <p>
 * If the files contain a duplicate entry an exception will be thrown.
 *
 * @param datePredicate  the predicate used to select the dates
 * @param groupsCharSource  the curve groups CSV character source
 * @param settingsCharSource  the curve settings CSV character source
 * @param curveValueCharSources  the CSV character sources for curves
 * @return the loaded curves, mapped by date and identifier
 * @throws IllegalArgumentException if the files contain a duplicate entry
 */
public static ImmutableListMultimap<LocalDate, LegalEntityCurveGroup> parse(Predicate<LocalDate> datePredicate,
        CharSource groupsCharSource, CharSource settingsCharSource,
        Collection<CharSource> curveValueCharSources) {

    Map<CurveGroupName, Map<Pair<RepoGroup, Currency>, CurveName>> repoGroups = new LinkedHashMap<>();
    Map<CurveGroupName, Map<Pair<LegalEntityGroup, Currency>, CurveName>> legalEntityGroups = new LinkedHashMap<>();
    parseCurveMaps(groupsCharSource, repoGroups, legalEntityGroups);
    Map<LocalDate, Map<CurveName, Curve>> allCurves = parseCurves(datePredicate, settingsCharSource,
            curveValueCharSources);
    ImmutableListMultimap.Builder<LocalDate, LegalEntityCurveGroup> builder = ImmutableListMultimap.builder();

    for (Map.Entry<LocalDate, Map<CurveName, Curve>> curveEntry : allCurves.entrySet()) {
        LocalDate date = curveEntry.getKey();
        Map<CurveName, Curve> curves = curveEntry.getValue();
        for (Map.Entry<CurveGroupName, Map<Pair<RepoGroup, Currency>, CurveName>> repoEntry : repoGroups
                .entrySet()) {
            CurveGroupName groupName = repoEntry.getKey();
            Map<Pair<RepoGroup, Currency>, Curve> repoCurves = MapStream.of(repoEntry.getValue())
                    .mapValues(name -> queryCurve(name, curves, date, groupName, "Repo")).toMap();
            Map<Pair<LegalEntityGroup, Currency>, Curve> issuerCurves = MapStream
                    .of(legalEntityGroups.get(groupName))
                    .mapValues(name -> queryCurve(name, curves, date, groupName, "Issuer")).toMap();
            builder.put(date, LegalEntityCurveGroup.of(groupName, repoCurves, issuerCurves));
        }
    }
    return builder.build();
}

From source file:org.rakam.presto.stream.metadata.StreamMetadata.java

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session,
        SchemaTablePrefix prefix) {//  w w  w  .ja v a  2s .  co  m
    checkNotNull(prefix, "prefix is null");

    ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder();
    for (TableColumn tableColumn : dao.listTableColumns(connectorId, prefix.getSchemaName(),
            prefix.getTableName())) {
        ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(),
                tableColumn.getDataType(), tableColumn.getOrdinalPosition(), false);
        columns.put(tableColumn.getTable(), columnMetadata);
    }
    return Multimaps.asMap(columns.build());
}

From source file:co.paralleluniverse.comsat.webactors.netty.NettyHttpRequest.java

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

From source file:com.google.devtools.build.lib.rules.cpp.CppToolchainInfo.java

/** Creates a CppToolchainInfo from a toolchain. */
public CppToolchainInfo(CToolchain cToolchain, PathFragment crosstoolTopPathFragment, Label toolchainLabel)
        throws InvalidConfigurationException {
    CToolchain toolchain = cToolchain;/*  w w w .  j  a v a2  s . c  o  m*/
    this.crosstoolTopPathFragment = crosstoolTopPathFragment;
    this.hostSystemName = toolchain.getHostSystemName();
    this.compiler = toolchain.getCompiler();
    this.targetCpu = toolchain.getTargetCpu();
    this.targetSystemName = toolchain.getTargetSystemName();
    this.targetLibc = toolchain.getTargetLibc();
    this.targetOS = toolchain.getCcTargetOs();

    try {
        this.staticRuntimeLibsLabel = toolchainLabel
                .getRelative(toolchain.hasStaticRuntimesFilegroup() ? toolchain.getStaticRuntimesFilegroup()
                        : "static-runtime-libs-" + targetCpu);
        this.dynamicRuntimeLibsLabel = toolchainLabel
                .getRelative(toolchain.hasDynamicRuntimesFilegroup() ? toolchain.getDynamicRuntimesFilegroup()
                        : "dynamic-runtime-libs-" + targetCpu);
    } catch (LabelSyntaxException e) {
        // All of the above label.getRelative() calls are valid labels, and the crosstool_top
        // was already checked earlier in the process.
        throw new AssertionError(e);
    }

    // Needs to be set before the first call to isLLVMCompiler().
    this.toolchainIdentifier = toolchain.getToolchainIdentifier();

    CrosstoolConfigurationIdentifier crosstoolConfig = CrosstoolConfigurationIdentifier
            .fromToolchain(toolchain);
    Preconditions.checkState(crosstoolConfig.getCpu().equals(targetCpu));
    Preconditions.checkState(crosstoolConfig.getCompiler().equals(compiler));
    Preconditions.checkState(crosstoolConfig.getLibc().equals(targetLibc));

    this.solibDirectory = "_solib_" + targetCpu;

    this.supportsEmbeddedRuntimes = toolchain.getSupportsEmbeddedRuntimes();
    toolchain = addLegacyFeatures(toolchain);
    this.toolchainFeatures = new CcToolchainFeatures(toolchain);
    this.supportsGoldLinker = toolchain.getSupportsGoldLinker();
    this.supportsStartEndLib = toolchain.getSupportsStartEndLib();
    this.supportsInterfaceSharedObjects = toolchain.getSupportsInterfaceSharedObjects();
    this.supportsFission = toolchain.getSupportsFission();

    Map<String, PathFragment> toolPathsCollector = Maps.newHashMap();
    for (CrosstoolConfig.ToolPath tool : toolchain.getToolPathList()) {
        PathFragment path = PathFragment.create(tool.getPath());
        if (!path.isNormalized()) {
            throw new IllegalArgumentException("The include path '" + tool.getPath() + "' is not normalized.");
        }
        toolPathsCollector.put(tool.getName(), crosstoolTopPathFragment.getRelative(path));
    }

    if (toolPathsCollector.isEmpty()) {
        // If no paths are specified, we just use the names of the tools as the path.
        for (Tool tool : Tool.values()) {
            toolPathsCollector.put(tool.getNamePart(),
                    crosstoolTopPathFragment.getRelative(tool.getNamePart()));
        }
    } else {
        Iterable<Tool> neededTools = Iterables.filter(EnumSet.allOf(Tool.class), tool -> {
            if (tool == Tool.DWP) {
                // When fission is unsupported, don't check for the dwp tool.
                return supportsFission();
            } else if (tool == Tool.LLVM_PROFDATA) {
                // TODO(tmsriram): Fix this to check if this is a llvm crosstool
                // and return true.  This needs changes to crosstool_config.proto.
                return false;
            } else if (tool == Tool.GCOVTOOL || tool == Tool.OBJCOPY) {
                // gcov-tool and objcopy are optional, don't check whether they're present
                return false;
            } else {
                return true;
            }
        });
        for (Tool tool : neededTools) {
            if (!toolPathsCollector.containsKey(tool.getNamePart())) {
                throw new IllegalArgumentException("Tool path for '" + tool.getNamePart() + "' is missing");
            }
        }
    }
    this.toolPaths = ImmutableMap.copyOf(toolPathsCollector);

    ImmutableListMultimap.Builder<CompilationMode, String> linkOptionsFromCompilationModeBuilder = ImmutableListMultimap
            .builder();
    for (CrosstoolConfig.CompilationModeFlags flags : toolchain.getCompilationModeFlagsList()) {
        // Remove this when CROSSTOOL files no longer contain 'coverage'.
        if (flags.getMode() == CrosstoolConfig.CompilationMode.COVERAGE) {
            continue;
        }
        CompilationMode realmode = CppConfiguration.importCompilationMode(flags.getMode());
        linkOptionsFromCompilationModeBuilder.putAll(realmode, flags.getLinkerFlagList());
    }
    linkOptionsFromCompilationMode = linkOptionsFromCompilationModeBuilder.build();

    ImmutableListMultimap.Builder<LipoMode, String> linkOptionsFromLipoModeBuilder = ImmutableListMultimap
            .builder();
    for (CrosstoolConfig.LipoModeFlags flags : toolchain.getLipoModeFlagsList()) {
        LipoMode realmode = flags.getMode();
        linkOptionsFromLipoModeBuilder.putAll(realmode, flags.getLinkerFlagList());
    }
    linkOptionsFromLipoMode = linkOptionsFromLipoModeBuilder.build();

    ImmutableListMultimap.Builder<LinkingMode, String> linkOptionsFromLinkingModeBuilder = ImmutableListMultimap
            .builder();

    // If a toolchain supports dynamic libraries at all, there must be at least one
    // of the following:
    // - a "DYNAMIC" section in linking_mode_flags (even if no flags are needed)
    // - a non-empty list in one of the dynamicLibraryLinkerFlag fields
    // If none of the above contain data, then the toolchain can't do dynamic linking.
    boolean haveDynamicMode = false;

    for (LinkingModeFlags flags : toolchain.getLinkingModeFlagsList()) {
        LinkingMode realmode = CppConfiguration.importLinkingMode(flags.getMode());
        if (realmode == LinkingMode.DYNAMIC) {
            haveDynamicMode = true;
        }
        linkOptionsFromLinkingModeBuilder.putAll(realmode, flags.getLinkerFlagList());
    }
    linkOptionsFromLinkingMode = linkOptionsFromLinkingModeBuilder.build();

    this.commonLinkOptions = ImmutableList.copyOf(toolchain.getLinkerFlagList());
    List<String> linkerFlagList = toolchain.getDynamicLibraryLinkerFlagList();
    List<CToolchain.OptionalFlag> optionalLinkerFlagList = toolchain.getOptionalDynamicLibraryLinkerFlagList();
    if (!linkerFlagList.isEmpty() || !optionalLinkerFlagList.isEmpty()) {
        haveDynamicMode = true;
    }
    this.supportsDynamicLinker = haveDynamicMode;
    dynamicLibraryLinkFlags = new FlagList(ImmutableList.copyOf(linkerFlagList),
            CppConfiguration.convertOptionalOptions(optionalLinkerFlagList), ImmutableList.<String>of());

    this.objcopyOptions = ImmutableList.copyOf(toolchain.getObjcopyEmbedFlagList());
    this.ldOptions = ImmutableList.copyOf(toolchain.getLdEmbedFlagList());

    this.abi = toolchain.getAbiVersion();
    this.abiGlibcVersion = toolchain.getAbiLibcVersion();

    this.defaultSysroot = CppConfiguration.computeDefaultSysroot(toolchain);

    this.rawBuiltInIncludeDirectories = ImmutableList.copyOf(toolchain.getCxxBuiltinIncludeDirectoryList());

    // The default value for optional string attributes is the empty string.

    // The runtime sysroot should really be set from --grte_top. However, currently libc has no
    // way to set the sysroot. The CROSSTOOL file does set the runtime sysroot, in the
    // builtin_sysroot field. This implies that you can not arbitrarily mix and match Crosstool
    // and libc versions, you must always choose compatible ones.
    runtimeSysroot = defaultSysroot;

    this.testOnlyLinkFlags = ImmutableList.copyOf(toolchain.getTestOnlyLinkerFlagList());
    this.toolchainNeedsPic = toolchain.getNeedsPic();

    Map<String, String> makeVariablesBuilder = new HashMap<>();
    // The following are to be used to allow some build rules to avoid the limits on stack frame
    // sizes and variable-length arrays. Ensure that these are always set.
    makeVariablesBuilder.put("STACK_FRAME_UNLIMITED", "");
    makeVariablesBuilder.put(CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME, "");
    for (CrosstoolConfig.MakeVariable variable : toolchain.getMakeVariableList()) {
        makeVariablesBuilder.put(variable.getName(), variable.getValue());
    }
    this.additionalMakeVariables = ImmutableMap.copyOf(makeVariablesBuilder);

    this.ldExecutable = getToolPathFragment(CppConfiguration.Tool.LD);
}

From source file:com.google.caliper.util.ShortDuration.java

private static ImmutableListMultimap<TimeUnit, String> createAbbreviations() {
    ImmutableListMultimap.Builder<TimeUnit, String> builder = ImmutableListMultimap.builder();
    builder.putAll(TimeUnit.NANOSECONDS, "ns", "nanos");
    builder.putAll(TimeUnit.MICROSECONDS, "\u03bcs" /*s*/, "us", "micros");
    builder.putAll(TimeUnit.MILLISECONDS, "ms", "millis");
    builder.putAll(TimeUnit.SECONDS, "s", "sec");

    // Do the rest in a JDK5-safe way
    TimeUnit[] allUnits = TimeUnit.values();
    if (allUnits.length >= 7) {
        builder.putAll(allUnits[4], "m", "min");
        builder.putAll(allUnits[5], "h", "hr");
        builder.putAll(allUnits[6], "d");
    }//  w  ww  .  ja v a  2 s . co m

    for (TimeUnit unit : TimeUnit.values()) {
        builder.put(unit, Ascii.toLowerCase(unit.name()));
    }
    return builder.build();
}

From source file:org.wso2.carbon.uuf.api.config.Configuration.java

/**
 * Sets menus for the app./*from  w  w  w .ja  v a2 s .  c  o  m*/
 *
 * @param menus menus to be set
 * @see #getMenu(String)
 */
public void setMenus(List<? extends Menu> menus) {
    ImmutableListMultimap.Builder<String, MenuItem> builder = new ImmutableListMultimap.Builder<>();
    menus.forEach(menu -> builder.putAll(menu.getName(), menu.getItems()));
    this.menus = builder.build();
}

From source file:com.facebook.presto.raptor.RaptorMetadata.java

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session,
        SchemaTablePrefix prefix) {//from w ww  .  jav  a 2s .c  o  m
    requireNonNull(prefix, "prefix is null");

    ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder();
    for (TableColumn tableColumn : dao.listTableColumns(prefix.getSchemaName(), prefix.getTableName())) {
        if (tableColumn.getColumnName().equals(SAMPLE_WEIGHT_COLUMN_NAME)) {
            continue;
        }
        ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(),
                tableColumn.getDataType(), false);
        columns.put(tableColumn.getTable(), columnMetadata);
    }
    return Multimaps.asMap(columns.build());
}