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

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

Introduction

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

Prototype

public ImmutableSet<K> keySet() 

Source Link

Usage

From source file:com.twitter.nodes.Node.java

/**
 * Set dependencies after a Node is constructed using the default constructor,
 * this should only be called by builder. We add all unset optional dependencies and check
 * if all required dependencies are set, if not the Preconditions check will fail.
 *///w  w w  .j  ava 2 s  .c  om
private void setAllDependencies(Map<Enum, Node> depsMap) {
    Preconditions.checkArgument(depsMap != null && !depsMap.isEmpty(), "You can set with empty dependency map");
    ImmutableMap<Enum, Node> allDependencies = addOptionalDeps(depsMap);
    // check if all dependencies are provided
    EnumSet unsetEnums = EnumSet.complementOf(EnumSet.copyOf(allDependencies.keySet()));
    Preconditions.checkArgument(unsetEnums.isEmpty(),
            "Required dependencies not set for node [" + getName() + "]: " + unsetEnums);
    this.dependentNodesByName = allDependencies;
}

From source file:org.glowroot.agent.impl.AdviceCache.java

@EnsuresNonNull({ "reweavableAdvisors", "reweavableConfigVersions", "allAdvisors" })
public void updateAdvisors(/*>>>@UnknownInitialization(AdviceCache.class) AdviceCache this,*/
        List<InstrumentationConfig> reweavableConfigs, boolean cleanTmpDir) throws Exception {
    ImmutableMap<Advice, LazyDefinedClass> advisors = AdviceGenerator.createAdvisors(reweavableConfigs, null,
            true);/*from  w w  w.  j a  va  2  s  . co m*/
    if (instrumentation == null) {
        // this is for tests that don't run with javaagent container
        ClassLoader loader = AdviceCache.class.getClassLoader();
        checkNotNull(loader);
        ClassLoaders.defineClassesInClassLoader(advisors.values(), loader);
    } else {
        File generatedJarDir = new File(baseDir, "tmp");
        if (cleanTmpDir) {
            ClassLoaders.createDirectoryOrCleanPreviousContentsWithPrefix(generatedJarDir, "config-pointcuts");
        }
        if (!advisors.isEmpty()) {
            String suffix = "";
            int count = jarFileCounter.incrementAndGet();
            if (count > 1) {
                suffix = "-" + count;
            }
            File jarFile = new File(generatedJarDir, "config-pointcuts" + suffix + ".jar");
            ClassLoaders.defineClassesInBootstrapClassLoader(advisors.values(), instrumentation, jarFile);
        }
    }
    reweavableAdvisors = advisors.keySet().asList();
    reweavableConfigVersions = createReweavableConfigVersions(reweavableConfigs);
    allAdvisors = ImmutableList.copyOf(Iterables.concat(pluginAdvisors, reweavableAdvisors));
}

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

private void compareRwadefHeaders(List<Header> savedHeadersList, List<Header> translatedHeadersList) {
    if (assertBothNull(savedHeadersList, translatedHeadersList)) {
        return;/*from  w  ww  .  j a v  a  2s.c o  m*/
    }

    ImmutableMap<String, Header> savedHeaders = Maps.uniqueIndex(savedHeadersList,
            new Function<Header, String>() {
                public String apply(Header header) {
                    return header.getName();
                }
            });
    ImmutableMap<String, Header> translatedHeaders = Maps.uniqueIndex(translatedHeadersList,
            new Function<Header, String>() {
                public String apply(Header header) {
                    return header.getName();
                }
            });

    assertEquals(savedHeaders.size(), translatedHeaders.size());
    for (String key : savedHeaders.keySet()) {
        Header savedHeader = savedHeaders.get(key);
        Header translatedHeader = translatedHeaders.get(key);
        assertNotNull(savedHeader);
        assertNotNull(translatedHeader);

        assertEquals(savedHeader.getDefaultValue(), translatedHeader.getDefaultValue());
        assertEquals(savedHeader.getDescription(), translatedHeader.getDescription());
        assertEquals(savedHeader.getType(), translatedHeader.getType());
        assertEquals(savedHeader.isRequired(), translatedHeader.isRequired());
        // TODO: does not exist in Swagger 2.0 yet
        // assertEquals(savedHeader.isAllowMultiple(), translatedHeader.isAllowMultiple());

    }
}

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

private void compareRwadefSections(Contract savedContract, Contract translatedContract) {
    if (assertBothNull(savedContract.getSections(), translatedContract.getSections())) {
        return;//w  w w.  j  a  va  2s. co  m
    }

    ImmutableMap<String, Section> savedSections = Maps.uniqueIndex(savedContract.getSections(),
            new Function<Section, String>() {
                public String apply(Section section) {
                    return section.getName();
                }
            });
    ImmutableMap<String, Section> translatedSections = Maps.uniqueIndex(translatedContract.getSections(),
            new Function<Section, String>() {
                public String apply(Section section) {
                    return section.getName();
                }
            });

    assertEquals(savedSections.size(), translatedSections.size());
    for (String key : savedSections.keySet()) {
        Section savedSection = savedSections.get(key);
        Section translatedSection = translatedSections.get(key);
        assertNotNull(savedSection);
        assertNotNull(translatedSection);
        assertEquals(savedSection.getDescription(), translatedSection.getDescription());
    }
}

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

