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

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:cd.go.contrib.elasticagents.docker.DockerContainer.java

private static JobIdentifier jobIdentifier(ContainerInfo containerInfo) {
    ImmutableMap<String, String> labels = containerInfo.config().labels();
    if (labels == null) {
        return null;
    }/*  w ww.  j a  va2s  . com*/
    return JobIdentifier.fromJson(labels.get(JOB_IDENTIFIER_LABEL_KEY));
}

From source file:com.spectralogic.ds3contractcomparator.Ds3ApiSpecComparatorImpl.java

/**
 * Compares two {@link ImmutableMap} of {@link Ds3Type}
 * @param oldTypes Map of {@link Ds3Type} from the older API
 * @param newTypes Map of {@link Ds3Type} from the newer API
 *//*  w w w  .  j a  va  2 s .  c om*/
static ImmutableList<AbstractDs3TypeDiff> compareDs3Types(final ImmutableMap<String, Ds3Type> oldTypes,
        final ImmutableMap<String, Ds3Type> newTypes) {
    final ImmutableSet<String> typeNames = getTypeNameUnion(oldTypes, newTypes);
    final Ds3TypeComparator comparator = new Ds3TypeComparatorImpl();
    return typeNames.stream().map(name -> comparator.compare(oldTypes.get(name), newTypes.get(name)))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.facebook.buck.core.model.targetgraph.TargetGraphFactory.java

/**
 * Like {@link #newInstance(TargetNode[])} but does not also add a node for unflavored version of
 * the given node.//from   w ww  .  ja  v  a  2  s  .c  o  m
 */
public static TargetGraph newInstanceExact(TargetNode<?>... nodes) {
    Map<BuildTarget, TargetNode<?>> builder = new HashMap<>();
    for (TargetNode<?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
    }
    ImmutableMap<BuildTarget, TargetNode<?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getBuildDeps()) {
            graph.addEdge(node, Objects.requireNonNull(map.get(dep), dep::toString));
        }
    }
    return new TargetGraph(graph, map);
}

From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3RequestDiffSimplePrinter.java

/**
 * Prints the changes between two {@link ImmutableList} of {@link Ds3ResponseCode}. If both lists are
 * empty, then nothing is printed./* ww  w. j a  v  a  2 s.com*/
 */
private static void printResponseCodes(final ImmutableList<Ds3ResponseCode> oldCodes,
        final ImmutableList<Ds3ResponseCode> newCodes, final WriterHelper writer) {
    if (isEmpty(oldCodes) && isEmpty(newCodes)) {
        //do not print empty values
        return;
    }
    writer.append(indent(INDENT)).append("ResponseCodes:").append("\n");

    final ImmutableSet<Integer> codes = getResponseCodeUnion(oldCodes, newCodes);
    final ImmutableMap<Integer, Ds3ResponseCode> oldCodeMap = toCodeMap(oldCodes);
    final ImmutableMap<Integer, Ds3ResponseCode> newCodeMap = toCodeMap(newCodes);

    codes.forEach(code -> printResponseCodeDiff(oldCodeMap.get(code), newCodeMap.get(code), writer));
}

From source file:com.facebook.buck.core.model.targetgraph.TargetGraphFactory.java

public static TargetGraph newInstance(Iterable<TargetNode<?>> nodes) {
    Map<BuildTarget, TargetNode<?>> builder = new HashMap<>();
    for (TargetNode<?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
        BuildTarget unflavoredTarget = node.getBuildTarget().withoutFlavors();
        if (node.getBuildTarget().isFlavored() && !builder.containsKey(unflavoredTarget)) {
            builder.put(unflavoredTarget, node.withFlavors(ImmutableSet.of()));
        }/*ww  w  . j  a v  a 2  s . c o  m*/
    }
    ImmutableMap<BuildTarget, TargetNode<?>> map = ImmutableMap.copyOf(builder);

    MutableDirectedGraph<TargetNode<?>> graph = new MutableDirectedGraph<>();
    for (TargetNode<?> node : map.values()) {
        graph.addNode(node);
        for (BuildTarget dep : node.getBuildDeps()) {
            graph.addEdge(node, Objects.requireNonNull(map.get(dep), dep::toString));
        }
    }
    return new TargetGraph(graph, map);
}

From source file:com.spectralogic.ds3autogen.test.helpers.RemoveDollarSignConverterHelper.java

/**
 * Checks if a Type Map generated by the createPopulatedMap function has
 * successfully changed all type names by removing the '$' symbol
 *///w  w w . j a v  a2 s.co  m
