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:nova.core.wrapper.mc.forge.v18.asm.lib.ASMHelper.java

public static byte[] writeMethods(String name, byte[] bytes, Multimap<String, MethodWriter> writers) {
    if (writers.containsKey(name)) {
        ClassNode cnode = createClassNode(bytes);

        for (MethodWriter mw : writers.get(name)) {
            MethodNode mv = findMethod(mw.method, cnode);
            if (mv == null) {
                mv = (MethodNode) cnode.visitMethod(mw.access, mw.method.s_name, mw.method.s_desc, null,
                        mw.exceptions);/* ww w . j av a 2 s .  com*/
            }

            mv.access = mw.access;
            mv.instructions.clear();
            mw.write(mv);
        }

        bytes = createBytes(cnode, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    }
    return bytes;
}

From source file:org.sonar.plsqlopen.checks.verifier.PlSqlCheckVerifier.java

private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected,
        List<Integer> unexpectedLines, AnalyzerMessage issue) {
    int line = issue.getLine();
    if (expected.containsKey(line)) {
        Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line));
        assertEquals(issue.getText(Locale.ENGLISH), attrs, IssueAttribute.MESSAGE);
        validateAnalyzerMessage(attrs, issue);
        expected.remove(line, attrs);/*from ww w .  j a  v  a 2s  .c  o m*/
    } else {
        unexpectedLines.add(line);
    }
}

From source file:nova.core.wrapper.mc.forge.v18.asm.lib.ASMHelper.java

public static byte[] injectMethods(String name, byte[] bytes, Multimap<String, MethodInjector> injectors) {
    if (injectors.containsKey(name)) {
        ClassNode cnode = createClassNode(bytes);

        for (MethodInjector injector : injectors.get(name)) {
            MethodNode method = findMethod(injector.method, cnode);
            if (method == null) {
                throw new RuntimeException("Method not found: " + injector.method);
            }/*from  w w  w.  j  a va 2  s .c  om*/
            System.out.println("Injecting into " + injector.method + "\n" + printInsnList(injector.injection));

            List<AbstractInsnNode> callNodes;
            if (injector.before) {
                callNodes = InstructionComparator.insnListFindStart(method.instructions, injector.needle);
            } else {
                callNodes = InstructionComparator.insnListFindEnd(method.instructions, injector.needle);
            }

            if (callNodes.size() == 0) {
                throw new RuntimeException("Needle not found in Haystack: " + injector.method + "\n"
                        + printInsnList(injector.needle));
            }

            for (AbstractInsnNode node : callNodes) {
                if (injector.before) {
                    System.out.println("Injected before: " + printInsn(node));
                    method.instructions.insertBefore(node, cloneInsnList(injector.injection));
                } else {
                    System.out.println("Injected after: " + printInsn(node));
                    method.instructions.insert(node, cloneInsnList(injector.injection));
                }
            }
        }

        bytes = createBytes(cnode, ClassWriter.COMPUTE_FRAMES);
    }
    return bytes;
}

From source file:rubedo.util.RemapHelper.java

@SuppressWarnings("unchecked")
public static void overwriteEntry(RegistryNamespaced registry, String name, Object object) {

    Object oldThing = registry.getObject(name);
    Repl.overwrite_do(registry, name, object, oldThing);
    Multimap<String, Object> reg = Repl.replacements.get(registry);
    if (reg == null) {
        Repl.replacements.put(registry, reg = ArrayListMultimap.create());
    }/*ww  w .  j a  va 2  s  .  c  o m*/
    if (!reg.containsKey(name)) {
        reg.put(name, oldThing);
    }
    reg.put(name, object);
    Repl.alterDelegateChain(registry, name, object);
}

From source file:com.google.devtools.build.lib.packages.EnvironmentGroup.java

