Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:grakn.core.graql.gremlin.RelationTypeInference.java

private static Multimap<Variable, Variable> getRelationRolePlayerMap(Set<Fragment> allFragments,
        Multimap<Variable, Type> instanceVarTypeMap) {
    // get all relation vars and its role player vars
    Multimap<Variable, Variable> relationRolePlayerMap = HashMultimap.create();
    allFragments.stream().filter(OutRolePlayerFragment.class::isInstance)
            .forEach(fragment -> relationRolePlayerMap.put(fragment.start(), fragment.end()));

    Multimap<Variable, Variable> inferrableRelationsRolePlayerMap = HashMultimap.create();

    allFragments.stream().filter(OutRolePlayerFragment.class::isInstance)
            .filter(fragment -> !instanceVarTypeMap.containsKey(fragment.start())) // filter out known rel types
            .forEach(fragment -> {//from w ww  .j  a  v  a2s  .c  om
                Variable relation = fragment.start();

                // the relation should have at least 2 known role players so we can infer something useful
                int numRolePlayersHaveType = 0;
                for (Variable rolePlayer : relationRolePlayerMap.get(relation)) {
                    if (instanceVarTypeMap.containsKey(rolePlayer)) {
                        numRolePlayersHaveType++;
                    }
                }

                if (numRolePlayersHaveType >= 2) {
                    inferrableRelationsRolePlayerMap.put(relation, fragment.end());
                }
            });

    return inferrableRelationsRolePlayerMap;
}

From source file:org.sonar.core.issue.tracking.BlockRecognizer.java

private static <T extends Trackable> Multimap<Integer, T> groupByLine(Iterable<T> trackables,
        BlockHashSequence hashSequence) {
    Multimap<Integer, T> result = LinkedHashMultimap.create();
    for (T trackable : trackables) {
        Integer line = trackable.getLine();
        if (hashSequence.hasLine(line)) {
            result.put(line, trackable);
        }/*www .j av a2s  .com*/
    }
    return result;
}

From source file:com.lithium.flow.matcher.StringMatchers.java

@Nonnull
public static StringMatcher fromList(@Nonnull List<String> list) {
    Multimap<String, String> multimap = HashMultimap.create();
    for (String value : list) {
        int index = value.indexOf(':');
        if (index == -1 || index >= value.length() - 1) {
            multimap.put("exact", value);
        } else {//from   w  w w .  j a v  a2  s.c o m
            int index2 = value.indexOf("?[");
            int index3 = value.indexOf("]:", index2);
            if (index2 > -1 && index3 > -1 && index2 < index) {
                index = index2 + 1;
            }

            String type = value.substring(0, index);
            String param = value.substring(index + 1);
            multimap.put(type, param);
        }
    }

    List<StringMatcher> quickMatchers = Lists.newArrayList();
    quickMatchers.addAll(buildList(multimap, "len", LenStringMatcher::new));
    Collection<String> exacts = multimap.get("exact");
    if (exacts.size() == 1) {
        quickMatchers.add(new ExactStringMatcher(exacts.iterator().next()));
    } else if (exacts.size() > 1) {
        quickMatchers.add(new ExactSetStringMatcher(Sets.newHashSet(exacts)));
    }
    quickMatchers.addAll(buildList(multimap, "prefix", PrefixStringMatcher::new));
    quickMatchers.addAll(buildList(multimap, "suffix", SuffixStringMatcher::new));
    quickMatchers.addAll(buildList(multimap, "contains", ContainsStringMatcher::new));

    List<StringMatcher> lowerMatchers = Lists.newArrayList();
    lowerMatchers.addAll(buildList(multimap, "lower.prefix", PrefixStringMatcher::new));
    lowerMatchers.addAll(buildList(multimap, "lower.suffix", SuffixStringMatcher::new));
    lowerMatchers.addAll(buildList(multimap, "lower.contains", ContainsStringMatcher::new));

    List<StringMatcher> regexMatchers = Lists.newArrayList();
    regexMatchers.addAll(buildList(multimap, "regex", RegexStringMatcher::new));
    regexMatchers.addAll(buildList(multimap, "lower.regex", LowerRegexStringMatcher::new));

    List<StringMatcher> allMatchers = Lists.newArrayList();
    allMatchers.add(buildComposite(quickMatchers, false));
    allMatchers.add(buildComposite(lowerMatchers, true));
    allMatchers.add(buildComposite(regexMatchers, false));
    return buildComposite(allMatchers, false);
}

From source file:moavns.SolucaoAleatoria.java

