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

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

Introduction

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

Prototype

public final ImmutableSet<Entry<K, V>> entrySet() 

Source Link

Usage

From source file:org.apache.cloudstack.outofbandmanagement.driver.ipmitool.IpmitoolWrapper.java

public List<String> getIpmiToolCommandArgs(final String ipmiToolPath, final String ipmiInterface,
        final String retries, final ImmutableMap<OutOfBandManagement.Option, String> options,
        String... commands) {//from w  ww.j av a 2  s  . c om

    final ImmutableList.Builder<String> ipmiToolCommands = ImmutableList.<String>builder().add(ipmiToolPath)
            .add("-I").add(ipmiInterface).add("-R").add(retries).add("-v");

    if (options != null) {
        for (ImmutableMap.Entry<OutOfBandManagement.Option, String> option : options.entrySet()) {
            switch (option.getKey()) {
            case ADDRESS:
                ipmiToolCommands.add("-H");
                break;
            case PORT:
                ipmiToolCommands.add("-p");
                break;
            case USERNAME:
                ipmiToolCommands.add("-U");
                break;
            case PASSWORD:
                ipmiToolCommands.add("-P");
                break;
            default:
                continue;
            }
            ipmiToolCommands.add(option.getValue());
        }
    }
    for (String command : commands) {
        ipmiToolCommands.add(command);
    }
    return ipmiToolCommands.build();
}

From source file:com.isotrol.impe3.pms.core.obj.ConfigurationObject.java

/**
 * Transforms the object to a protocol buffer message.
 * @param fileManager Required in order to recover file content.
 * @return The PB message.//from w  w w  .j a v a  2 s .  c o m
 */
final ConfigurationPB toPB(FileManager fileManager) {
    ConfigurationPB.Builder b = ConfigurationPB.newBuilder();

    final ImmutableMap<String, Item> parameters = definition.getParameters();

    for (Entry<String, Item> entry : parameters.entrySet()) {
        final Item item = entry.getValue();
        if (item != null) {
            final String name = entry.getKey();
            b.addConfigurationValues(configurationValuePB(name, item, fileManager));
        }
    }

    return b.build();
}

From source file:com.google.devtools.build.lib.exec.SpawnActionContextMaps.java

/**
 * Print a sorted list of our (Spawn)ActionContext maps.
 *
 * <p>Prints out debug information about the mappings.
 */// w w  w . ja  v  a2  s . c o  m
public void debugPrintSpawnActionContextMaps(Reporter reporter) {
    for (Map.Entry<String, SpawnActionContext> entry : spawnStrategyMnemonicMap.entrySet()) {
        reporter.handle(Event.info(String.format("SpawnActionContextMap: \"%s\" = %s", entry.getKey(),
                entry.getValue().getClass().getSimpleName())));
    }

    ImmutableMap<Class<? extends ActionContext>, ActionContext> contextMap = contextMap();
    TreeMap<String, String> sortedContextMapWithSimpleNames = new TreeMap<>();
    for (Map.Entry<Class<? extends ActionContext>, ActionContext> entry : contextMap.entrySet()) {
        sortedContextMapWithSimpleNames.put(entry.getKey().getSimpleName(),
                entry.getValue().getClass().getSimpleName());
    }
    for (Map.Entry<String, String> entry : sortedContextMapWithSimpleNames.entrySet()) {
        // Skip uninteresting identity mappings of contexts.
        if (!entry.getKey().equals(entry.getValue())) {
            reporter.handle(Event.info(String.format("ContextMap: %s = %s", entry.getKey(), entry.getValue())));
        }
    }

    for (RegexFilterSpawnActionContext entry : spawnStrategyRegexList) {
        reporter.handle(Event.info(String.format("SpawnActionContextMap: \"%s\" = %s",
                entry.regexFilter().toString(), entry.spawnActionContext().getClass().getSimpleName())));
    }
}

From source file:net.sourceforge.jwbf.core.actions.HttpActionClient.java

