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:io.prestosql.sql.planner.optimizations.joins.JoinGraph.java

private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinClauses, Context context,
        PlanNodeId newRoot) {/*  w w w. j  a  v a 2  s  .com*/
    for (PlanNode node : other.nodes) {
        checkState(!edges.containsKey(node.getId()), format("Node [%s] appeared in two JoinGraphs", node));
    }

    List<PlanNode> nodes = ImmutableList.<PlanNode>builder().addAll(this.nodes).addAll(other.nodes).build();

    ImmutableMultimap.Builder<PlanNodeId, Edge> edges = ImmutableMultimap.<PlanNodeId, Edge>builder()
            .putAll(this.edges).putAll(other.edges);

    List<Expression> joinedFilters = ImmutableList.<Expression>builder().addAll(this.filters)
            .addAll(other.filters).build();

    for (JoinNode.EquiJoinClause edge : joinClauses) {
        Symbol leftSymbol = edge.getLeft();
        Symbol rightSymbol = edge.getRight();
        checkState(context.containsSymbol(leftSymbol));
        checkState(context.containsSymbol(rightSymbol));

        PlanNode left = context.getSymbolSource(leftSymbol);
        PlanNode right = context.getSymbolSource(rightSymbol);
        edges.put(left.getId(), new Edge(right, leftSymbol, rightSymbol));
        edges.put(right.getId(), new Edge(left, rightSymbol, leftSymbol));
    }

    return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty());
}

From source file:com.android.tools.idea.npw.assetstudio.wizard.GenerateIconsPanel.java

/**
 * Create a panel which can generate Android icons. The supported types passed in will be
 * presented to the user in a pulldown menu (unless there's only one supported type). If no
 * supported types are passed in, then all types will be supported by default.
 *///  w w  w .j a  v a2s  .c o  m
public GenerateIconsPanel(@NotNull Disposable disposableParent, @NotNull AndroidProjectPaths defaultPaths,
        @NotNull AndroidIconType... supportedTypes) {
    super(new BorderLayout());

    myDefaultPaths = defaultPaths;
    myPaths = myDefaultPaths;

    if (supportedTypes.length == 0) {
        supportedTypes = AndroidIconType.values();
    }

    DefaultComboBoxModel supportedTypesModel = new DefaultComboBoxModel(supportedTypes);
    myIconTypeCombo.setModel(supportedTypesModel);
    myIconTypeCombo.setVisible(supportedTypes.length > 1);

    assert myConfigureIconPanels.getLayout() instanceof CardLayout;
    for (AndroidIconType iconType : supportedTypes) {
        myConfigureIconPanels.add(new ConfigureIconPanel(this, iconType), iconType.toString());
    }

    mySourceAssetMaxWidthPanel.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            updateSourceAssetPreview(getActiveIconPanel().getAsset().toImage());
        }
    });

    // @formatter:off
    ImmutableMultimap.Builder<AndroidIconType, PreviewIconsPanel> previewPanelBuilder = ImmutableMultimap
            .builder();
    previewPanelBuilder.putAll(AndroidIconType.ACTIONBAR,
            new PreviewIconsPanel("", PreviewIconsPanel.Theme.TRANSPARENT));
    previewPanelBuilder.putAll(AndroidIconType.LAUNCHER,
            new PreviewIconsPanel("", PreviewIconsPanel.Theme.TRANSPARENT));
    previewPanelBuilder.putAll(AndroidIconType.NOTIFICATION,
            new PreviewIconsPanel("API 11+", PreviewIconsPanel.Theme.DARK,
                    new CategoryIconMap.NotificationFilter(NotificationIconGenerator.Version.V11)),
            new PreviewIconsPanel("API 9+", PreviewIconsPanel.Theme.LIGHT,
                    new CategoryIconMap.NotificationFilter(NotificationIconGenerator.Version.V9)),
            new PreviewIconsPanel("Older APIs", PreviewIconsPanel.Theme.GRAY,
                    new CategoryIconMap.NotificationFilter(NotificationIconGenerator.Version.OLDER)));
    myOutputPreviewPanels = previewPanelBuilder.build();
    // @formatter:on

    for (PreviewIconsPanel iconsPanel : myOutputPreviewPanels.values()) {
        myOutputPreviewPanel.add(iconsPanel);
    }

    myOutputIconType = new AsValueExpression<>(new SelectedItemProperty<>(myIconTypeCombo));

    initializeListenersAndBindings();

    myValidatorPanel = new ValidatorPanel(this, myRootPanel);
    initializeValidators();

    Disposer.register(disposableParent, this);
    Disposer.register(this, myValidatorPanel);
    add(myValidatorPanel);
}