/**
 * Given an environment and set of environments that directly fulfill it, computes a nested
 * set of environments that <i>transitively</i> fulfill it, places it into transitiveFulfillers,
 * and returns that set.//from   w w  w.ja  v a 2 s  . co  m
 */
private static NestedSet<Label> setTransitiveFulfillers(Label env, Multimap<Label, Label> directFulfillers,
        Map<Label, NestedSet<Label>> transitiveFulfillers) {
    if (transitiveFulfillers.containsKey(env)) {
        return transitiveFulfillers.get(env);
    } else if (!directFulfillers.containsKey(env)) {
        // Nobody fulfills this environment.
        NestedSet<Label> emptySet = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
        transitiveFulfillers.put(env, emptySet);
        return emptySet;
    } else {
        NestedSetBuilder<Label> set = NestedSetBuilder.stableOrder();
        for (Label fulfillingEnv : directFulfillers.get(env)) {
            set.add(fulfillingEnv);
            set.addTransitive(setTransitiveFulfillers(fulfillingEnv, directFulfillers, transitiveFulfillers));
        }
        NestedSet<Label> builtSet = set.build();
        transitiveFulfillers.put(env, builtSet);
        return builtSet;
    }
}

From source file:org.sonar.java.checks.verifier.CheckVerifier.java

private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected,
        List<Integer> unexpectedLines, AnalyzerMessage issue,
        @Nullable RemediationFunction remediationFunction) {
    int line = issue.getLine();
    if (expected.containsKey(line)) {
        Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line));
        assertEquals(issue.getMessage(), attrs, IssueAttribute.MESSAGE);
        Double cost = issue.getCost();
        if (cost != null) {
            Preconditions.checkState(remediationFunction != RemediationFunction.CONST,
                    "Rule with constant remediation function shall not provide cost");
            assertEquals(Integer.toString(cost.intValue()), attrs, IssueAttribute.EFFORT_TO_FIX);
        } else if (remediationFunction == RemediationFunction.LINEAR) {
            Fail.fail("A cost should be provided for a rule with linear remediation function");
        }// w  w w . j a  v a2s . c  o m
        validateAnalyzerMessage(attrs, issue);
        expected.remove(line, attrs);
    } else {
        unexpectedLines.add(line);
    }
}

From source file:org.apache.crunch.lib.Quantiles.java

private static <V> Collection<Pair<Double, V>> findQuantiles(Iterator<V> sortedCollectionIterator,
        long collectionSize, List<Double> quantiles) {
    Collection<Pair<Double, V>> output = Lists.newArrayList();
    Multimap<Long, Double> quantileIndices = ArrayListMultimap.create();

    for (double quantile : quantiles) {
        long idx = Math.max((int) Math.ceil(quantile * collectionSize) - 1, 0);
        quantileIndices.put(idx, quantile);
    }/*  w  w  w. j a  v a  2s  . c om*/

    long index = 0;
    while (sortedCollectionIterator.hasNext()) {
        V value = sortedCollectionIterator.next();
        if (quantileIndices.containsKey(index)) {
            for (double quantile : quantileIndices.get(index)) {
                output.add(Pair.of(quantile, value));
            }
        }
        index++;
    }
    return output;
}

From source file:org.jclouds.chef.predicates.CookbookVersionPredicates.java

/**
 * Note that the default recipe of a cookbook is its name. Otherwise, you
 * prefix the recipe with the name of the cookbook. ex. {@code apache2} will
 * be the default recipe where {@code apache2::mod_proxy} is a specific one
 * in the cookbook.//from  w  ww.j ava 2  s  .  c  om
 * 
 * @param recipes
 *           names of the recipes.
 * @return true if the cookbook version contains a recipe in the list.
 */
