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

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

Introduction

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

Prototype

boolean containsKey(@Nullable Object key);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the key key .

Usage

From source file:com.textocat.textokit.morph.opencorpora.resource.YoLemmaPostProcessor.java

/**
 * {@inheritDoc}/*from   w  w w.j a  v  a  2  s . c  o  m*/
 */
@Override
public boolean process(MorphDictionary dict, Lemma.Builder lemmaBuilder, Multimap<String, Wordform> wfMap) {
    Multimap<String, Wordform> additionalWfs = LinkedHashMultimap.create();
    for (String wfStr : wfMap.keySet()) {
        // alternative wordform string
        String altStr = StringUtils.replaceChars(wfStr, YO_CHARS, YO_REPLACEMENTS);
        if (Objects.equal(wfStr, altStr)) {
            continue;
        } // else wfStr contains 'yo'
        if (wfMap.containsKey(altStr)) {
            // the wordform multimap already contains string without 'yo'
            continue;
        }
        additionalWfs.putAll(altStr, wfMap.get(wfStr));
    }
    wfMap.putAll(additionalWfs);
    return true;
}

From source file:edu.umn.msi.tropix.persistence.service.impl.FolderServiceImpl.java

private Collection<TropixObjectContext<VirtualFolder>> buildSharedFolderContexts(
        final Collection<VirtualFolder> virtualFolders, final String gridId) {
    final Multimap<String, String> objectsRoles = getTropixObjectDao().getRoles(gridId,
            ModelUtils.getIds(virtualFolders));
    return Collections2.transform(Collections2.filter(virtualFolders, new Predicate<TropixObject>() {

        public boolean apply(final TropixObject input) {
            return objectsRoles.containsKey(input.getId())
                    && ModelPredicates.isValidObjectPredicate().apply(input);
        }/*from ww w .j  a va2  s . c  o  m*/

    }), new Function<VirtualFolder, TropixObjectContext<VirtualFolder>>() {

        public TropixObjectContext<VirtualFolder> apply(final VirtualFolder input) {
            final Collection<String> objectRoles = objectsRoles.get(input.getId());
            final TropixObjectUserAuthorities context = new TropixObjectUserAuthorities(
                    objectRoles.contains("write"), objectRoles.contains("write"));
            return new TropixObjectContext<VirtualFolder>(context, input);
        }

    });

}

From source file:de.esukom.decoit.ifmapclient.iptables.PollResultChecker.java

/**
 * check if passed in entry from poll-result-meta-data matches an "allowance" or an enforcement
 * filter-integer from enforcement.properties
 * //from  www . ja v a  2 s .  c  o  m
 * @param filterStrings map of rules to check against
 * @param resultPropertyValue the property of the entry to check
 * @param resultFilterValue value to compare to entry-content
 * @param checkType type of check to perform (contains/matches)
 * 
 * @return true, if passed in result-filter-value is contained or matched with entry inside
 *         filter-string--map
 */