private void compareRwadefProperties(List<Property> savedPropertiesList,
        List<Property> translatedPropertiesList) {
    if (assertBothNull(savedPropertiesList, translatedPropertiesList)) {
        return;//  ww  w.  j  av  a  2 s.co  m
    }

    ImmutableMap<String, Property> savedProperties = Maps.uniqueIndex(savedPropertiesList,
            new Function<Property, String>() {
                public String apply(Property property) {
                    return property.getName();
                }
            });
    ImmutableMap<String, Property> translatedProperties = Maps.uniqueIndex(translatedPropertiesList,
            new Function<Property, String>() {
                public String apply(Property property) {
                    return property.getName();
                }
            });

    assertEquals(savedProperties.size(), translatedProperties.size());
    for (String key : savedProperties.keySet()) {
        Property savedProperty = savedProperties.get(key);
        Property translatedProperty = translatedProperties.get(key);
        assertNotNull(savedProperty);
        assertNotNull(translatedProperty);

        assertEquals(savedProperty.getDefaultValue(), translatedProperty.getDefaultValue());
        assertEquals(savedProperty.getDescription(), translatedProperty.getDescription());
        assertEquals(savedProperty.getExample(), translatedProperty.getExample());
        assertEquals(savedProperty.getMax(), translatedProperty.getMax());
        assertEquals(savedProperty.getMin(), translatedProperty.getMin());
        assertEquals(savedProperty.getType(), translatedProperty.getType());
        assertEquals(savedProperty.getMaxOccurs(), translatedProperty.getMaxOccurs());
        assertEquals(savedProperty.getMinOccurs(), translatedProperty.getMinOccurs());

        compareRwadefProperties(savedProperty.getProperties(), translatedProperty.getProperties());
        compareStringLists(savedProperty.getEnumeration(), translatedProperty.getEnumeration());
    }
}

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 ww .  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;/* w  ww .  j av a 2s  .c om*/
    }

    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;/*  www . j a  v a  2 s.  co  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;/*from   w ww .j  a  v  a 2  s .  c  o 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:com.facebook.buck.distributed.DistributedCellProviderFactory.java

public static CellProvider create(DistBuildCellParams rootCell,
        ImmutableMap<Path, DistBuildCellParams> cellParams, CellPathResolver rootCellPathResolver,
        UnconfiguredBuildTargetFactory unconfiguredBuildTargetFactory) {
    Map<String, Path> cellPaths = cellParams.values().stream().filter(p -> p.getCanonicalName().isPresent())
            .collect(Collectors.toMap(p -> p.getCanonicalName().get(), p -> p.getFilesystem().getRootPath()));
    ImmutableSet<String> declaredCellNames = ImmutableSet.copyOf(cellPaths.keySet());
    Path rootCellPath = rootCell.getFilesystem().getRootPath();
    DefaultCellPathResolver rootCellResolver = DefaultCellPathResolver.of(rootCellPath, cellPaths);

    return new CellProvider(cellProvider -> CacheLoader.from(cellPath -> {
        DistBuildCellParams cellParam = Objects.requireNonNull(cellParams.get(cellPath),
                "This should only be called for secondary cells.");
        Path currentCellRoot = cellParam.getFilesystem().getRootPath();
        Preconditions.checkState(!currentCellRoot.equals(rootCellPath));
        CellPathResolver currentCellResolver = rootCellResolver;
        // The CellPathResolverView is required because it makes the
        // [RootPath<->CanonicalName] resolver methods non-symmetrical to handle the
        // fact/*  ww w  . j a v  a  2  s.c  om*/
        // that relative main cell from inside a secondary cell resolves actually to
        // secondary cell. If the DefaultCellPathResolver is used, then it would return
        // a BuildTarget as if it belonged to the main cell.
        currentCellResolver = new CellPathResolverView(rootCellResolver, declaredCellNames, currentCellRoot);
        CellPathResolver cellPathResolverForParser = currentCellResolver;
        BuckConfig configWithResolver = cellParam.getConfig()
                .withBuildTargetParser(buildTargetName -> unconfiguredBuildTargetFactory
                        .create(cellPathResolverForParser, buildTargetName));
        RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(configWithResolver,
                cellParam.getBuckModuleManager());
        ToolchainProvider toolchainProvider = new DefaultToolchainProvider(cellParam.getPluginManager(),
                cellParam.getEnvironment(), configWithResolver, cellParam.getFilesystem(),
                cellParam.getProcessExecutor(), cellParam.getExecutableFinder(), ruleKeyConfiguration);

        return ImmutableCell.of(ImmutableSortedSet.copyOf(cellParams.keySet()),
                // Distributed builds don't care about cell names, use a sentinel value that
                // will show up if it actually does care about them.
                cellParam.getCanonicalName(), cellParam.getFilesystem(), configWithResolver, cellProvider,
                toolchainProvider, ruleKeyConfiguration, currentCellResolver);
    }), cellProvider -> RootCellFactory.create(cellProvider, rootCellResolver, rootCellPathResolver,
            rootCell.getFilesystem(), rootCell.getBuckModuleManager(), rootCell.getPluginManager(),
            rootCell.getConfig(), rootCell.getEnvironment(), rootCell.getProcessExecutor(),
            rootCell.getExecutableFinder()));
}