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

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

Introduction

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

Prototype

@Override
    public boolean containsKey(@Nullable Object key) 

Source Link

Usage

From source file:google.registry.model.common.TimedTransitionProperty.java

/**
 * Validates that a transition map is not null or empty, starts at START_OF_TIME, and has
 * transitions which move from one value to another in allowed ways.
 *//*from  www  . ja v a2s  . c  o  m*/
public static <V, T extends TimedTransitionProperty.TimedTransition<V>> void validateTimedTransitionMap(
        @Nullable NavigableMap<DateTime, V> transitionMap, ImmutableMultimap<V, V> allowedTransitions,
        String mapName) {
    checkArgument(!nullToEmpty(transitionMap).isEmpty(), "%s map cannot be null or empty.", mapName);
    checkArgument(transitionMap.firstKey().equals(START_OF_TIME), "%s map must start at START_OF_TIME.",
            mapName);

    // Check that all transitions between states are allowed.
    Iterator<V> it = transitionMap.values().iterator();
    V currentState = it.next();
    while (it.hasNext()) {
        checkArgument(allowedTransitions.containsKey(currentState), "%s map cannot transition from %s.",
                mapName, currentState);
        V nextState = it.next();
        checkArgument(allowedTransitions.containsEntry(currentState, nextState),
                "%s map cannot transition from %s to %s.", mapName, currentState, nextState);
        currentState = nextState;
    }
}

From source file:io.jwt.primer.tasks.DeleteStaticTokensTask.java

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter out) throws Exception {
    if (parameters.containsKey("app")) {
        log.info("Deleting static tokens for app: " + parameters.get("app").asList().get(0));
        final String setName = parameters.get("app").asList().get(0) + "_static_tokens";
        log.info("Set Name: " + setName);
        AerospikeConnectionManager.getClient().scanAll(null, aerospikeConfig.getNamespace(), setName,
                (key, record) -> AerospikeConnectionManager.getClient().delete(null, key));
        out.print("Static tokens for app: [" + parameters.get("app").asList().get(0) + "] is being deleted");
    } else {//  w ww.  java2  s  . co  m
        out.print("Parameter[app] missing!");
    }
}

From source file:io.jwt.primer.tasks.DeleteDynamicTokensTask.java

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter out) throws Exception {
    if (parameters.containsKey("app")) {
        log.info("Deleting dynamic tokens for app: " + parameters.get("app").asList().get(0));
        final String setName = parameters.get("app").asList().get(0) + "_tokens";
        log.info("Set Name: " + setName);
        AerospikeConnectionManager.getClient().scanAll(null, aerospikeConfig.getNamespace(), setName,
                (key, record) -> AerospikeConnectionManager.getClient().delete(null, key));
        out.print("Dynamic tokens for app: [" + parameters.get("app").asList().get(0) + "] is being deleted");
    } else {/*from  w  w  w .j a  v  a2s  . com*/
        out.print("Parameter[app] missing!");
    }
}

From source file:com.smoketurner.dropwizard.consul.task.MaintenanceTask.java

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {

    if (!parameters.containsKey("enable")) {
        throw new IllegalArgumentException("Parameter \"enable\" not found");
    }/*from   ww w . j a va  2s . co  m*/

    final boolean enable = Boolean.parseBoolean(parameters.get("enable").asList().get(0));
    final String reason;
    if (parameters.containsKey("reason")) {
        reason = Strings.nullToEmpty(parameters.get("reason").asList().get(0));
    } else {
        reason = "";
    }

    if (enable) {
        if (!Strings.isNullOrEmpty(reason)) {
            LOGGER.warn("Enabling maintenance mode for service {} (reason: {})", serviceId, reason);
        } else {
            LOGGER.warn("Enabling maintenance mode for service {} (no reason given)", serviceId);
        }
    } else {
        LOGGER.warn("Disabling maintenance mode for service {}", serviceId);
    }

    consul.agentClient().toggleMaintenanceMode(serviceId, enable, reason);

    output.println("OK");
    output.flush();
}

From source file:com.facebook.buck.android.AndroidModuleConsistencyStep.java

@Override
public StepExecutionResult execute(ExecutionContext context) {
    try {/*from   ww  w  . j  a va  2 s .  c  om*/
        ProguardTranslatorFactory translatorFactory = ProguardTranslatorFactory.create(filesystem,
                proguardFullConfigFile, proguardMappingFile, skipProguard);
        ImmutableMultimap<String, APKModule> classToModuleMap = APKModuleGraph.getAPKModuleToClassesMap(
                apkModuleToJarPathMap, translatorFactory.createObfuscationFunction(), filesystem).inverse();

        ImmutableMap<String, String> classToModuleResult = AppModularityMetadataUtil
                .getClassToModuleMap(filesystem, metadataInput);

        boolean hasError = false;
        StringBuilder errorMessage = new StringBuilder();

        for (Map.Entry<String, String> entry : classToModuleResult.entrySet()) {
            String className = entry.getKey();
            String resultName = entry.getValue();
            if (classToModuleMap.containsKey(className)) {
                // if the new classMap does not contain the old class, that's fine,
                // consistency is only broken when a class changes to a different module.
                APKModule module = classToModuleMap.get(className).iterator().next();
                if (!module.getName().equals(resultName)) {
                    hasError = true;
                    errorMessage.append(className).append(" moved from App Module: ").append(resultName)
                            .append(" to App Module: ").append(module.getName()).append("\n");
                }
            }
        }

        if (hasError) {
            throw new IllegalStateException(errorMessage.toString());
        }

        return StepExecutionResults.SUCCESS;
    } catch (IOException e) {
        context.logError(e, "There was an error running AndroidModuleConsistencyStep.");
        return StepExecutionResults.ERROR;
    } catch (IllegalStateException e) {
        context.logError(e, "There was an error running AndroidModuleConsistencyStep.");
        return StepExecutionResults.ERROR;
    }
}

