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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:org.nnsoft.guice.junice.GuiceMockModule.java

@SuppressWarnings("unchecked")
@Override//from   www .  ja v a2s  .  c  om
protected void configure() {
    final Multimap<Type, Field> fieldsByType = HashMultimap.create();

    for (final Entry<Field, Object> entry : this.mockedFields.entrySet()) {
        fieldsByType.put(entry.getKey().getGenericType(), entry.getKey());
    }

    for (final Type type : fieldsByType.keySet()) {
        final Collection<Field> fields = fieldsByType.get(type);

        boolean isTypeConflicts = false;
        if (fields.size() != 1) {
            isTypeConflicts = checkTypeConflict(fields);
        }

        checkState(!isTypeConflicts, "   Found multiple annotation @%s for type: %s; binding skipped!.",
                Mock.class.getSimpleName(), type);
        for (final Field field : fields) {
            final TypeLiteral literal = TypeLiteral.get(type);
            final Mock annoBy = field.getAnnotation(Mock.class);
            final Object mock = this.mockedFields.get(field);
            if (annoBy.annotatedWith() != Mock.NoAnnotation.class) {
                bind(literal).annotatedWith(annoBy.annotatedWith()).toInstance(mock);
            } else if (!"".equals(annoBy.namedWith())) {
                bind(literal).annotatedWith(Names.named(annoBy.namedWith())).toInstance(mock);
            } else {
                bind(literal).toInstance(mock);
            }
            if (logger.isLoggable(Level.FINER)) {
                logger.finer("    Created binding for: " + type + " " + annoBy);
            }
        }
    }
}

From source file:org.nuxeo.ecm.platform.groups.audit.service.acl.AclExcelLayoutBuilderMultiColumn.java

@Override
protected void renderAcl(Multimap<String, Pair<String, Boolean>> userAcls) throws ClientException {
    for (String user : userAcls.keySet()) {
        List<Pair<String, Boolean>> acls = new ArrayList<Pair<String, Boolean>>(userAcls.get(user));
        int last = acls.size() - 1;

        // TODO: IF ACLS not contain an ACL that should be first or last,
        // thus showing border, post draw white cells

        for (int i = 0; i < acls.size(); i++) {
            boolean isFirst = false;// (i == 0);
            boolean isLast = false;// (i == last);

            Pair<String, Boolean> ace = acls.get(i);
            String permission = ace.a;
            boolean accept = ace.b;
            int aclColumn = layout.getUserAclColumn(Pair.of(user, permission));
            String aceText = "";// formatAce(ace)

            if (accept) {
                // draws an accept cell
                renderAcceptCell(isFirst, isLast, aclColumn, aceText);
            } else {
                // draws a deny cell
                renderDenyCell(isFirst, isLast, aclColumn, aceText);
            }//from   w w  w  .  ja  v  a  2  s.  c  o  m
        }
        // String info = formatAcl(userAcls.get(user));
    }
}

From source file:org.apache.calcite.rel.metadata.RelMdCollation.java

/** Helper method to determine a {@link Project}'s collation. */
public static List<RelCollation> project(RelMetadataQuery mq, RelNode input, List<? extends RexNode> projects) {
    final SortedSet<RelCollation> collations = new TreeSet<>();
    final List<RelCollation> inputCollations = mq.collations(input);
    if (inputCollations == null || inputCollations.isEmpty()) {
        return ImmutableList.of();
    }//from www  . j av  a 2 s  .co m
    final Multimap<Integer, Integer> targets = LinkedListMultimap.create();
    final Map<Integer, SqlMonotonicity> targetsWithMonotonicity = new HashMap<>();
    for (Ord<RexNode> project : Ord.zip(projects)) {
        if (project.e instanceof RexInputRef) {
            targets.put(((RexInputRef) project.e).getIndex(), project.i);
        } else if (project.e instanceof RexCall) {
            final RexCall call = (RexCall) project.e;
            final RexCallBinding binding = RexCallBinding.create(input.getCluster().getTypeFactory(), call,
                    inputCollations);
            targetsWithMonotonicity.put(project.i, call.getOperator().getMonotonicity(binding));
        }
    }
    final List<RelFieldCollation> fieldCollations = new ArrayList<>();
    loop: for (RelCollation ic : inputCollations) {
        if (ic.getFieldCollations().isEmpty()) {
            continue;
        }
        fieldCollations.clear();
        for (RelFieldCollation ifc : ic.getFieldCollations()) {
            final Collection<Integer> integers = targets.get(ifc.getFieldIndex());
            if (integers.isEmpty()) {
                continue loop; // cannot do this collation
            }
            fieldCollations.add(ifc.copy(integers.iterator().next()));
        }
        assert !fieldCollations.isEmpty();
        collations.add(RelCollations.of(fieldCollations));
    }

    final List<RelFieldCollation> fieldCollationsForRexCalls = new ArrayList<>();
    for (Map.Entry<Integer, SqlMonotonicity> entry : targetsWithMonotonicity.entrySet()) {
        final SqlMonotonicity value = entry.getValue();
        switch (value) {
        case NOT_MONOTONIC:
        case CONSTANT:
            break;
        default:
            fieldCollationsForRexCalls
                    .add(new RelFieldCollation(entry.getKey(), RelFieldCollation.Direction.of(value)));
            break;
        }
    }

    if (!fieldCollationsForRexCalls.isEmpty()) {
        collations.add(RelCollations.of(fieldCollationsForRexCalls));
    }

    return ImmutableList.copyOf(collations);
}

