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:com.facebook.buck.cxx.CxxFlags.java

private static ImmutableListMultimap<CxxSource.Type, String> toLanguageFlags(ImmutableList<String> flags) {

    ImmutableListMultimap.Builder<CxxSource.Type, String> result = ImmutableListMultimap.builder();

    for (CxxSource.Type type : CxxSource.Type.values()) {
        result.putAll(type, flags);//from  ww w . ja  v a 2s .c o m
    }

    return result.build();
}

From source file:org.tensorics.core.tensor.lang.OngoingOrderedFlattening.java

private ListMultimap<Position, S> intoListMultimap() {
    ImmutableListMultimap.Builder<Position, S> builder = ImmutableListMultimap.builder();
    Tensor<Map<C, S>> maps = TensorInternals.mapOut(tensor).inDirectionOf(dimensionToFlatten);
    for (Entry<Position, Map<C, S>> entry : entrySetOf(maps)) {
        Position newPosition = entry.getKey();
        Map<C, S> map = entry.getValue();
        List<C> keys = new ArrayList<>(map.keySet());
        Collections.sort(keys);/* w w  w .  j  ava 2s. co  m*/
        for (C key : keys) {
            builder.put(newPosition, map.get(key));
        }
    }
    return builder.build();
}

From source file:com.cisco.oss.foundation.http.apache.ApacheHttpResponse.java

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

    Header[] allHeaders = httpResponse.getAllHeaders();
    for (Header header : allHeaders) {
        builder.put(header.getName(), header.getValue());
    }/*ww w. j a v a  2s  .  c om*/
    return builder.build().asMap();
}

From source file:com.google.template.soy.shared.internal.DelTemplateSelector.java

private DelTemplateSelector(Builder<T> builder) {
    ImmutableTable.Builder<String, String, Group<T>> nameAndVariantBuilder = ImmutableTable.builder();
    ImmutableListMultimap.Builder<String, T> delTemplateNameToValuesBuilder = ImmutableListMultimap.builder();
    for (Table.Cell<String, String, Group.Builder<T>> entry : builder.nameAndVariantToGroup.cellSet()) {
        Group<T> group = entry.getValue().build();
        nameAndVariantBuilder.put(entry.getRowKey(), entry.getColumnKey(), group);
        String delTemplateName = entry.getRowKey();
        if (group.defaultValue != null) {
            delTemplateNameToValuesBuilder.put(delTemplateName, group.defaultValue);
        }/*from w  w w .ja v a  2  s .  c o m*/
        delTemplateNameToValuesBuilder.putAll(delTemplateName, group.delpackageToValue.values());
    }
    this.nameAndVariantToGroup = nameAndVariantBuilder.build();
    this.delTemplateNameToValues = delTemplateNameToValuesBuilder.build();
}

From source file:no.ssb.vtl.script.operations.join.InnerJoinMerger.java

private ImmutableListMultimap<Integer, Integer> buildIndices(ImmutableList<Component> leftList,
        ImmutableList<Component> rightList) {
    ImmutableListMultimap.Builder<Integer, Integer> indexMapBuilder = ImmutableListMultimap.builder();
    // Save the indices of the right data points that need to be moved to the left.
    for (int i = 0; i < rightList.size(); i++) {
        Component rightComponent = rightList.get(i);
        for (int j = 0; j < leftList.size(); j++) {
            Component leftComponent = leftList.get(j);
            if (rightComponent.equals(leftComponent)) {
                indexMapBuilder.put(i, j);
            }//from ww w .  j  av  a2s .  c  o m
        }
    }
    return indexMapBuilder.build();
}

From source file:io.prestosql.sql.planner.iterative.rule.PushProjectionThroughUnion.java

@Override
public Result apply(ProjectNode parent, Captures captures, Context context) {
    UnionNode source = captures.get(CHILD);

    // OutputLayout of the resultant Union, will be same as the layout of the Project
    List<Symbol> outputLayout = parent.getOutputSymbols();

    // Mapping from the output symbol to ordered list of symbols from each of the sources
    ImmutableListMultimap.Builder<Symbol, Symbol> mappings = ImmutableListMultimap.builder();

    // sources for the resultant UnionNode
    ImmutableList.Builder<PlanNode> outputSources = ImmutableList.builder();

    for (int i = 0; i < source.getSources().size(); i++) {
        Map<Symbol, SymbolReference> outputToInput = source.sourceSymbolMap(i); // Map: output of union -> input of this source to the union
        Assignments.Builder assignments = Assignments.builder(); // assignments for the new ProjectNode

        // mapping from current ProjectNode to new ProjectNode, used to identify the output layout
        Map<Symbol, Symbol> projectSymbolMapping = new HashMap<>();

        // Translate the assignments in the ProjectNode using symbols of the source of the UnionNode
        for (Map.Entry<Symbol, Expression> entry : parent.getAssignments().entrySet()) {
            Expression translatedExpression = inlineSymbols(outputToInput, entry.getValue());
            Type type = context.getSymbolAllocator().getTypes().get(entry.getKey());
            Symbol symbol = context.getSymbolAllocator().newSymbol(translatedExpression, type);
            assignments.put(symbol, translatedExpression);
            projectSymbolMapping.put(entry.getKey(), symbol);
        }//from www  . j  av a 2s .  c o  m
        outputSources.add(new ProjectNode(context.getIdAllocator().getNextId(), source.getSources().get(i),
                assignments.build()));
        outputLayout.forEach(symbol -> mappings.put(symbol, projectSymbolMapping.get(symbol)));
    }

    return Result.ofPlanNode(new UnionNode(parent.getId(), outputSources.build(), mappings.build(),
            ImmutableList.copyOf(mappings.build().keySet())));
}