From source file:uk.ac.open.kmi.iserve.sal.manager.impl.ServiceManagerIndexRdf.java

/**
 * Given an operation, this method obtains the list of input URIs mapped to their annotated types (i.e., modelReferences).
 * Note that the same input may have several annotations indicating the type.
 *
 * @param operationUri the URI for which we want to obtain the inputs and their annotated types
 * @return a Multimap with the inputs and their corresponding types.
 */// w  w w.jav  a  2 s .c  om
@Override
public Multimap<URI, URI> listTypedInputs(URI operationUri) {
    if (operationUri == null) {
        return ImmutableMultimap.of();
    }

    ImmutableMultimap.Builder<URI, URI> result = ImmutableMultimap.builder();
    for (URI input : this.opInputMap.get(operationUri)) {
        result.putAll(input, this.modelReferencesMap.get(input));
    }

    return result.build();
}

From source file:com.facebook.presto.metadata.DatabaseShardManager.java

@Override
public Multimap<String, ? extends PartitionKey> getAllPartitionKeys(TableHandle tableHandle) {
    checkNotNull(tableHandle, "tableHandle is null");
    checkState(tableHandle instanceof NativeTableHandle, "can only commit partitions for native tables");
    final long tableId = ((NativeTableHandle) tableHandle).getTableId();

    Set<NativePartitionKey> partitionKeys = dao.getPartitionKeys(tableId);
    ImmutableMultimap.Builder<String, PartitionKey> builder = ImmutableMultimap.builder();
    for (NativePartitionKey partitionKey : partitionKeys) {
        builder.put(partitionKey.getPartitionName(), partitionKey);
    }/* ww w  .ja  v a  2  s  .  c om*/

    return builder.build();
}

From source file:org.kiji.schema.zookeeper.UsersTracker.java

/**
 * Retrieve a multimap of the current users to their respective value (either table layout version
 * if tracking table users, or system version if tracking instance users).
 *
 * @return a multimap of the current table users to their respective value.
 * @throws IOException on failure./*w  w  w  .  j  a  v  a  2  s .c  o m*/
 */
