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

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

Introduction

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

Prototype

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

Source Link

Document

Returns a new builder.

Usage

From source file:edu.udo.scaffoldhunter.model.dataimport.ImportProcess.java

private ImmutableMultimap<ImportJob, Integer> getPropertiesWithUndefinedMergeStrategy() {
    ImmutableMultimap.Builder<ImportJob, Integer> builder = ImmutableMultimap.builder();
    Set<PropertyDefinition> propertyDefinitions = Sets.newHashSet();
    for (ImportJob s : importJobs) {
        int i = -1;
        for (SourcePropertyMapping m : s.getPropertyMappings().values()) {
            i++;/*ww w.j  av  a  2 s . c om*/
            PropertyDefinition propDef = m.getPropertyDefiniton();
            if (propDef == null)
                continue;
            if (propertyDefinitions.contains(propDef) && m.getMergeStrategy() == MergeStrategy.NONE)
                builder.put(s, i);
            else
                propertyDefinitions.add(propDef);
        }

    }
    return builder.build();
}

From source file:com.techcavern.pircbotz.UserChannelMap.java

public UserChannelMapSnapshot createSnapshot(Map<U, UserSnapshot> userSnapshots,
        Map<C, ChannelSnapshot> channelSnapshots) {
    //Create new multimaps replacing each user and channel with their respective snapshots
    ImmutableMultimap.Builder<UserSnapshot, ChannelSnapshot> userToChannelSnapshotBuilder = ImmutableMultimap
            .builder();/*from   w w w  .java  2s.  c  om*/
    for (Map.Entry<U, C> curEntry : userToChannelMap.entries()) {
        if (userSnapshots.get(curEntry.getKey()) != null && channelSnapshots.get(curEntry.getValue()) != null)
            userToChannelSnapshotBuilder.put(userSnapshots.get(curEntry.getKey()),
                    channelSnapshots.get(curEntry.getValue()));
    }
    ImmutableMultimap.Builder<ChannelSnapshot, UserSnapshot> channelToUserSnapshotBuilder = ImmutableMultimap
            .builder();
    for (Map.Entry<C, U> curEntry : channelToUserMap.entries()) {
        if (channelSnapshots.get(curEntry.getKey()) != null && userSnapshots.get(curEntry.getValue()) != null)
            channelToUserSnapshotBuilder.put(channelSnapshots.get(curEntry.getKey()),
                    userSnapshots.get(curEntry.getValue()));

    } //Return a snapshot of the map
    return new UserChannelMapSnapshot(userToChannelSnapshotBuilder.build(),
            channelToUserSnapshotBuilder.build());
}

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

/**
 * Creates a new time zone./* w  w  w.  j  ava2 s. c o  m*/
 * 
 * @param id the time zone id. Must be non {@code null}.
 * @param observances the time zone observances. Must be non {@code null}, all
 *        elements must be non {@code null}. Must contain at least one
 *        element.
 * @param extraProperties the extra properties of the time zone. Must be non
 *        {@code null}, all elements must be non {@code null}, may be empty.
 * @param extraComponents the extra components of the time zone. Must be non
 *        {@code null}, all elements must be non {@code null}, may be empty.
 */
public VTimeZone(final TypedProperty<TextType> id, final Iterable<VTimeZoneObservance> observances,
        final Iterable<Property> extraProperties, final Iterable<Component> extraComponents) {
    Preconditions.checkNotNull(id, "id required");
    Preconditions.checkNotNull(observances, "observances required");
    Preconditions.checkArgument(observances.iterator().hasNext(), "one or more observances required");
    for (VTimeZoneObservance observance : observances)
        Preconditions.checkNotNull(observance, "each observance must be non null");
    Preconditions.checkNotNull(extraProperties, "extraProperties required");
    for (Property prop : extraProperties)
        Preconditions.checkNotNull(prop, "each extra property must be non null");
    Preconditions.checkNotNull(extraComponents, "extraComponents required");
    for (Component comp : extraComponents)
        Preconditions.checkNotNull(comp, "each extra component must be non null");

    this.id = id;

    this.observances = ImmutableSet.copyOf(observances);

    ImmutableMultimap.Builder<String, Property> extraPropertiesBuilder = ImmutableMultimap.builder();
    for (Property prop : extraProperties)
        extraPropertiesBuilder.put(prop.getName().getName(), prop);
    this.extraProperties = extraPropertiesBuilder.build();

    ImmutableMultimap.Builder<String, Component> extraComponentsBuilder = ImmutableMultimap.builder();
    for (Component comp : extraComponents)
        extraComponentsBuilder.put(comp.getName(), comp);
    this.extraComponents = extraComponentsBuilder.build();
}