public static void checkAutoPopulatedMap(final ImmutableMap<String, Ds3Type> map) {
    assertThat(map.size(), is(2));
    assertTrue(map.containsKey("com.test.package.Ds3Type_v1"));
    assertTrue(map.containsKey("com.test.package.Ds3Type_v2"));

    checkAutoPopulatedType(map.get("com.test.package.Ds3Type_v1"), "_v1");
    checkAutoPopulatedType(map.get("com.test.package.Ds3Type_v2"), "_v2");
}

From source file:com.ikanow.aleph2.logging.utils.LoggingUtils.java

/**
 * Gets the minimal log level for the given subsystem by checking:
 * 1. if logging_overrides has that subsystem as a key
 * 2. if not, checks if there is a default level set
 * 3. if not, uses default_log_level/*from ww w.  jav a 2 s .  c  om*/
 * Then returns if the passed in log level is above the minimal log level or not.
 * 
 * @param level
 * @param logging_overrides
 * @param subsystem
 * @param default_log_level
 * @return
 */
public static boolean meetsLogLevelThreshold(final Level level,
        final ImmutableMap<String, Level> logging_overrides, final String subsystem,
        final Level default_log_level) {
    final Level curr_min_level = Optional.ofNullable(logging_overrides.get(subsystem)).orElseGet(
            () -> (Optional.ofNullable(logging_overrides.get(DEFAULT_LEVEL_KEY)).orElse(default_log_level)));
    return curr_min_level.isLessSpecificThan(level);
}

From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3TypeDiffSimplePrinter.java

/**
 * Prints the changes between two {@link ImmutableList} of {@link Ds3Element}. If both lists are
 * empty, then nothing is printed./*from   ww  w  . j a  v  a  2 s  .  c o  m*/
 */
private static void printElements(final ImmutableList<Ds3Element> oldElements,
        final ImmutableList<Ds3Element> newElements, final WriterHelper writer,
        final boolean printAllAnnotations) {
    if (isEmpty(oldElements) && isEmpty(newElements)) {
        //do not print empty values
        return;
    }
    writer.append(indent(INDENT)).append("Elements:").append("\n");

    final ImmutableSet<String> elementNames = getElementNameUnion(oldElements, newElements);
    final ImmutableMap<String, Ds3Element> oldMap = toElementMap(oldElements);
    final ImmutableMap<String, Ds3Element> newMap = toElementMap(newElements);

    elementNames
            .forEach(name -> printElementDiff(oldMap.get(name), newMap.get(name), writer, printAllAnnotations));
}

From source file:com.cognifide.aet.runner.conversion.SuiteMergeStrategy.java

private static void mergeStep(Step currentStep, Step patternStep) {
    updateComment(currentStep, patternStep);
    currentStep.updatePattern(patternStep.getPattern());

    final ImmutableMap<String, Comparator> comparators = FluentIterable.from(currentStep.getComparators())
            .uniqueIndex(COMPARATOR_TO_MAP);

    for (Comparator patternComparator : patternStep.getComparators()) {
        if (comparators.containsKey(patternComparator.getName())) {
            updateComment(comparators.get(patternComparator.getName()), patternComparator);
        }/*from  w  w  w . j  a  v  a 2s. c o  m*/
    }
}

From source file:com.facebook.buck.cxx.toolchain.CxxPlatformsProviderFactory.java

private static Optional<UnresolvedCxxPlatform> augmentSystemPlatform(Platform platform,
        ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatformsMap, CxxPlatform defaultHostCxxPlatform,
        ImmutableSet<Flavor> possibleHostFlavors, Flavor flavor, CxxBuckConfig cxxConfig) {
    UnresolvedCxxPlatform baseUnresolvedCxxPlatform = cxxSystemPlatformsMap.get(flavor);
    CxxPlatform baseCxxPlatform;/*from  w  w  w  . j av a2s. com*/
    if (baseUnresolvedCxxPlatform == null) {
        if (possibleHostFlavors.contains(flavor)) {
            // If a flavor is for an alternate host, it's safe to skip.
            return Optional.empty();
        }
        LOG.info("Applying \"%s\" overrides to default host platform", flavor);
        baseCxxPlatform = defaultHostCxxPlatform;
    } else {
        if (!(baseUnresolvedCxxPlatform instanceof StaticUnresolvedCxxPlatform)) {
            throw new HumanReadableException("Cannot override non-static cxx platform %s", flavor);
        }
        baseCxxPlatform = ((StaticUnresolvedCxxPlatform) baseUnresolvedCxxPlatform).getCxxPlatform();
    }

    StaticUnresolvedCxxPlatform augmentedPlatform = new StaticUnresolvedCxxPlatform(
            CxxPlatforms.copyPlatformWithFlavorAndConfig(baseCxxPlatform, platform, cxxConfig, flavor));
    return Optional.of(augmentedPlatform);
}