public boolean checkPollResultForIPTablesIntegerRules(Multimap<String, Integer> filterInteger,
        String resultPropertyValue, int resultFilterValue, byte checkType, byte resultType) {

    // equals-match
    if (checkType == RULECHECK_TYPE_EQUALS) {
        if (filterInteger.containsKey(resultPropertyValue)) {
            // get entry for attribute
            Object[] resultFilter = filterInteger.get(resultPropertyValue).toArray();
            for (int i = 0; i < resultFilter.length; i++) {
                int currentFilter = new Integer((Integer) resultFilter[0]).intValue();
                if (resultFilterValue == currentFilter) {
                    return true;
                }
            }
        }
    }

    // greater-match
    else if (checkType == RULECHECK_TYPE_GREATER) {
        if (filterInteger.containsKey(resultPropertyValue)) {
            // get entry for attribute
            Object[] resultFilter = filterInteger.get(resultPropertyValue).toArray();
            for (int i = 0; i < resultFilter.length; i++) {
                int currentFilter = new Integer((Integer) resultFilter[0]).intValue();
                if (resultFilterValue > currentFilter) {
                    return true;
                }
            }
        }
    }

    // lower-match ;-)
    else /* if (checkType == RULECHECK_TYPE_MATCHES) */ {
        if (filterInteger.containsKey(resultPropertyValue)) {
            // get entry for attribute
            Object[] resultFilter = filterInteger.get(resultPropertyValue).toArray();
            for (int i = 0; i < resultFilter.length; i++) {
                int currentFilter = new Integer((Integer) resultFilter[0]).intValue();
                if (resultFilterValue < currentFilter) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.java

/**
 * Variation of {@link Multimap#put} that triggers an exception if a value already exists.
 *//*from w  ww  . ja  va 2 s.  c o  m*/
@VisibleForTesting
static <K, V> void putOnlyEntry(Multimap<K, V> map, K key, V value) {
    // Performance note: while "Verify.verify(!map.containsKey(key, value), String.format(...)))"
    // is simpler code, profiling shows a substantial performance penalty to that approach
    // (~10% extra analysis phase time on a simple cc_binary). Most of that is from the cost of
    // evaluating value.toString() on every call. This approach essentially eliminates the overhead.
    if (map.containsKey(key)) {
        throw new VerifyException(
                String.format("couldn't insert %s: map already has key %s", value.toString(), key.toString()));
    }
    map.put(key, value);
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime.Runtime.java

public Element toXml(Set<ObjectName> instancesToMap, Set<ObjectName> configBeans, Document document) {
    Element root = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.<String>absent());

    Element modulesElement = XmlUtil.createElement(document, XmlNetconfConstants.MODULES_KEY,
            Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
    root.appendChild(modulesElement);/*w w w  .  j  a va2 s  . c  o  m*/

    Map<String, Multimap<String, ObjectName>> moduleToRuntimeInstance = mapInstancesToModules(instancesToMap);
    Map<String, Map<String, Collection<ObjectName>>> moduleToConfigInstance = Config
            .getMappedInstances(configBeans, moduleConfigs);

    for (String localNamespace : moduleConfigs.keySet()) {

        Map<String, Collection<ObjectName>> instanceToMbe = moduleToConfigInstance.get(localNamespace);

        for (String moduleName : moduleConfigs.get(localNamespace).keySet()) {
            Multimap<String, ObjectName> instanceToRbe = moduleToRuntimeInstance.get(moduleName);

            for (ObjectName instanceON : instanceToMbe.get(moduleName)) {
                String instanceName = ObjectNameUtil.getInstanceName(instanceON);

                Element runtimeXml;
                ModuleConfig moduleConfig = moduleConfigs.get(localNamespace).get(moduleName);
                if (instanceToRbe == null || !instanceToRbe.containsKey(instanceName)) {
                    runtimeXml = moduleConfig.toXml(instanceON, document, localNamespace);
                } else {
                    ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
                    runtimeXml = moduleRuntime.toXml(localNamespace, instanceToRbe.get(instanceName), document,
                            moduleConfig, instanceON);
                }
                modulesElement.appendChild(runtimeXml);
            }

        }
    }

    return root;
}

From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java

private static void createAccount(PublicKey pubKey, UserInfo userInfo, String loginFilePath,
        String groupFilePath, Properties props, Multimap<String, String> groupsMap)
        throws ManageUsersException, KeyException {
    if (!userInfo.isLoginSet()) {
        warnWithMessage(PROVIDED_USERNAME + IS_EMPTY_SKIPPING);
        return;/* w w w . j a va  2  s.c  om*/
    }
    if (!userInfo.isPasswordSet()) {
        warnWithMessage("Provided password for user " + userInfo.getLogin() + IS_EMPTY_SKIPPING);
        return;
    }
    if (!userInfo.isGroupSet()) {
        warnWithMessage("Provided groups for user " + userInfo.getLogin() + IS_EMPTY_SKIPPING);
        return;
    }
    if (props.containsKey(userInfo.getLogin())) {
        warnWithMessage(USER_HEADER + userInfo.getLogin() + ALREADY_EXISTS_IN_LOGIN_FILE + loginFilePath
                + UPDATING_THIS_USER_INFORMATION);
    }
    if (groupsMap.containsKey(userInfo.getLogin())) {
        warnWithMessage(USER_HEADER + userInfo.getLogin() + ALREADY_EXISTS_IN_GROUP_FILE + groupFilePath
                + UPDATING_THIS_USER_INFORMATION);
    }
    updateUserPassword(pubKey, userInfo.getLogin(), userInfo.getPassword(), props);
    updateUserGroups(userInfo.getLogin(), userInfo.getGroups(), groupsMap);
    System.out.println("Created user " + userInfo.getLogin());

}

From source file:org.opendaylight.controller.config.facade.xml.runtime.Runtime.java

public Element toXml(Set<ObjectName> instancesToMap, Set<ObjectName> configBeans, Document document,
        final EnumResolver enumResolver) {
    Element root = XmlUtil.createElement(document, XmlMappingConstants.DATA_KEY, Optional.<String>absent());

    Element modulesElement = XmlUtil.createElement(document, XmlMappingConstants.MODULES_KEY,
            Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
    root.appendChild(modulesElement);/*from  w ww .ja  v  a2 s.c  o  m*/

    Map<String, Multimap<String, ObjectName>> moduleToRuntimeInstance = mapInstancesToModules(instancesToMap);
    Map<String, Map<String, Collection<ObjectName>>> moduleToConfigInstance = Config
            .getMappedInstances(configBeans, moduleConfigs);

    for (String localNamespace : moduleConfigs.keySet()) {

        Map<String, Collection<ObjectName>> instanceToMbe = moduleToConfigInstance.get(localNamespace);

        for (String moduleName : moduleConfigs.get(localNamespace).keySet()) {
            Multimap<String, ObjectName> instanceToRbe = moduleToRuntimeInstance.get(moduleName);

            for (ObjectName instanceON : instanceToMbe.get(moduleName)) {
                String instanceName = ObjectNameUtil.getInstanceName(instanceON);

                Element runtimeXml;
                ModuleConfig moduleConfig = moduleConfigs.get(localNamespace).get(moduleName);
                if (instanceToRbe == null || !instanceToRbe.containsKey(instanceName)) {
                    runtimeXml = moduleConfig.toXml(instanceON, document, localNamespace, enumResolver);
                } else {
                    ModuleRuntime moduleRuntime = moduleRuntimes.get(localNamespace).get(moduleName);
                    runtimeXml = moduleRuntime.toXml(localNamespace, instanceToRbe.get(instanceName), document,
                            moduleConfig, instanceON, enumResolver);
                }
                modulesElement.appendChild(runtimeXml);
            }

        }
    }

    return root;
}

From source file:org.sonar.java.se.JavaCheckVerifier.java

private void validateIssue(Multimap<Integer, Expectations.Issue> expected, List<Integer> unexpectedLines,
        AnalyzerMessage issue) {//w w  w  .  ja v  a 2s  .  c o m
    int line = issue.getLine();
    if (expected.containsKey(line)) {
        Expectations.Issue attrs = Iterables.getLast(expected.get(line));
        assertAttributeMatch(issue, attrs, MESSAGE);
        validateAnalyzerMessageAttributes(attrs, issue);
        expected.remove(line, attrs);
    } else {
        unexpectedLines.add(line);
    }
}

From source file:org.sosy_lab.java_smt.utils.UfElimination.java

private Multimap<FunctionDeclaration<?>, UninterpretedFunctionApplication> merge(
        Multimap<FunctionDeclaration<?>, UninterpretedFunctionApplication> pUfs, Result pPreviousResult) {
    for (Entry<FunctionDeclaration<?>, UninterpretedFunctionApplication> ufInOtherFormula : pPreviousResult
            .getUfs().entries()) {//w ww  .jav a 2  s .c o  m
        if (pUfs.containsKey(ufInOtherFormula.getKey())) {
            pUfs.put(ufInOtherFormula.getKey(), ufInOtherFormula.getValue());
        }
    }
    return pUfs;
}

From source file:org.opennms.features.topology.plugins.topo.linkd.internal.CdpLinkStatusProvider.java

@Override
protected List<EdgeAlarmStatusSummary> getEdgeAlarmSummaries(List<Integer> linkIds) {

    List<CdpTopologyLink> cdpLinks = getCdpLinkDao().findLinksForTopologyByIds(linkIds.toArray(new Integer[0]));
    Multimap<String, EdgeAlarmStatusSummary> summaryMap = HashMultimap.create();
    for (CdpTopologyLink link : cdpLinks) {
        summaryMap.put(link.getSrcNodeId() + ":" + link.getSrcIfIndex(),
                new EdgeAlarmStatusSummary(link.getSourceId(), link.getTargetId(), null));
    }//from w  ww.  jav a 2  s  .c  o  m

    List<OnmsAlarm> alarms = getLinkDownAlarms();
    for (OnmsAlarm alarm : alarms) {
        String key = alarm.getNodeId() + ":" + alarm.getIfIndex();
        if (summaryMap.containsKey(key)) {
            Collection<EdgeAlarmStatusSummary> summaries = summaryMap.get(key);
            for (EdgeAlarmStatusSummary summary : summaries) {
                summary.setEventUEI(alarm.getUei());
            }
        }
    }

    return new ArrayList<>(summaryMap.values());
}