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:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefEndpoints(Definition savedDefinition, Definition translatedDefinition) {
    if (assertBothNull(savedDefinition.getEndpoints(), translatedDefinition.getEndpoints())) {
        return;// w w w .j a va2  s. co m
    }

    ImmutableMap<String, Endpoint> savedEndpoints = Maps.uniqueIndex(savedDefinition.getEndpoints(),
            new Function<Endpoint, String>() {
                public String apply(Endpoint endpoint) {
                    return endpoint.computeUrl();
                }
            });
    ImmutableMap<String, Endpoint> translatedEndpoints = Maps.uniqueIndex(translatedDefinition.getEndpoints(),
            new Function<Endpoint, String>() {
                public String apply(Endpoint endpoint) {
                    return endpoint.computeUrl();
                }
            });
    assertEquals(savedEndpoints.size(), translatedEndpoints.size());
    for (String key : savedEndpoints.keySet()) {
        Endpoint savedEndpoint = savedEndpoints.get(key);
        Endpoint translatedEndpoint = translatedEndpoints.get(key);
        assertNotNull(savedEndpoint);
        assertNotNull(translatedEndpoint);
        assertEquals(savedEndpoint.getAuthenticationProtocol(), translatedEndpoint.getAuthenticationProtocol());
        assertEquals(savedEndpoint.getBasePath(), translatedEndpoint.getBasePath());
        assertEquals(savedEndpoint.getDomain(), translatedEndpoint.getDomain());
        assertEquals(savedEndpoint.getProtocol(), translatedEndpoint.getProtocol());
        assertEquals(savedEndpoint.getPort(), translatedEndpoint.getPort());
    }
}

From source file:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefResponses(Operation savedOperation, Operation translatedOperation) {
    if (assertBothNull(savedOperation.getResponses(), translatedOperation.getResponses())) {
        return;//from   ww w . j a va2  s .co m
    }

    ImmutableMap<Integer, Response> savedResponses = Maps.uniqueIndex(savedOperation.getResponses(),
            new Function<Response, Integer>() {
                public Integer apply(Response response) {
                    return response.getCode();
                }
            });
    ImmutableMap<Integer, Response> translatedResponses = Maps.uniqueIndex(translatedOperation.getResponses(),
            new Function<Response, Integer>() {
                public Integer apply(Response response) {
                    return response.getCode();
                }
            });

    assertEquals(savedResponses.size(), translatedResponses.size());
    for (Integer key : savedResponses.keySet()) {
        Response savedResponse = savedResponses.get(key);
        Response translatedResponse = translatedResponses.get(key);
        assertNotNull(savedResponse);
        assertNotNull(translatedResponse);

        assertEquals(savedResponse.getDescription(), translatedResponse.getDescription());

        // both don't exist in Swagger => can't be retrieved
        // assertEquals(savedResponse.getMessage(), translatedResponse.getMessage());
        // assertEquals(savedResponse.getName(), translatedResponse.getName());

        compareRwadefHeaders(savedResponse.getHeaders(), translatedResponse.getHeaders());
        compareRwadefPayloads(savedResponse.getOutputPayLoad(), translatedResponse.getOutputPayLoad());
    }
}

From source file:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefResources(Contract savedContract, Contract translatedContract) {
    if (assertBothNull(savedContract.getResources(), translatedContract.getResources())) {
        return;//  w  w w . j ava2s .c o  m
    }

    ImmutableMap<String, Resource> savedResources = Maps.uniqueIndex(savedContract.getResources(),
            new Function<Resource, String>() {
                public String apply(Resource resource) {
                    return resource.getResourcePath();
                }
            });
    ImmutableMap<String, Resource> translatedResources = Maps.uniqueIndex(translatedContract.getResources(),
            new Function<Resource, String>() {
                public String apply(Resource resource) {
                    return resource.getResourcePath();
                }
            });

    assertEquals(savedResources.size(), translatedResources.size());
    for (String key : savedResources.keySet()) {
        Resource savedResource = savedResources.get(key);
        Resource translatedResource = translatedResources.get(key);
        assertNotNull(savedResource);
        assertNotNull(translatedResource);

        assertEquals(savedResource.getDescription(), translatedResource.getDescription());
        assertEquals(savedResource.getAuthenticationProtocol(), translatedResource.getAuthenticationProtocol());
        assertEquals(savedResource.getName(), translatedResource.getName());
        compareStringLists(savedResource.getSections(), translatedResource.getSections());

        compareRwadefPathVariables(savedResource, translatedResource);
        compareRwadefOperations(savedResource, translatedResource);
    }
}

