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:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3EnumConstantDiffSimplePrinter.java

/**
 * Prints the changes between two {@link ImmutableList} of {@link Ds3Property}. If both lists are
 * empty, then nothing is printed./*from   w  ww. j  a v  a2s.  c  om*/
 */
private static void printProperties(final ImmutableList<Ds3Property> oldProperties,
        final ImmutableList<Ds3Property> newProperties, final boolean printProperties,
        final WriterHelper writer) {
    if (!printProperties || (isEmpty(oldProperties) && isEmpty(newProperties))) {
        //do not print empty values
        return;
    }
    writer.append(indent(INDENT + 1)).append("Properties:").append("\n");

    final ImmutableSet<String> propertyNames = getPropertyNameUnion(oldProperties, newProperties);
    final ImmutableMap<String, Ds3Property> oldPropertyMap = toPropertyMap(oldProperties);
    final ImmutableMap<String, Ds3Property> newPropertyMap = toPropertyMap(newProperties);

    propertyNames
            .forEach(name -> printPropertyDiff(oldPropertyMap.get(name), newPropertyMap.get(name), writer));
}

From source file:com.spectralogic.ds3client.helpers.ReadJobImpl.java

private static ImmutableCollection<Range> getRangesForBlob(
        final ImmutableMap<String, ImmutableMultimap<BulkObject, Range>> blobToRanges,
        final BulkObject ds3Object) {
    final ImmutableMultimap<BulkObject, Range> ranges = blobToRanges.get(ds3Object.getName());
    if (ranges == null)
        return null;
    return ranges.get(ds3Object);
}

From source file:org.apache.hadoop.yarn.nodelabels.NodeLabelTestBase.java

public static void assertMapEquals(Map<NodeId, Set<String>> expected,
        ImmutableMap<NodeId, Set<String>> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    for (NodeId k : expected.keySet()) {
        Assert.assertTrue(actual.containsKey(k));
        assertCollectionEquals(expected.get(k), actual.get(k));
    }/* w w  w  .ja  va 2 s.  c o  m*/
}

From source file:org.apache.hadoop.yarn.nodelabels.NodeLabelTestBase.java

public static void assertLabelInfoMapEquals(Map<NodeId, Set<NodeLabel>> expected,
        ImmutableMap<NodeId, Set<NodeLabel>> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    for (NodeId k : expected.keySet()) {
        Assert.assertTrue(actual.containsKey(k));
        assertNLCollectionEquals(expected.get(k), actual.get(k));
    }/*from   ww  w  .  j  ava2  s . com*/
}

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

/**
 * Compares two {@link ImmutableList} of {@link Ds3Request}
 * @param oldRequests List of {@link Ds3Request} from the older API
 * @param newRequests List of {@link Ds3Request} from the newer API
 */// ww  w .ja  v  a2s  . c  om
static ImmutableList<AbstractDs3RequestDiff> compareDs3Requests(final ImmutableList<Ds3Request> oldRequests,
        final ImmutableList<Ds3Request> newRequests) {
    final ImmutableSet<String> requestNames = getRequestNameUnion(oldRequests, newRequests);
    final ImmutableMap<String, Ds3Request> oldMap = toRequestMap(oldRequests);
    final ImmutableMap<String, Ds3Request> newMap = toRequestMap(newRequests);

    final Ds3RequestComparator comparator = new Ds3RequestComparatorImpl();
    return requestNames.stream().map(name -> comparator.compare(oldMap.get(name), newMap.get(name)))
            .collect(GuavaCollectors.immutableList());
}

From source file:com.spectralogic.ds3autogen.converters.RemoveDollarSignConverter.java

/**
 * Checks if a type exists within the type map
 * @throws TypeRenamingConflictException Exception thrown if the map contains
 *         a type with the same name but different type
 *//*from  w  w  w .ja va2  s . co m*/
protected static boolean containsType(final String typeName, final Ds3Type type,
        final ImmutableMap<String, Ds3Type> map) {
    if (isEmpty(map)) {
        return false;
    }
    final Ds3Type mapType = map.get(typeName);
    if (mapType == null) {
        return false;
    }
    if (mapType.equals(type)) {
        return true;
    }
    throw new TypeRenamingConflictException(typeName);
}

From source file:com.facebook.buck.versions.VersionedTargetGraphFactory.java

public static VersionedTargetGraph newInstance(Iterable<TargetNode<?, ?>> nodes) {
    Map<BuildTarget, TargetNode<?, ?>> builder = new HashMap<>();
    for (TargetNode<?, ?> node : nodes) {
        builder.put(node.getBuildTarget(), node);
    }//ww  w . ja v  a 2s.  co  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.getDeps()) {
            graph.addEdge(node, Preconditions.checkNotNull(map.get(dep), dep));
        }
    }
    return new VersionedTargetGraph(graph, map, ImmutableSet.of());
}

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

/**
 * Prints the changes between two {@link ImmutableList} of {@link Ds3Param}. If both lists are
 * empty, then nothing is printed./*from ww w.jav  a2  s. c  o  m*/
 * @param label Label describing these parameters, such as RequiredParameters or OptionalParameters
 */
private static void printRequestParameters(final String label, final ImmutableList<Ds3Param> oldParams,
        final ImmutableList<Ds3Param> newParams, final WriterHelper writer) {
    if (isEmpty(oldParams) && isEmpty(newParams)) {
        //do not print empty values
        return;
    }
    writer.append(indent(INDENT)).append(label).append("\n");

    final ImmutableSet<String> paramNames = getParamNameUnion(oldParams, newParams);
    final ImmutableMap<String, Ds3Param> oldParamMap = toParamMap(oldParams);
    final ImmutableMap<String, Ds3Param> newParamMap = toParamMap(newParams);

    paramNames.forEach(name -> printParamDiff(oldParamMap.get(name), newParamMap.get(name), writer));
}

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

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

    final ImmutableSet<String> annotationNames = getAnnotationElementNameUnion(oldElements, newElements);
    final ImmutableMap<String, Ds3AnnotationElement> oldParamMap = toAnnotationElementMap(oldElements);
    final ImmutableMap<String, Ds3AnnotationElement> newParamMap = toAnnotationElementMap(newElements);

    annotationNames
            .forEach(name -> printAnnotationElementDiff(oldParamMap.get(name), newParamMap.get(name), writer));
}

From source file:com.facebook.buck.testutil.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 = BuildTarget.of(node.getBuildTarget().getUnflavoredBuildTarget());
        if (node.getBuildTarget().isFlavored() && !builder.containsKey(unflavoredTarget)) {
            builder.put(unflavoredTarget, node);
        }/*  w  ww. j av  a2 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.getDeps()) {
            graph.addEdge(node, Preconditions.checkNotNull(map.get(dep), dep));
        }
    }
    return new TargetGraph(graph, map, ImmutableSet.of());
}