public static Solucao eliminarRedundancia(Solucao solucao) {
    Multimap<Float, Integer> colunas = TreeMultimap.create();
    for (Coluna coluna : solucao.getColunas()) {
        Float custo = coluna.getCusto();
        colunas.put((custo * (-1)), coluna.getNome());
    }//from   w  ww. ja v a 2 s . c  o  m
    Solucao testarsolucao = new Solucao(solucao);
    for (Float chave : colunas.keySet()) {
        Iterator iterador = colunas.get(chave).iterator();
        while (iterador.hasNext()) {
            Solucao testar = new Solucao(testarsolucao);
            Coluna maiorcoluna = testarsolucao.getLinhasX().get(iterador.next());
            testar.getLinhasCobertas().clear();
            cobrirLinhas(maiorcoluna, testar);
            if (testar.getLinhasCobertas().size() == testar.getQtdeLinhas()) {
                testar.getColunas().remove(maiorcoluna);
                testar.setCustototal(testar.getCustototal() - maiorcoluna.getCusto());
                testarsolucao = testar;
            }
        }
    }
    return testarsolucao;
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

static Multimap<KbaChangeSetQualifier, Binding> buildQualifierToBindingMap(List<Binding> bindings) {
    Multimap<KbaChangeSetQualifier, Binding> result = ArrayListMultimap.create();
    for (Binding binding : bindings) {
        result.put(qualifierForBinding(binding, Action.ADD), binding);
    }/*  ww  w  . j a  va2 s. com*/
    return result;
}

From source file:com.torodb.torod.db.backends.query.processors.InProcessor.java

public static List<ProcessedQueryCriteria> process(InQueryCriteria criteria,
        QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor) {

    if (!Utils.isTypeKnownInStructure(criteria.getAttributeReference())) {
        return Collections.singletonList(new ProcessedQueryCriteria(null, criteria));
    } else {//from  w  w  w  .  ja v a 2  s .c  o m

        Multimap<ScalarType, ScalarValue<?>> byTypeValues = MultimapBuilder.enumKeys(ScalarType.class)
                .hashSetValues().build();

        for (ScalarValue<?> value : criteria.getValue()) {
            byTypeValues.put(value.getType(), value);
        }

        List<ProcessedQueryCriteria> result;

        if (byTypeValues.isEmpty()) {
            result = Collections.emptyList();
        } else {
            result = Lists.newArrayList();

            ProcessedQueryCriteria typeQuery;

            typeQuery = getNumericQuery(criteria, byTypeValues);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.STRING);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.ARRAY);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.BOOLEAN);
            if (typeQuery != null) {
                result.add(typeQuery);
            }

            typeQuery = getProcessedQuery(criteria, byTypeValues, ScalarType.NULL);
            if (typeQuery != null) {
                result.add(typeQuery);
            }
        }

        return result;
    }
}

From source file:com.isotrol.impe3.core.support.RouteParams.java

public static Multimap<String, String> toParams(UUID csrfToken, Route route) {
    if (route == null) {
        return ImmutableMultimap.of();
    }/*from   w w  w .  j  ava2  s.c  om*/
    final PageKey key = route.getPage();
    if (key == null) {
        return ImmutableMultimap.of();
    }
    Multimap<String, String> p = ArrayListMultimap.create();
    if (route.isSecure()) {
        p.put(SECURE, "");
    }
    // The pk will only be an error page in case no page was resolved, so we turn to the main page
    if (key == PageKey.main() || key instanceof ErrorPage) {
        p.put(TYPE, TYPE_M);
    } else if (key instanceof Special) {
        p.put(TYPE, TYPE_S);
        p.put(NAME, ((Special) key).getName().toString());
    } else if (key instanceof WithNavigation) {
        WithNavigation wn = (WithNavigation) key;
        final NavigationKey nk = wn.getNavigationKey();
        if (nk != null) {
            if (nk.isCategory()) {
                p.put(CATEGORY, nk.getCategory().getId().toString());
            } else if (nk.isTag()) {
                p.put(TAG, nk.getTag());
            }
            if (nk.isContentType()) {
                p.put(TYPE, TYPE_L);
                p.put(CONTENT_TYPE, nk.getContentType().getId().toString());
            }
        }
        if (wn instanceof NavigationPage) {
            p.put(TYPE, TYPE_N);
        } else if (wn instanceof ContentPage) {
            ContentPage cp = (ContentPage) key;
            final ContentKey ck = cp.getContentKey();
            p.put(CONTENT_TYPE, ck.getContentType().getId().toString());
            p.put(CONTENT_ID, ck.getContentId());
            p.put(TYPE, TYPE_C);
        }
    }
    final Locale locale = route.getLocale();
    if (locale != null) {
        p.put(LOCALE, locale.toString());
    }
    final Device device = route.getDevice();
    if (device != null) {
        p.put(DEVICE, device.getId().toString());
    }
    if (csrfToken != null) {
        p.put(SESSIONCSRF, csrfToken.toString());
    }
    return p;
}