From source file:io.wcm.caravan.pipeline.extensions.hal.crawler.LinkExtractors.java

/**
 * Returns all relations and links provided by the {@code delegate}d {@link LinkExtractor} where the URI starts with
 * the given prefix./* w  w  w .  j a  va2s.com*/
 * @param prefix URI prefix
 * @param delegate Delegated link extractor
 * @return Link extractor for prefixed URIs
 */
public static LinkExtractor filterByPrefix(String prefix, LinkExtractor delegate) {
    return new LinkExtractor() {

        @Override
        public String getId() {
            return "ONLY-STARTING-WITH('" + prefix + "', " + delegate.getId() + ")";
        }

        @Override
        public ListMultimap<String, Link> extract(HalResource hal) {

            ListMultimap<String, Link> fromDelegate = delegate.extract(hal);
            Builder<String, Link> builder = ImmutableListMultimap.builder();
            fromDelegate.entries().stream()
                    .filter(entry -> StringUtils.startsWith(entry.getValue().getHref(), prefix))
                    .forEach(entry -> builder.put(entry));
            return builder.build();

        }
    };
}

From source file:org.ambraproject.wombat.freemarker.TemplateModelUtil.java

static ImmutableListMultimap<String, TemplateModel> getAsMultimap(TemplateModel value)
        throws TemplateModelException {
    if (value == null)
        return ImmutableListMultimap.of();
    if (value instanceof TemplateHashModelEx) {
        TemplateHashModelEx ftlHash = (TemplateHashModelEx) value;
        ImmutableListMultimap.Builder<String, TemplateModel> builder = ImmutableListMultimap.builder();
        for (TemplateModelIterator iterator = ftlHash.keys().iterator(); iterator.hasNext();) {
            String key = iterator.next().toString();
            TemplateModel model = ftlHash.get(key);
            if (model instanceof TemplateSequenceModel) {
                TemplateSequenceModel sequenceModel = (TemplateSequenceModel) model;
                int size = sequenceModel.size();
                for (int i = 0; i < size; i++) {
                    builder.put(key, sequenceModel.get(i));
                }//w  w  w. j a v a  2s .  c o m
            } else {
                builder.put(key, model);
            }
        }
        return builder.build();
    }
    throw new TemplateModelException("Hash type expected");
}

From source file:com.isotrol.impe3.web20.server.CommentMap.java

CommentMap(Builder builder) {
    final ImmutableListMultimap.Builder<Key, Entry<String>> b = ImmutableListMultimap.builder();
    for (Map.Entry<Key, Multiset<String>> e : builder.map.entrySet()) {
        b.putAll(e.getKey(), ORDER.sortedCopy(e.getValue().entrySet()));
    }//from   w  w  w.  j  av a2 s  .  co m
    this.map = b.build();
}

From source file:com.facebook.buck.cxx.CxxFlags.java

public static ImmutableListMultimap<CxxSource.Type, String> getLanguageFlags(ImmutableList<String> flags,
        PatternMatchedCollection<ImmutableList<String>> platformFlags,
        ImmutableMap<CxxSource.Type, ImmutableList<String>> languageFlags, CxxPlatform platform) {

    ImmutableListMultimap.Builder<CxxSource.Type, String> langFlags = ImmutableListMultimap.builder();

    langFlags.putAll(toLanguageFlags(getFlags(flags, platformFlags, platform)));

    for (ImmutableMap.Entry<CxxSource.Type, ImmutableList<String>> entry : languageFlags.entrySet()) {
        langFlags.putAll(entry.getKey(), Iterables.transform(entry.getValue(), getTranslateMacrosFn(platform)));
    }//  w w  w  .  ja v a2 s  .  c  o m

    return langFlags.build();
}