From source file:com.google.javascript.jscomp.newtypes.JSType.java

private static void updateTypemap(Multimap<String, JSType> typeMultimap, String typeParam, JSType type) {
    Preconditions.checkNotNull(type);//from ww  w  .  j a v  a2 s  . c om
    Set<JSType> typesToRemove = new LinkedHashSet<>();
    for (JSType other : typeMultimap.get(typeParam)) {
        JSType unified = unifyUnknowns(type, other);
        if (unified != null) {
            // Can't remove elms while iterating over the collection, so do it later
            typesToRemove.add(other);
            type = unified;
        }
    }
    for (JSType typeToRemove : typesToRemove) {
        typeMultimap.remove(typeParam, typeToRemove);
    }
    typeMultimap.put(typeParam, type);
}

From source file:org.xacml4j.v30.pdp.Policy.java

public Collection<CombinerParameter> getRuleCombinerParam(String ruleId, String name) {
    Multimap<String, CombinerParameter> p = ruleCombiningParameters.get(ruleId);
    return (p == null) ? ImmutableList.<CombinerParameter>of() : p.get(name);
}

From source file:com.google.devtools.build.lib.analysis.config.ConfigurationResolver.java

/**
 * This method allows resolution of configurations outside of a skyfunction call.
 *
 * <p>If {@link BuildConfiguration.Options#trimConfigurations()} is true, transforms a collection
 * of <Target, Configuration> pairs by trimming each target's configuration to only the fragments
 * the target and its transitive dependencies need.
 *
 * <p>Else returns configurations that unconditionally include all fragments.
 *
 * <p>Preserves the original input order (but merges duplicate nodes that might occur due to
 * top-level configuration transitions) . Uses original (untrimmed) configurations for targets
 * that can't be evaluated (e.g. due to loading phase errors).
 *
 * <p>This is suitable for feeding {@link ConfiguredTargetValue} keys: as general principle {@link
 * ConfiguredTarget}s should have exactly as much information in their configurations as they need
 * to evaluate and no more (e.g. there's no need for Android settings in a C++ configured target).
 *
 * @param inputs the original targets and configurations
 * @param asDeps the inputs repackaged as dependencies
 * @param eventHandler//from w  w  w.j a  v a 2s .  com
 * @param skyframeExecutor
 */
// TODO(bazel-team): error out early for targets that fail - untrimmed configurations should
// never make it through analysis (and especially not seed ConfiguredTargetValues)
public static LinkedHashSet<TargetAndConfiguration> getConfigurationsFromExecutor(
        Iterable<TargetAndConfiguration> inputs, Multimap<BuildConfiguration, Dependency> asDeps,
        ExtendedEventHandler eventHandler, SkyframeExecutor skyframeExecutor) throws InterruptedException {

    Map<Label, Target> labelsToTargets = new LinkedHashMap<>();
    for (TargetAndConfiguration targetAndConfig : inputs) {
        labelsToTargets.put(targetAndConfig.getLabel(), targetAndConfig.getTarget());
    }

    // Maps <target, originalConfig> pairs to <target, finalConfig> pairs for targets that
    // could be successfully Skyframe-evaluated.
    Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = new LinkedHashMap<>();
    if (!asDeps.isEmpty()) {
        for (BuildConfiguration fromConfig : asDeps.keySet()) {
            Multimap<Dependency, BuildConfiguration> trimmedTargets = skyframeExecutor
                    .getConfigurations(eventHandler, fromConfig.getOptions(), asDeps.get(fromConfig));
            for (Map.Entry<Dependency, BuildConfiguration> trimmedTarget : trimmedTargets.entries()) {
                Target target = labelsToTargets.get(trimmedTarget.getKey().getLabel());
                successfullyEvaluatedTargets.put(new TargetAndConfiguration(target, fromConfig),
                        new TargetAndConfiguration(target, trimmedTarget.getValue()));
            }
        }
    }

    LinkedHashSet<TargetAndConfiguration> result = new LinkedHashSet<>();
    for (TargetAndConfiguration originalInput : inputs) {
        if (successfullyEvaluatedTargets.containsKey(originalInput)) {
            // The configuration was successfully trimmed.
            result.add(successfullyEvaluatedTargets.get(originalInput));
        } else {
            // Either the configuration couldn't be determined (e.g. loading phase error) or it's null.
            result.add(originalInput);
        }
    }
    return result;
}

From source file:co.mitro.core.server.BeforeAfterState.java