public Multimap<String, String> getUsers() throws IOException {
    ImmutableMultimap.Builder<String, String> users = ImmutableSetMultimap.builder();
    for (ChildData child : mCache.getCurrentData()) {
        String nodeName = Iterables.getLast(Splitter.on('/').split(child.getPath()));
        String[] split = nodeName.split(ZooKeeperUtils.ZK_NODE_NAME_SEPARATOR);
        if (split.length != 2) {
            LOG.error("Ignoring invalid ZooKeeper table user node: {}.", nodeName);
            continue;
        }
        final String userID = URLDecoder.decode(split[0], Charsets.UTF_8.displayName());
        final String layoutID = URLDecoder.decode(split[1], Charsets.UTF_8.displayName());

        users.put(userID, layoutID);
    }
    return users.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;//ww  w  .j  av 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:io.prestosql.plugin.raptor.legacy.storage.organization.ShardOrganizerUtil.java

public static Collection<Collection<ShardIndexInfo>> getShardsByDaysBuckets(Table tableInfo,
        Collection<ShardIndexInfo> shards, TemporalFunction temporalFunction) {
    if (shards.isEmpty()) {
        return ImmutableList.of();
    }/*from  w  ww.j  av a  2  s.c  o m*/

    // Neither bucketed nor temporal, no partitioning required
    if (!tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return ImmutableList.of(shards);
    }

    // if only bucketed, partition by bucket number
    if (tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return Multimaps.index(shards, shard -> shard.getBucketNumber().getAsInt()).asMap().values();
    }

    // if temporal, partition into days first
    ImmutableMultimap.Builder<Long, ShardIndexInfo> shardsByDaysBuilder = ImmutableMultimap.builder();
    shards.stream().filter(shard -> shard.getTemporalRange().isPresent()).forEach(shard -> {
        long day = temporalFunction.getDayFromRange(shard.getTemporalRange().get());
        shardsByDaysBuilder.put(day, shard);
    });

    Collection<Collection<ShardIndexInfo>> byDays = shardsByDaysBuilder.build().asMap().values();

    // if table is bucketed further partition by bucket number
    if (!tableInfo.getBucketCount().isPresent()) {
        return byDays;
    }

    ImmutableList.Builder<Collection<ShardIndexInfo>> sets = ImmutableList.builder();
    for (Collection<ShardIndexInfo> s : byDays) {
        sets.addAll(Multimaps.index(s, ShardIndexInfo::getBucketNumber).asMap().values());
    }
    return sets.build();
}

From source file:eu.eubrazilcc.lvl.core.xml.GbSeqXmlBinder.java

/**
 * Infers the possible countries of the species from which the DNA sequence was obtained and 
 * returns a map of Java {@link Locale} where the key of the map is the GenBank field that was
 * used to infer the country. The country is inferred from the annotations of the GenBank file 
 * format, using the fields in the following order:
 * <ol>//from  ww w.  j  a v  a 2s . c o m
 * <li>If a country entry exists in the features of the file, then this is returned to 
 * the caller and no other check is performed;</li>
 * <li>Definition field;</li>
 * <li>Title field; or</li>
 * <li>Check PubMed title and abstract fields.</li>
 * </ol>
 * @param sequence - sequence to be analyzed
 * @return a map of Java {@link Locale} inferred from the input sequence, where the key of the map
 *         is the GenBank field used to infer the country.
 */
public static final ImmutableMultimap<String, Locale> inferCountry(final GBSeq sequence) {
    checkArgument(sequence != null, "Uninitialized or invalid sequence");
    final ImmutableMultimap.Builder<String, Locale> builder = new ImmutableMultimap.Builder<String, Locale>();
    // infer from features
    final String countryFeature = countryFeature(sequence);
    Locale locale = isNotBlank(countryFeature) ? countryFeatureToLocale(countryFeature) : null;
    if (locale != null) {
        builder.put("features", locale);
    } else {
        // infer from definition
        // TODO

        // infer from title
        // TODO

        // infer from PubMed title and abstract fields
        // TODO
    }
    return builder.build();
}

From source file:com.facebook.presto.raptor.storage.organization.ShardOrganizerUtil.java

public static Collection<Collection<ShardIndexInfo>> getShardsByDaysBuckets(Table tableInfo,
        Collection<ShardIndexInfo> shards) {
    // Neither bucketed nor temporal, no partitioning required
    if (!tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return ImmutableList.of(shards);
    }//from  www . j a v  a 2s  .  c  om

    // if only bucketed, partition by bucket number
    if (tableInfo.getBucketCount().isPresent() && !tableInfo.getTemporalColumnId().isPresent()) {
        return Multimaps.index(shards, shard -> shard.getBucketNumber().getAsInt()).asMap().values();
    }

    // if temporal, partition into days first
    ImmutableMultimap.Builder<Long, ShardIndexInfo> shardsByDaysBuilder = ImmutableMultimap.builder();
    shards.stream().filter(shard -> shard.getTemporalRange().isPresent()).forEach(shard -> {
        long day = determineDay(shard.getTemporalRange().get());
        shardsByDaysBuilder.put(day, shard);
    });

    Collection<Collection<ShardIndexInfo>> byDays = shardsByDaysBuilder.build().asMap().values();

    // if table is bucketed further partition by bucket number
    if (!tableInfo.getBucketCount().isPresent()) {
        return byDays;
    }

    ImmutableList.Builder<Collection<ShardIndexInfo>> sets = ImmutableList.builder();
    for (Collection<ShardIndexInfo> s : byDays) {
        sets.addAll(Multimaps.index(s, ShardIndexInfo::getBucketNumber).asMap().values());
    }
    return sets.build();
}

From source file:com.facebook.presto.metadata.DatabaseShardManager.java

@Override
public Multimap<Long, Entry<Long, String>> getCommittedPartitionShardNodes(TableHandle tableHandle) {
    checkNotNull(tableHandle, "tableHandle is null");
    checkState(tableHandle instanceof NativeTableHandle, "tableHandle not a native table");
    final long tableId = ((NativeTableHandle) tableHandle).getTableId();

    ImmutableMultimap.Builder<Long, Entry<Long, String>> map = ImmutableMultimap.builder();

    List<ShardNode> shardNodes = dao.getCommittedShardNodesByTableId(tableId);
    for (ShardNode shardNode : shardNodes) {
        map.put(shardNode.getPartitionId(),
                Maps.immutableEntry(shardNode.getShardId(), shardNode.getNodeIdentifier()));
    }//from  w ww . ja  va2 s  .com
    return map.build();
}