@VisibleForTesting
String post(HttpRequestBase requestBase //
        , ReturningTextProcessor contentProcessable, HttpAction ha) {
    Post post = (Post) ha;//from  w  ww .  j a  v a2 s .  c  o m
    Charset charset = Charset.forName(post.getCharset());
    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    ImmutableMap<String, Object> postParams = post.getParams();
    for (Map.Entry<String, Object> entry : postParams.entrySet()) {
        applyToEntityBuilder(entry.getKey(), entry.getValue(), charset, entityBuilder);
    }
    ((HttpPost) requestBase).setEntity(entityBuilder.build());

    return executeAndProcess(requestBase, contentProcessable, ha);
}

From source file:dollar.internal.runtime.script.obj.DollarObject.java

@Override
public ImmutableList<String> toStrings() {
    List<String> values = new ArrayList<>();
    ImmutableMap<String, Object> map = toJavaMap();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        assert entry.getKey() != null;
        values.add(entry.getKey());/*from w ww  .  j  av  a  2  s  .c o m*/
        values.add(entry.getValue().toString());
    }
    return ImmutableList.copyOf(values);
}

From source file:io.fabric8.container.process.ProcessControllerFactoryService.java

protected void checkProcessesStatus() {
    ProcessManager manager = getProcessManager();
    FabricService fabric = getFabricService();
    if (manager != null && fabric != null) {
        Set<String> aliveIds = new HashSet<>();
        ImmutableMap<String, Installation> map = manager.listInstallationMap();
        ImmutableSet<Map.Entry<String, Installation>> entries = map.entrySet();
        for (Map.Entry<String, Installation> entry : entries) {
            String id = entry.getKey();
            Installation installation = entry.getValue();
            try {
                Container container = null;
                try {
                    container = fabric.getContainer(id);
                } catch (Exception e) {
                    LOG.debug("No container for id: " + id + ". " + e, e);
                }/*from ww w. ja v a2s.  c o  m*/
                if (container != null) {
                    Long pid = installation.getActivePid();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Polling container " + id + " for its PID");
                    }
                    if (pid == null) {
                        if (container.isAlive()) {
                            container.setAlive(false);
                        }
                    } else if (pid != null && pid != 0) {
                        if (!container.isAlive()) {
                            container.setAlive(true);
                        }
                        if (!Objects.equal(container.getProvisionResult(), Container.PROVISION_SUCCESS)) {
                            container.setProvisionResult(Container.PROVISION_SUCCESS);
                        }
                        aliveIds.add(id);

                        Map<String, String> envVars = ProcessManagerController
                                .getInstallationProxyPorts(installation);
                        List<String> newZkPaths = JolokiaAgentHelper.jolokiaKeepAliveCheck(zkMasterCache,
                                fabric, container, envVars);
                        if (!newZkPaths.isEmpty()) {
                            ChildContainerController controller = getControllerForContainer(container);
                            if (controller instanceof ProcessManagerController) {
                                ProcessManagerController processManagerController = (ProcessManagerController) controller;
                                addZooKeeperPaths(installation, container, newZkPaths);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                LOG.warn("Failed to get PID for process " + id + ". " + e, e);
            }
        }
        deleteContainerPathsForDeadContainers(aliveIds);
    }
}

From source file:com.facebook.buck.features.python.PexStep.java

/**
 * Return the manifest as a JSON blob to write to the pex processes stdin.
 *
 * <p>We use stdin rather than passing as an argument to the processes since manifest files can
 * occasionally get extremely large, and surpass exec/shell limits on arguments.
 *//*  w w  w  .j  a  va 2s .c o  m*/
@Override
protected Optional<String> getStdin(ExecutionContext context) throws InterruptedException {
    // Convert the map of paths to a map of strings before converting to JSON.
    ImmutableMap<Path, Path> resolvedModules;
    try {
        resolvedModules = getExpandedSourcePaths(context.getProjectFilesystemFactory(), modules);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ImmutableMap.Builder<String, String> modulesBuilder = ImmutableMap.builder();
    for (ImmutableMap.Entry<Path, Path> ent : resolvedModules.entrySet()) {
        modulesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
    }
    addResolvedModuleDirsSources(modulesBuilder);

    ImmutableMap.Builder<String, String> resourcesBuilder = ImmutableMap.builder();
    for (ImmutableMap.Entry<Path, Path> ent : resources.entrySet()) {
        resourcesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
    }
    ImmutableMap.Builder<String, String> nativeLibrariesBuilder = ImmutableMap.builder();
    for (ImmutableMap.Entry<Path, Path> ent : nativeLibraries.entrySet()) {
        nativeLibrariesBuilder.put(ent.getKey().toString(), ent.getValue().toString());
    }

    try {
        return Optional.of(ObjectMappers.WRITER
                .writeValueAsString(ImmutableMap.of("modules", modulesBuilder.build(), "resources",
                        resourcesBuilder.build(), "nativeLibraries", nativeLibrariesBuilder.build(),
                        // prebuiltLibraries key kept for compatibility
                        "prebuiltLibraries", ImmutableList.<String>of())));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.addthis.hydra.job.web.resources.GroupsResource.java

private void logDiskQuotas() {
    try {//from   w  w  w  .  j  a  va 2s.c o m
        if (logDirectory == null) {
            return;
        }
        Files.createDirectories(logDirectory);
        Path logfile = logDirectory.resolve(LOG_FILENAME);
        long timestamp = System.currentTimeMillis();
        ImmutableMap<String, Double> summary = this.diskSummary;
        try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(logfile, StandardOpenOption.CREATE,
                StandardOpenOption.WRITE, StandardOpenOption.APPEND))) {
            for (Map.Entry<String, Double> entry : summary.entrySet()) {
                writer.printf("%d\t%s\t%.3f%n", timestamp, entry.getKey(), entry.getValue());
            }
        }
    } catch (Exception ex) {
        log.warn("Error logging group resource: ", ex);
    }
}

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

@Override
ImmutableSet<JavaWriter> write(ClassName generatedTypeName, MembersInjectionBinding binding) {
    // We don't want to write out resolved bindings -- we want to write out the generic version.
    checkState(!binding.hasNonDefaultTypeParameters());

    TypeName injectedTypeName = TypeNames.forTypeMirror(binding.key().type());
    JavaWriter writer = JavaWriter.inPackage(generatedTypeName.packageName());

    ClassWriter injectorWriter = writer.addClass(generatedTypeName.simpleName());
    List<TypeVariableName> typeParameters = Lists.newArrayList();
    for (TypeParameterElement typeParameter : binding.bindingTypeElement().getTypeParameters()) {
        typeParameters.add(TypeVariableName.fromTypeParameterElement(typeParameter));
    }// ww  w. j  a va 2s.  c om
    injectorWriter.addTypeParameters(typeParameters);
    injectorWriter.annotate(Generated.class).setValue(ComponentProcessor.class.getCanonicalName());
    injectorWriter.addModifiers(PUBLIC, FINAL);
    TypeName implementedType = ParameterizedTypeName.create(MembersInjector.class, injectedTypeName);
    injectorWriter.addImplementedType(implementedType);

    ConstructorWriter constructorWriter = injectorWriter.addConstructor();
    constructorWriter.addModifiers(PUBLIC);
    MethodWriter injectMembersWriter = injectorWriter.addMethod(VoidName.VOID, "injectMembers");
    injectMembersWriter.addModifiers(PUBLIC);
    injectMembersWriter.annotate(Override.class);
    injectMembersWriter.addParameter(injectedTypeName, "instance");
    injectMembersWriter.body().addSnippet(Joiner.on('\n').join("if (instance == null) {",
            "  throw new NullPointerException(\"Cannot inject members into a null reference\");", "}"));

    Optional<DeclaredType> supertype = MoreTypes.nonObjectSuperclass(types, elements,
            MoreTypes.asDeclared(binding.key().type()));
    if (supertype.isPresent()) {
        ParameterizedTypeName supertypeMemebersInjectorType = ParameterizedTypeName
                .create(MembersInjector.class, TypeNames.forTypeMirror(supertype.get()));
        injectorWriter.addField(supertypeMemebersInjectorType, "supertypeInjector").addModifiers(PRIVATE,
                FINAL);
        constructorWriter.addParameter(supertypeMemebersInjectorType, "supertypeInjector");
        constructorWriter.body().addSnippet("assert supertypeInjector != null;")
                .addSnippet("this.supertypeInjector = supertypeInjector;");
        injectMembersWriter.body().addSnippet("supertypeInjector.injectMembers(instance);");
    }

    ImmutableMap<BindingKey, FrameworkField> fields = SourceFiles.generateBindingFieldsForDependencies(
            dependencyRequestMapper, ImmutableSet.copyOf(binding.dependencies()));

    ImmutableMap.Builder<BindingKey, FieldWriter> dependencyFieldsBuilder = ImmutableMap.builder();

    for (Entry<BindingKey, FrameworkField> fieldEntry : fields.entrySet()) {
        FrameworkField bindingField = fieldEntry.getValue();
        TypeName fieldType = bindingField.frameworkType();
        FieldWriter field = injectorWriter.addField(fieldType, bindingField.name());
        field.addModifiers(PRIVATE, FINAL);
        constructorWriter.addParameter(field.type(), field.name());
        constructorWriter.body().addSnippet("assert %s != null;", field.name());
        constructorWriter.body().addSnippet("this.%1$s = %1$s;", field.name());
        dependencyFieldsBuilder.put(fieldEntry.getKey(), field);
    }

    // We use a static create method so that generated components can avoid having
    // to refer to the generic types of the factory.
    // (Otherwise they may have visibility problems referring to the types.)
    MethodWriter createMethodWriter = injectorWriter.addMethod(implementedType, "create");
    createMethodWriter.addTypeParameters(typeParameters);
    createMethodWriter.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
    Map<String, TypeName> params = constructorWriter.parameters();
    for (Map.Entry<String, TypeName> param : params.entrySet()) {
        createMethodWriter.addParameter(param.getValue(), param.getKey());
    }
    createMethodWriter.body().addSnippet("  return new %s(%s);",
            parameterizedMembersInjectorNameForMembersInjectionBinding(binding),
            Joiner.on(", ").join(params.keySet()));

    ImmutableMap<BindingKey, FieldWriter> depedencyFields = dependencyFieldsBuilder.build();
    for (InjectionSite injectionSite : binding.injectionSites()) {
        switch (injectionSite.kind()) {
        case FIELD:
            DependencyRequest fieldDependency = Iterables.getOnlyElement(injectionSite.dependencies());
            FieldWriter singleField = depedencyFields.get(fieldDependency.bindingKey());
            injectMembersWriter.body().addSnippet("instance.%s = %s;", injectionSite.element().getSimpleName(),
                    frameworkTypeUsageStatement(Snippet.format(singleField.name()), fieldDependency.kind()));
            break;
        case METHOD:
            ImmutableList.Builder<Snippet> parameters = ImmutableList.builder();
            for (DependencyRequest methodDependency : injectionSite.dependencies()) {
                FieldWriter field = depedencyFields.get(methodDependency.bindingKey());
                parameters.add(
                        frameworkTypeUsageStatement(Snippet.format(field.name()), methodDependency.kind()));
            }
            injectMembersWriter.body().addSnippet("instance.%s(%s);", injectionSite.element().getSimpleName(),
                    Snippet.makeParametersSnippet(parameters.build()));
            break;
        default:
            throw new AssertionError();
        }
    }
    return ImmutableSet.of(writer);
}

From source file:dollar.api.types.DollarMap.java

@Override
public ImmutableList<String> toStrings() {
    List<String> values = new ArrayList<>();
    ImmutableMap<String, Object> map = toJavaMap();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        assert entry.getKey() instanceof String;
        values.add(entry.getKey());/*from ww  w  .  j a v  a 2  s  . c o m*/
        values.add(entry.getValue().toString());
    }
    return ImmutableList.copyOf(values);
}