From source file:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefOperations(Resource savedResource, Resource translatedResource) {
    if (assertBothNull(savedResource.getOperations(), translatedResource.getOperations())) {
        return;//  w w  w . jav a  2s  .  co m
    }

    ImmutableMap<String, Operation> savedOperations = Maps.uniqueIndex(savedResource.getOperations(),
            new Function<Operation, String>() {
                public String apply(Operation operation) {
                    return operation.getName();
                }
            });
    ImmutableMap<String, Operation> translatedOperations = Maps.uniqueIndex(translatedResource.getOperations(),
            new Function<Operation, String>() {
                public String apply(Operation operation) {
                    return operation.getName();
                }
            });

    assertEquals(savedOperations.size(), translatedOperations.size());
    for (String key : savedOperations.keySet()) {
        Operation savedOperation = savedOperations.get(key);
        Operation translatedOperation = translatedOperations.get(key);
        assertNotNull(savedOperation);
        assertNotNull(translatedOperation);

        assertEquals(savedOperation.getDescription(), translatedOperation.getDescription());
        assertEquals(savedOperation.getMethod(), translatedOperation.getMethod());

        compareRwadefHeaders(savedOperation.getHeaders(), translatedOperation.getHeaders());
        compareRwadefQueryParameters(savedOperation, translatedOperation);
        compareRwadefPayloads(savedOperation.getInputPayLoad(), translatedOperation.getInputPayLoad());
        compareRwadefResponses(savedOperation, translatedOperation);

        compareStringLists(savedOperation.getProduces(), translatedOperation.getProduces());
        compareStringLists(savedOperation.getConsumes(), translatedOperation.getConsumes());
    }
}

From source file:se.sics.caracaldb.global.DefaultPolicy.java

private void replaceFailedNodes(LUTWorkingBuffer lut, ImmutableSortedMap<Integer, Address> failIds,
        ImmutableSortedMap<Integer, Address> joinIds, ExtremeKMap<Double, Address> xKMemory,
        ExtremeKMap<Double, Address> xKCpu, ImmutableMap<Address, Stats.Report> stats) {

    TreeSet<Integer> idsToDealWith = new TreeSet<Integer>(failIds.keySet());
    TreeMultimap<Long, Integer> candidates = TreeMultimap.create();
    // If a node fails and rejoins immediately, assign the same id and don't touch 
    // its replicationSets, since it may still have data from before the failure
    for (Entry<Integer, Address> e : joinIds.entrySet()) {
        Address curNode = lut.lut.getHost(e.getKey());
        if (curNode.equals(e.getValue())) {
            idsToDealWith.remove(e.getKey());
            candidates.put(0l, e.getKey());
        }/*from   w  w  w.ja v  a  2  s . c  o m*/
    }
    // Add nodes with lowest resource usage to candidates
    ImmutableSet.Builder<Address> candidateAddrs = ImmutableSet.builder(); // still need to look up their ids
    candidateAddrs.addAll(xKMemory.bottom().values()).addAll(xKCpu.bottom().values()).build();
    Map<Address, Integer> candidateIds = lut.lut.getIdsForAddresses(candidateAddrs.build());
    for (Entry<Address, Integer> e : candidateIds.entrySet()) {
        Address addr = e.getKey();
        Integer id = e.getValue();
        Stats.Report rep = stats.get(addr);
        long curSize = rep.averageSize * rep.numberOfVNodes;
        candidates.put(curSize, id);
    }
    // Replace nodes in affected sets
    int index = 0;
    for (Integer[] member : lut.replicationSets()) {
        Integer[] newRepSet = Arrays.copyOf(member, member.length);
        for (int pos = 0; pos < member.length; pos++) {
            if (idsToDealWith.contains(member[pos])) {
                long lowestSize = candidates.keySet().first();
                if (lowestSize > averageHostSize) {
                    addMoreCandidates(lut, candidates, stats);
                }
                // pick the first (lowestSize) host not in the replicationSet
                long curSize = -1;
                long addedSize = -1;
                for (Entry<Long, Integer> e : candidates.entries()) {
                    if (LookupTable.positionInSet(newRepSet, e.getValue()) < 0) {
                        newRepSet[pos] = e.getValue();
                        curSize = e.getKey();
                        addedSize = guessAddedSize(lut, member, stats);
                        break;
                    }
                }
                if ((curSize < 0) || (addedSize < 0)) {
                    LOG.error("Could not find any candidate for replacing {} in replicationSet {}!",
                            member[pos], index);
                    continue;
                }
                // Update candidates
                candidates.remove(curSize, newRepSet[pos]);
                candidates.put(curSize + addedSize, newRepSet[pos]);
            }
        }
        if (!Arrays.equals(member, newRepSet)) {
            lut.putRepSet(index, newRepSet);
        }
        index++;
    }
}