From source file:com.facebook.presto.execution.MockRemoteTaskFactory.java

public RemoteTask createTableScanTask(Node newNode, List<Split> splits,
        SplitCountChangeListener splitCountChangeListener) {
    TaskId taskId = new TaskId(new StageId("test", "1"), "1");
    Symbol symbol = new Symbol("column");
    PlanNodeId tableScanNodeId = new PlanNodeId("test");
    PlanNodeId sourceId = new PlanNodeId("sourceId");
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId("test"),
            new TableScanNode(new PlanNodeId("test"), new TableHandle("test", new TestingTableHandle()),
                    ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")),
                    Optional.empty(), TupleDomain.all(), null),
            ImmutableMap.<Symbol, Type>of(symbol, VARCHAR), ImmutableList.of(symbol),
            PlanFragment.PlanDistribution.SOURCE, tableScanNodeId, PlanFragment.OutputPartitioning.NONE,
            Optional.empty(), Optional.empty(), Optional.empty());

    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    for (Split sourceSplit : splits) {
        initialSplits.put(sourceId, sourceSplit);
    }//from   w  ww .ja va2  s  .co  m
    return createRemoteTask(TEST_SESSION, taskId, newNode, testFragment, initialSplits.build(),
            OutputBuffers.INITIAL_EMPTY_OUTPUT_BUFFERS, splitCountChangeListener);
}

From source file:no.ssb.jsonstat.v2.Dataset.java

/**
 * Return an {@link ImmutableMultimap} representing the roles of the dimensions.
 *
 * @see <a href="https://json-stat.org/format/#role">json-stat.org/format/#role</a>
 *///from w  ww .  jav  a 2  s.c  om
public ImmutableMultimap<Dimension.Roles, String> getRole() {
    ImmutableMultimap.Builder<Dimension.Roles, String> builder;
    builder = ImmutableMultimap.builder();

    for (Map.Entry<String, Dimension> dimensionEntry : getDimension().entrySet()) {
        Dimension.Roles role = dimensionEntry.getValue().getRole();
        if (role != null) {
            builder.put(role, dimensionEntry.getKey());
        }
    }
    return builder.build();
}

From source file:org.pircbotx.UserChannelMap.java

public UserChannelMapSnapshot createSnapshot(Map<U, UserSnapshot> userSnapshots,
        Map<C, ChannelSnapshot> channelSnapshots) {
    //Create new multimaps replacing each user and channel with their respective snapshots
    ImmutableMultimap.Builder<UserSnapshot, ChannelSnapshot> userToChannelSnapshotBuilder = ImmutableMultimap
            .builder();//from  w  ww.  j a v  a 2 s  .  c  o m
    for (Map.Entry<U, C> curEntry : userToChannelMap.entries())
        userToChannelSnapshotBuilder.put(userSnapshots.get(curEntry.getKey()),
                channelSnapshots.get(curEntry.getValue()));
    ImmutableMultimap.Builder<ChannelSnapshot, UserSnapshot> channelToUserSnapshotBuilder = ImmutableMultimap
            .builder();
    for (Map.Entry<C, U> curEntry : channelToUserMap.entries())
        channelToUserSnapshotBuilder.put(channelSnapshots.get(curEntry.getKey()),
                userSnapshots.get(curEntry.getValue()));

    //Return a snapshot of the map
    return new UserChannelMapSnapshot(userToChannelSnapshotBuilder.build(),
            channelToUserSnapshotBuilder.build());
}

From source file:com.google.template.soy.passes.FindIjParamsVisitor.java