From source file:com.android.manifmerger.Actions.java

public String blame(XmlDocument xmlDocument) throws IOException, SAXException, ParserConfigurationException {

    ImmutableMultimap<Integer, Record> resultingSourceMapping = getResultingSourceMapping(xmlDocument);
    LineReader lineReader = new LineReader(new StringReader(xmlDocument.prettyPrint()));

    StringBuilder actualMappings = new StringBuilder();
    String line;/*from  w ww . j a v a2  s  .  c om*/
    int count = 0;
    while ((line = lineReader.readLine()) != null) {
        actualMappings.append(count + 1).append(line).append("\n");
        if (resultingSourceMapping.containsKey(count)) {
            for (Record record : resultingSourceMapping.get(count)) {
                actualMappings.append(count + 1).append("-->").append(record.getActionLocation().toString())
                        .append("\n");
            }
        }
        count++;
    }
    return actualMappings.toString();
}

From source file:com.google.gerrit.server.notedb.ChangeRebuilderImpl.java

@Override
public boolean rebuildProject(ReviewDb db, ImmutableMultimap<Project.NameKey, Change.Id> allChanges,
        Project.NameKey project, Repository allUsersRepo)
        throws NoSuchChangeException, IOException, OrmException, ConfigInvalidException {
    checkArgument(allChanges.containsKey(project));
    boolean ok = true;
    ProgressMonitor pm = new TextProgressMonitor(new PrintWriter(System.out));
    pm.beginTask(FormatUtil.elide(project.get(), 50), allChanges.get(project).size());
    try (NoteDbUpdateManager manager = updateManagerFactory.create(project);
            ObjectInserter allUsersInserter = allUsersRepo.newObjectInserter();
            RevWalk allUsersRw = new RevWalk(allUsersInserter.newReader())) {
        manager.setAllUsersRepo(allUsersRepo, allUsersRw, allUsersInserter,
                new ChainedReceiveCommands(allUsersRepo));
        for (Change.Id changeId : allChanges.get(project)) {
            try {
                buildUpdates(manager, ChangeBundle.fromReviewDb(db, changeId));
            } catch (Throwable t) {
                log.error("Failed to rebuild change " + changeId, t);
                ok = false;/*from w w  w. ja  v a 2s  .c  o m*/
            }
            pm.update(1);
        }
        manager.execute();
    } finally {
        pm.endTask();
    }
    return ok;
}

From source file:com.facebook.presto.AbstractTestQueries.java

@Test
public void testShowFunctions() throws Exception {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedTuple> functions = Multimaps.index(result.getMaterializedTuples(),
            new Function<MaterializedTuple, String>() {
                @Override/*from   w  ww .ja v a2 s  .  c  om*/
                public String apply(MaterializedTuple input) {
                    assertEquals(input.getFieldCount(), 5);
                    return (String) input.getField(0);
                }
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 2);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar (non-deterministic)");

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar, varchar, bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");
}

From source file:com.facebook.presto.tests.AbstractTestQueries.java

@Test
public void testShowFunctions() throws Exception {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(),
            input -> {//from   w  w w  .  j av a2  s . c  o  m
                assertEquals(input.getFieldCount(), 6);
                return (String) input.getField(0);
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 2);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("abs").asList().get(0).getField(4), true);

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("rand").asList().get(0).getField(4), false);

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar, varchar, bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");

    assertFalse(functions.containsKey("like"),
            "Expected function names " + functions + " not to contain 'like'");
}

From source file:io.prestosql.tests.AbstractTestQueries.java

@Test
public void testShowFunctions() {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(),
            input -> {/* www.j  a v  a2 s. c o m*/
                assertEquals(input.getFieldCount(), 6);
                return (String) input.getField(0);
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 6);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(1).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(2).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(3).getField(1), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(2), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(4).getField(1), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(2), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(5).getField(1), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(2), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("abs").asList().get(0).getField(4), true);

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("rand").asList().get(0).getField(4), false);

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar(x)");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar(x), varchar(y), bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");

    assertFalse(functions.containsKey("like"),
            "Expected function names " + functions + " not to contain 'like'");
}