From source file:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefPathVariables(Resource savedResource, Resource translatedResource) {
    if (assertBothNull(savedResource.getPathVariables(), translatedResource.getPathVariables())) {
        return;//  ww w  .  j a va2s. c  o  m
    }

    ImmutableMap<String, PathVariable> savedPathVariables = Maps.uniqueIndex(savedResource.getPathVariables(),
            new Function<PathVariable, String>() {
                public String apply(PathVariable pathVariable) {
                    return pathVariable.getName();
                }
            });
    ImmutableMap<String, PathVariable> translatedPathVariables = Maps
            .uniqueIndex(translatedResource.getPathVariables(), new Function<PathVariable, String>() {
                public String apply(PathVariable pathVariable) {
                    return pathVariable.getName();
                }
            });

    assertEquals(savedPathVariables.size(), translatedPathVariables.size());
    for (String key1 : savedPathVariables.keySet()) {
        PathVariable savedPathVariable = savedPathVariables.get(key1);
        PathVariable translatedPathVariable = translatedPathVariables.get(key1);
        assertNotNull(savedPathVariable);
        assertNotNull(translatedPathVariable);

        assertEquals(savedPathVariable.getDescription(), translatedPathVariable.getDescription());
        assertEquals(savedPathVariable.getExample(), translatedPathVariable.getExample());
        assertEquals(savedPathVariable.getType(), translatedPathVariable.getType());
        assertEquals(savedPathVariable.isRequired(), translatedPathVariable.isRequired());
    }
}

From source file:dagger2.internal.codegen.ComponentGenerator.java

private Snippet initializeMembersInjectorForBinding(ClassName componentName, MembersInjectionBinding binding,
        ImmutableMap<BindingKey, MemberSelect> memberSelectSnippets) {
    switch (binding.injectionStrategy()) {
    case NO_OP:/*  w w w.  j  a v  a2  s  .  c  o  m*/
        return Snippet.format("%s.noOp()", ClassName.fromClass(MembersInjectors.class));
    case DELEGATE:
        DependencyRequest parentInjectorRequest = binding.parentInjectorRequest().get();
        return Snippet.format("%s.delegatingTo(%s)", ClassName.fromClass(MembersInjectors.class),
                memberSelectSnippets.get(parentInjectorRequest.bindingKey()).getSnippetFor(componentName));
    case INJECT_MEMBERS:
        List<Snippet> parameters = getDependencyParameters(componentName, binding.implicitDependencies(),
                memberSelectSnippets);
        return Snippet.format("%s.create(%s)", membersInjectorNameForMembersInjectionBinding(binding),
                Snippet.makeParametersSnippet(parameters));
    default:
        throw new AssertionError();
    }
}

From source file:org.restlet.test.ext.apispark.conversion.swagger.v2_0.Swagger2TestCase.java

private void compareRwadefQueryParameters(Operation savedOperation, Operation translatedOperation) {
    if (assertBothNull(savedOperation.getQueryParameters(), translatedOperation.getQueryParameters())) {
        return;//from  w  w  w  .  ja va2s.  co m
    }

    ImmutableMap<String, QueryParameter> savedQueryParameters = Maps
            .uniqueIndex(savedOperation.getQueryParameters(), new Function<QueryParameter, String>() {
                public String apply(QueryParameter header) {
                    return header.getName();
                }
            });
    ImmutableMap<String, QueryParameter> translatedQueryParameters = Maps
            .uniqueIndex(translatedOperation.getQueryParameters(), new Function<QueryParameter, String>() {
                public String apply(QueryParameter header) {
                    return header.getName();
                }
            });

    assertEquals(savedQueryParameters.size(), translatedQueryParameters.size());
    for (String key : savedQueryParameters.keySet()) {
        QueryParameter savedQueryParameter = savedQueryParameters.get(key);
        QueryParameter translatedQueryParameter = translatedQueryParameters.get(key);
        assertNotNull(savedQueryParameter);
        assertNotNull(translatedQueryParameter);

        assertEquals(savedQueryParameter.getDefaultValue(), translatedQueryParameter.getDefaultValue());
        assertEquals(savedQueryParameter.getDescription(), translatedQueryParameter.getDescription());
        assertEquals(savedQueryParameter.getType(), translatedQueryParameter.getType());
        assertEquals(savedQueryParameter.getExample(), translatedQueryParameter.getExample());
        assertEquals(savedQueryParameter.getSeparator(), translatedQueryParameter.getSeparator());
        assertEquals(savedQueryParameter.isRequired(), translatedQueryParameter.isRequired());
        // TODO: not available in Swagger 2.0
        // assertEquals(savedQueryParameter.isAllowMultiple(), translatedQueryParameter.isAllowMultiple());
        compareStringLists(savedQueryParameter.getEnumeration(), translatedQueryParameter.getEnumeration());
    }
}