/**
 * Computes injected params info for a template.
 *
 * <p> Note: This method is not thread-safe. If you need to get injected params info in a
 * thread-safe manner, then please use {@link #execOnAllTemplates}() in a thread-safe manner.
 *///from  www.  j  a  v  a  2s . c  o  m
public IjParamsInfo exec(TemplateNode rootTemplate) {

    TransitiveDepTemplatesInfo depsInfo = findTransitiveDepTemplatesVisitor.exec(rootTemplate);

    if (!depsInfoToIjParamsInfoMap.containsKey(depsInfo)) {

        ImmutableMultimap.Builder<String, TemplateNode> ijParamToCalleesMultimapBuilder = ImmutableMultimap
                .builder();

        for (TemplateNode template : depsInfo.depTemplateSet) {

            if (!templateToLocalIjParamsMap.containsKey(template)) {
                templateToLocalIjParamsMap.put(template, IjDataQueries.getAllIjs(template));
            }

            for (String localIjParam : templateToLocalIjParamsMap.get(template)) {
                ijParamToCalleesMultimapBuilder.put(localIjParam, template);
            }

            for (TemplateParam injectedParam : template.getInjectedParams()) {
                ijParamToCalleesMultimapBuilder.put(injectedParam.name(), template);
            }
        }

        IjParamsInfo ijParamsInfo = new IjParamsInfo(ijParamToCalleesMultimapBuilder.build());
        depsInfoToIjParamsInfoMap.put(depsInfo, ijParamsInfo);
    }

    return depsInfoToIjParamsInfoMap.get(depsInfo);
}

From source file:org.lanternpowered.server.asset.DirectoryAssetRepository.java

@Override
public Multimap<String, Asset> getAssetsMap(String path, boolean checkChildDirectories) {
    final ImmutableMultimap.Builder<String, Asset> builder = ImmutableMultimap.builder();
    final Pattern pattern = Pattern.compile(generateRegex(path));
    final int length = this.directory.toString().length() + 1;
    try {/*from   ww  w.j  a  v a 2  s .  c o  m*/
        Files.walkFileTree(this.directory, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                final String file0 = file.toString().substring(length).replace('\\', '/');
                final Matcher matcher = pattern.matcher(file0);
                if (matcher.matches()) {
                    final String id = matcher.group(2).toLowerCase(Locale.ENGLISH);
                    final int index = id.indexOf('/');
                    if (index == -1 || (checkChildDirectories && index != id.lastIndexOf('/'))) {
                        return FileVisitResult.CONTINUE;
                    }
                    final String plugin = matcher.group(1).toLowerCase(Locale.ENGLISH);
                    builder.put(id.substring(0, index), registerAsset(plugin, plugin + ':' + id, file));
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return builder.build();
}

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

public static <R extends HttpRequest> R indexIterableToFormValuesWithPrefix(R request, String prefix,
        Object input) {//ww  w .jav a  2  s  .  co  m
    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:com.spectralogic.dsbrowser.gui.services.ds3Panel.DeleteService.java

/**
 * Delete folder(s)/* ww  w .ja  v  a2  s  . c  om*/
 *
 * @param ds3Common ds3Common object
 * @param values    list of folders to be deleted
 */
public static void deleteFolders(final Ds3Common ds3Common,
        final ImmutableList<TreeItem<Ds3TreeTableValue>> values) {
    LOG.info("Got delete folder event");

    final Ds3PanelPresenter ds3PanelPresenter = ds3Common.getDs3PanelPresenter();
    final Session currentSession = ds3Common.getCurrentSession();

    if (currentSession != null) {
        final ImmutableMultimap.Builder<String, String> deleteFoldersMap = ImmutableMultimap.builder();
        values.forEach(folder -> {
            deleteFoldersMap.put(folder.getValue().getBucketName(), folder.getValue().getFullName());
        });
        final Ds3DeleteFoldersTask deleteFolderTask = new Ds3DeleteFoldersTask(currentSession.getClient(),
                deleteFoldersMap.build());

        DeleteFilesPopup.show(deleteFolderTask, ds3Common);
        ds3PanelPresenter.getDs3PathIndicator().setText(StringConstants.EMPTY_STRING);
        ds3PanelPresenter.getDs3PathIndicatorTooltip().setText(StringConstants.EMPTY_STRING);
    }
}