public Map<DBIdentity, UserDiff> diffState() throws SQLException, MitroServletException {
    // get the new state
    Multimap<Integer, Integer> newState = ArrayListMultimap.create();
    addUserDataToSet(userIdToSecretIds.keySet(), newState);

    Map<DBIdentity, UserDiff> rval = Maps.newHashMap();
    for (Integer uid : userIdToSecretIds.keySet()) {
        Set<Integer> preSecrets = Sets.newHashSet(userIdToSecretIds.get(uid));
        Set<Integer> postSecrets = Sets.newHashSet(newState.get(uid));
        UserDiff ud = new UserDiff();
        ud.removedSecrets = Sets.difference(preSecrets, postSecrets);
        ud.newSecrets = Sets.difference(postSecrets, preSecrets);
        if (ud.removedSecrets.isEmpty() && ud.newSecrets.isEmpty()) {
            continue;
        }/*  w  w  w  .  j ava2s .  com*/

        // TODO: optimize this to one query instead of n queries.
        DBIdentity id = manager.identityDao.queryForId(uid);
        ud.userName = id.getName();
        rval.put(id, ud);
    }
    return rval;
}

From source file:org.polarsys.reqcycle.export.transform.TraceabilityExport.java

protected void handleTracea(Multimap<Reachable, Link> traceaMap, Requirement r, List<Attribute> tracea,
        org.polarsys.reqcycle.export.model.ReqCycleExport.Requirement reqCopy) {
    Collection<Link> links = traceaMap.get(getReachable(r));
    for (Link l : links) {
        Traceability t = factory.createTraceability();

        Attribute attribute = getAttribute(tracea, l.getLabel(), String.class.getName());
        AttributeValue val = factory.createAttributeValue();
        val.setValue(getLabel(l.getTargets().iterator().next()));
        val.setAttribute(attribute);

        t.getTraceabilityValues().add(val);

        Collection<EditableAttribute> attributeOfLink = attributesManager.getAttributes(l.getId());
        for (EditableAttribute a : attributeOfLink) {
            Attribute att = getAttribute(tracea, a.getName(), a.getType().getName());
            AttributeValue value = factory.createAttributeValue();
            value.setValue(valueOf(a.getValue()));
            value.setAttribute(att);//from w  ww. j a v  a 2 s.  co  m
            t.getTraceabilityValues().add(value);
        }
        reqCopy.getDownwardTraceability().add(t);
    }
}

From source file:org.apache.james.mpt.onami.test.GuiceMockModule.java

@SuppressWarnings("unchecked")
@Override/* w  w  w .  j av  a  2 s.  c o  m*/
protected void configure() {
    final Multimap<Type, Field> fieldsByType = HashMultimap.create();

    for (final Entry<Field, Object> entry : this.mockedFields.entrySet()) {
        fieldsByType.put(entry.getKey().getGenericType(), entry.getKey());
    }

    for (final Type type : fieldsByType.keySet()) {
        final Collection<Field> fields = fieldsByType.get(type);

        boolean isTypeConflicts = false;
        if (fields.size() != 1) {
            isTypeConflicts = checkTypeConflict(fields);
        }

        checkState(!isTypeConflicts, "   Found multiple annotation @%s for type: %s; binding skipped!.",
                Mock.class.getSimpleName(), type);
        for (final Field field : fields) {
            @SuppressWarnings("rawtypes")
            final TypeLiteral literal = TypeLiteral.get(type);
            final Mock annoBy = field.getAnnotation(Mock.class);
            final Object mock = this.mockedFields.get(field);
            if (annoBy.annotatedWith() != Mock.NoAnnotation.class) {
                bind(literal).annotatedWith(annoBy.annotatedWith()).toInstance(mock);
            } else if (!"".equals(annoBy.namedWith())) {
                bind(literal).annotatedWith(Names.named(annoBy.namedWith())).toInstance(mock);
            } else {
                bind(literal).toInstance(mock);
            }
            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer("    Created binding for: " + type + " " + annoBy);
            }
        }
    }
}

From source file:cherry.foundation.testtool.stub.StubConfigurer.java

public void configure() throws IOException {
    for (Resource r : resources) {
        if (!r.exists()) {
            continue;
        }/* w  w  w  .  java2  s  .c o m*/
        try (InputStream in = r.getInputStream()) {
            Map<Class<?>, Map<String, Object>> map = objectMapper.readValue(in,
                    new TypeReference<LinkedHashMap<Class<?>, Map<String, Object>>>() {
                    });
            for (Map.Entry<Class<?>, Map<String, Object>> entry : map.entrySet()) {
                Multimap<String, Method> methodMap = createMethodMap(entry.getKey().getDeclaredMethods());
                for (Map.Entry<String, Object> ent : entry.getValue().entrySet()) {
                    if (!methodMap.containsKey(ent.getKey())) {
                        continue;
                    }
                    for (Method method : methodMap.get(ent.getKey())) {
                        JavaType type = objectMapper.getTypeFactory()
                                .constructType(method.getGenericReturnType());
                        List<Config> cfglist = parseConfig(ent.getValue());
                        for (Config cfg : cfglist) {
                            Object v = parseValue(cfg, type);
                            if (cfglist.size() == 1) {
                                repository.get(method).alwaysReturn(v);
                            } else {
                                repository.get(method).thenReturn(v);
                            }
                        }
                    }
                }
            }
        }
    }
}