From source file:annis.sqlgen.FrequencySqlGenerator.java

private Multimap<FrequencyTableEntry, String> conditionsForEntries(List<FrequencyTableEntry> frequencyEntries,
        QueryData queryData, List<QueryNode> alternative) {
    Multimap<FrequencyTableEntry, String> conditions = LinkedHashMultimap.create();
    int i = 1;//from w  w w.  ja v  a2 s  .co  m

    ImmutableMap<String, QueryNode> idxNodeVariables = Maps.uniqueIndex(alternative.iterator(),
            new Function<QueryNode, String>() {
                @Override
                public String apply(QueryNode input) {
                    return input.getVariable();
                }
            });

    for (FrequencyTableEntry e : frequencyEntries) {
        if (e.getType() == FrequencyTableEntryType.meta) {
            List<String> qName = Splitter.on(':').limit(2).omitEmptyStrings().splitToList(e.getKey());
            if (qName.size() == 2) {
                conditions.put(e, "v" + i + ".namespace = '" + escaper.escape(qName.get(0)) + "'");
                conditions.put(e, "v" + i + ".name = '" + escaper.escape(qName.get(1)) + "'");
            } else {
                conditions.put(e, "v" + i + ".name = '" + escaper.escape(qName.get(0)) + "'");
            }
            conditions.put(e, "v" + i + ".corpus_ref = solutions.corpus_ref");
        } else {
            // general partition restriction
            conditions.put(e,
                    "v" + i + ".toplevel_corpus IN (" + StringUtils.join(queryData.getCorpusList(), ",") + ")");
            // specificly join on top level corpus
            conditions.put(e, "v" + i + ".toplevel_corpus = solutions.toplevel_corpus");

            // join on node ID
            QueryNode referencedNode = idxNodeVariables.get(e.getReferencedNode());
            if (referencedNode == null) {
                throw new AnnisQLSemanticsException("No such node \"" + e.getReferencedNode() + "\". "
                        + "Your query contains " + alternative.size()
                        + " node(s), make sure no node definition numbers are greater than this number");
            }
            conditions.put(e, "v" + i + ".id = solutions.id" + referencedNode.getId());

            if (e.getType() == FrequencyTableEntryType.span) {
                conditions.put(e, "v" + i + ".n_sample IS TRUE");
            } else if (e.getType() == FrequencyTableEntryType.annotation) {
                // TODO: support namespaces
                // filter by selected key
                conditions.put(e, "v" + i + ".node_annotext LIKE '"
                        + AnnotationConditionProvider.likeEscaper.escape(e.getKey()) + ":%'");
                conditions.put(e, "v" + i + ".n_na_sample IS TRUE");
            }
        }
        i++;
    }
    return conditions;
}

From source file:com.facebook.buck.apple.xcode.ProjectGenerator.java

private void addSourcePathToSourcesBuildPhase(SourcePath sourcePath, PBXGroup sourcesGroup,
        PBXSourcesBuildPhase sourcesBuildPhase, ImmutableMap<SourcePath, String> sourceFlags) {
    Path path = sourcePath.resolve();
    PBXFileReference fileReference = sourcesGroup.getOrCreateFileReferenceBySourceTreePath(new SourceTreePath(
            PBXReference.SourceTree.SOURCE_ROOT, this.repoRootRelativeToOutputDirectory.resolve(path)));
    PBXBuildFile buildFile = new PBXBuildFile(fileReference);
    sourcesBuildPhase.getFiles().add(buildFile);
    String customFlags = sourceFlags.get(sourcePath);
    if (customFlags != null) {
        NSDictionary settings = new NSDictionary();
        settings.put("COMPILER_FLAGS", customFlags);
        buildFile.setSettings(Optional.of(settings));
    }/*from   w w w  . j  av a 2 s . c  o m*/
}