public static Predicate<CookbookVersion> containsRecipes(String... recipes) {
    checkNotNull(recipes, "recipes must be defined");
    final Multimap<String, String> search = LinkedListMultimap.create();
    for (String recipe : recipes) {
        if (recipe.indexOf("::") != -1) {
            Iterable<String> nameRecipe = Splitter.on("::").split(recipe);
            search.put(get(nameRecipe, 0), get(nameRecipe, 1) + ".rb");
        } else {
            search.put(recipe, "default.rb");
        }
    }
    return new Predicate<CookbookVersion>() {
        @Override
        public boolean apply(final CookbookVersion cookbookVersion) {
            return search.containsKey(cookbookVersion.getCookbookName())
                    && any(search.get(cookbookVersion.getCookbookName()), new Predicate<String>() {

                        @Override
                        public boolean apply(final String recipeName) {
                            return any(cookbookVersion.getRecipes(), new Predicate<Resource>() {

                                @Override
                                public boolean apply(Resource resource) {
                                    return resource.getName().equals(recipeName);
                                }

                            });
                        }

                    });
        }

        @Override
        public String toString() {
            return "containsRecipes(" + search + ")";
        }
    };
}

From source file:org.gradle.model.internal.manage.binding.DefaultStructBindingsStore.java

private static <T> ManagedProperty<T> createManagedProperty(StructBindingExtractionContext<?> extractionContext,
        String propertyName, ModelSchema<T> propertySchema,
        Multimap<PropertyAccessorType, StructMethodBinding> accessors) {
    boolean writable = accessors.containsKey(SETTER);
    boolean declaredAsUnmanaged = isDeclaredAsHavingUnmanagedType(accessors.get(GET_GETTER))
            || isDeclaredAsHavingUnmanagedType(accessors.get(IS_GETTER));
    boolean internal = !extractionContext.getPublicSchema().hasProperty(propertyName);

    validateManagedProperty(extractionContext, propertyName, propertySchema, writable, declaredAsUnmanaged);

    return new ManagedProperty<T>(propertyName, propertySchema.getType(), writable, declaredAsUnmanaged,
            internal);/* w  w w  .j a  va2 s  . com*/
}

From source file:org.kiji.hive.utils.DataRequestOptimizer.java

/**
 * This method propogates the configuration of a family in a KijiDataRequest by replacing
 * it with a page of fully qualified columns with the same configuration.
 *
 * @param kijiDataRequest to use as a base.
 * @param qualifiersPage a page of fully qualified columns to replace families in the original
 *                        data request with.
 * @return A new data request with the appropriate families replaced with the page of fully
 * qualified columns.//from   w w w.  j a v a2 s.  co  m
 */
public static KijiDataRequest expandFamilyWithPagedQualifiers(KijiDataRequest kijiDataRequest,
        Collection<KijiColumnName> qualifiersPage) {

    // Organize the page of column names by family.
    Multimap<String, KijiColumnName> familyToQualifiersMap = ArrayListMultimap.create();
    for (KijiColumnName kijiColumnName : qualifiersPage) {
        familyToQualifiersMap.put(kijiColumnName.getFamily(), kijiColumnName);
    }

    // Build a new data request
    KijiDataRequestBuilder qualifierRequestBuilder = KijiDataRequest.builder();
    for (Column column : kijiDataRequest.getColumns()) {
        KijiColumnName kijiColumnName = column.getColumnName();
        if (kijiColumnName.isFullyQualified()
                || !familyToQualifiersMap.containsKey(kijiColumnName.getFamily())) {
            // If the column is fully qualified or it's not in qualifiersPage add this column as is.
            qualifierRequestBuilder.newColumnsDef(column);
        } else {
            // Iterate through the paged qualifiers and add
            for (KijiColumnName columnName : familyToQualifiersMap.get(kijiColumnName.getFamily())) {
                qualifierRequestBuilder.newColumnsDef().withFilter(column.getFilter())
                        .withPageSize(column.getPageSize()).withMaxVersions(column.getMaxVersions())
                        .add(columnName.getFamily(), columnName.getQualifier());
            }
        }
    }
    return qualifierRequestBuilder.build();
}