From source file:org.drools.verifier.report.html.MissingRangesReportVisitor.java

public static Collection<String> visitRestrictionsCollection(String sourceFolder,
        Collection<Restriction> restrictions, Collection<MissingRange> causes) {

    Multimap<String, DataRow> dt = TreeMultimap.create();
    Collection<String> stringRows = new ArrayList<String>();

    for (MissingRange cause : causes) {
        dt.put(cause.getValueAsString(),
                new DataRow(null, null, cause.getOperator(), cause.getValueAsString()));
    }//  w  w w . ja  v  a2s.  co  m

    for (Restriction r : restrictions) {
        if (r instanceof NumberRestriction) {
            try {
                NumberRestriction restriction = (NumberRestriction) r;

                dt.put(restriction.getValue().toString(), new DataRow(restriction.getRulePath(),
                        restriction.getRuleName(), restriction.getOperator(), restriction.getValueAsString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    DataRow previous = null;
    for (Iterator<DataRow> iterator = dt.values().iterator(); iterator.hasNext();) {
        DataRow current = iterator.next();

        if (previous != null) {
            // Check if previous and current are from the same rule.
            if (previous.ruleId == null && current.ruleId == null && !previous.operator.equals(Operator.EQUAL)
                    && !previous.operator.equals(Operator.NOT_EQUAL) && !current.operator.equals(Operator.EQUAL)
                    && !current.operator.equals(Operator.NOT_EQUAL)) {
                // Combine these two.
                stringRows.add("Missing : " + previous + " .. " + current);

                if (iterator.hasNext())
                    current = iterator.next();

            } else if (previous.ruleId != null && previous.ruleId.equals(current.ruleId)) {
                // Combine these two.
                stringRows.add(UrlFactory.getRuleUrl(sourceFolder, current.ruleId, current.ruleName) + " : "
                        + previous.toString() + " " + current.toString());

                if (iterator.hasNext())
                    current = iterator.next();

            } else if (!iterator.hasNext()) { // If this is last row
                // Print previous and current if they were not merged.
                processRangeOutput(previous, stringRows, sourceFolder);
                processRangeOutput(current, stringRows, sourceFolder);

            } else { // If they are not from the same rule
                // Print previous.
                processRangeOutput(previous, stringRows, sourceFolder);
            }
        } else if (!iterator.hasNext()) {
            processRangeOutput(current, stringRows, sourceFolder);
        }

        // Set current as previous.
        previous = current;
    }

    return stringRows;
}

From source file:com.github.autermann.wps.streaming.data.ReferencedData.java

public static ReferencedData of(InputReferenceType xb) {
    XmlObject body = null;/*from ww  w. j a  v  a2s . co m*/
    URI bodyReference = null;
    if (xb.isSetBody()) {
        body = xb.getBody();
    }
    if (xb.isSetBodyReference()) {
        bodyReference = URI.create(xb.getBodyReference().getHref());
    }
    Method method = Method.GET;
    URI href = URI.create(xb.getHref());
    if (xb.isSetMethod()) {
        switch (xb.getMethod().toString()) {
        case "GET":
            method = Method.GET;
            break;
        case "POST":
            method = Method.POST;
            break;
        }
    }
    Multimap<String, String> headers = HashMultimap.create();
    if (xb.getHeaderArray() != null) {
        for (InputReferenceType.Header header : xb.getHeaderArray()) {
            headers.put(header.getKey(), header.getValue());
        }
    }
    Format format = new Format(xb.getMimeType(), xb.getEncoding(), xb.getSchema());
    return new ReferencedData(href, method, headers, format, bodyReference, body);
}

From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainerBuilder.java

private static ImmutableMultimap<Path, OmniProjectTask> buildProjectTasksRecursively(GradleProject project,
        Multimap<Path, OmniProjectTask> tasksPerProject, boolean enforceAllTasksPublic) {
    // add tasks of the current project
    for (GradleTask task : project.getTasks()) {
        tasksPerProject.put(Path.from(project.getPath()),
                DefaultOmniProjectTask.from(task, enforceAllTasksPublic));
    }//from  w  ww. java  2 s.  c o m

    // recurse into child projects and add their tasks
    for (GradleProject childProject : project.getChildren()) {
        buildProjectTasksRecursively(childProject, tasksPerProject, enforceAllTasksPublic);
    }

    // return the tasks grouped by project path
    return ImmutableMultimap.copyOf(tasksPerProject);
}