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

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

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Usage

From source file:com.querydsl.core.types.QBean.java

private static ImmutableMap<String, Expression<?>> createBindings(Expression<?>... args) {
    ImmutableMap.Builder<String, Expression<?>> rv = ImmutableMap.builder();
    for (Expression<?> expr : args) {
        if (expr instanceof Path<?>) {
            Path<?> path = (Path<?>) expr;
            rv.put(path.getMetadata().getName(), expr);
        } else if (expr instanceof Operation<?>) {
            Operation<?> operation = (Operation<?>) expr;
            if (operation.getOperator() == Ops.ALIAS && operation.getArg(1) instanceof Path<?>) {
                Path<?> path = (Path<?>) operation.getArg(1);
                if (isCompoundExpression(operation.getArg(0))) {
                    rv.put(path.getMetadata().getName(), operation.getArg(0));
                } else {
                    rv.put(path.getMetadata().getName(), operation);
                }// w w w  .j  a  va2 s . com
            } else {
                throw new IllegalArgumentException("Unsupported expression " + expr);
            }

        } else {
            throw new IllegalArgumentException("Unsupported expression " + expr);
        }
    }
    return rv.build();
}

From source file:org.apache.sqoop.shell.ShowCommand.java

protected ShowCommand(Shell shell) {
    super(shell, Constants.CMD_SHOW, Constants.CMD_SHOW_SC,
            new ImmutableMap.Builder<String, Class<? extends SqoopFunction>>()
                    .put(Constants.FN_SERVER, ShowServerFunction.class)
                    .put(Constants.FN_VERSION, ShowVersionFunction.class)
                    .put(Constants.FN_CONNECTOR, ShowConnectorFunction.class)
                    .put(Constants.FN_DRIVER_CONFIG, ShowDriverFunction.class)
                    .put(Constants.FN_LINK, ShowLinkFunction.class).put(Constants.FN_JOB, ShowJobFunction.class)
                    .put(Constants.FN_SUBMISSION, ShowSubmissionFunction.class)
                    .put(Constants.FN_OPTION, ShowOptionFunction.class).build());
}

From source file:io.swagger.codegen.options.RubyClientOptionsProvider.java

@Override
public Map<String, String> createOptions() {
    ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
    return builder.put(RubyClientCodegen.GEM_NAME, GEM_NAME_VALUE)
            .put(RubyClientCodegen.MODULE_NAME, MODULE_NAME_VALUE)
            .put(RubyClientCodegen.GEM_VERSION, GEM_VERSION_VALUE)
            .put(RubyClientCodegen.GEM_LICENSE, GEM_LICENSE_VALUE)
            .put(RubyClientCodegen.GEM_DESCRIPTION, GEM_DESCRIPTION_VALUE)
            .put(RubyClientCodegen.GEM_HOMEPAGE, GEM_HOMEPAGE_VALUE)
            .put(RubyClientCodegen.GEM_SUMMARY, GEM_SUMMARY_VALUE)
            .put(RubyClientCodegen.GEM_AUTHOR, GEM_AUTHOR_VALUE)
            .put(RubyClientCodegen.GEM_AUTHOR_EMAIL, GEM_AUTHOR_EMAIL_VALUE)
            .put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
            .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE).build();
}

From source file:de.ii.ldproxy.output.geojson.GeoJsonTargetMappingSubTypeIds.java

@Override
public Map<Class<?>, String> getMapping() {
    return new ImmutableMap.Builder<Class<?>, String>().put(GeoJsonPropertyMapping.class, "GEO_JSON_PROPERTY")
            .put(GeoJsonGeometryMapping.class, "GEO_JSON_GEOMETRY").build();
}

From source file:com.google.template.soy.jbcsrc.internal.MemoryClassLoader.java

private static ImmutableMap<String, ClassData> indexByClassname(Iterable<ClassData> classes) {
    ImmutableMap.Builder<String, ClassData> builder = ImmutableMap.builder();
    for (ClassData classData : classes) {
        builder.put(classData.type().className(), classData);
    }/*from ww  w  .ja  v  a 2 s .  c  o  m*/
    return builder.build();
}

From source file:com.helion3.keys.commands.KeysCommands.java

/**
 * Build a complete command hierarchy/*from   ww w  . j  a v a  2  s. c o  m*/
 * @return
 */
public static CommandSpec getCommand() {
    ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
    builder.put(ImmutableList.of("add"), AddKeyCommand.getCommand());
    builder.put(ImmutableList.of("remove", "del", "delete"), RemoveKeyCommand.getCommand());
    builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand());
    builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());

    return CommandSpec.builder().permission("keys.use").executor(new CommandExecutor() {
        @Override
        public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
            src.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
                    TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #helion3\n"));
            return CommandResult.empty();
        }
    }).children(builder.build()).build();
}

From source file:com.google.template.soy.shared.internal.ModuleUtils.java

/**
 * Given the set of all Soy function implementations and a specific Soy function type (subtype
 * of SoyFunction) to look for, finds the Soy functions that implement the specific type
 * and returns them in the form of a map from function name to function.
 *
 * @param <T> The specific Soy function type to look for.
 * @param soyFunctionsSet The set of all Soy functions.
 * @param specificSoyFunctionType The class of the specific Soy function type to look for.
 * @return A map of the relevant specific Soy functions (name to function).
 *///  w w  w.  j a v  a2  s. com
public static <T extends SoyFunction> ImmutableMap<String, T> buildSpecificSoyFunctionsMap(
        Set<SoyFunction> soyFunctionsSet, Class<T> specificSoyFunctionType) {

    ImmutableMap.Builder<String, T> mapBuilder = ImmutableMap.builder();

    Set<String> seenFnNames = Sets.newHashSetWithExpectedSize(soyFunctionsSet.size());

    for (SoyFunction fn : soyFunctionsSet) {
        if (specificSoyFunctionType.isAssignableFrom(fn.getClass())) {
            String fnName = fn.getName();

            if (seenFnNames.contains(fnName) || NonpluginFunction.forFunctionName(fnName) != null) {
                throw new IllegalStateException(
                        "Found two implementations of " + specificSoyFunctionType.getSimpleName()
                                + " with the same function name '" + fnName + "'.");
            }
            seenFnNames.add(fnName);

            mapBuilder.put(fnName, specificSoyFunctionType.cast(fn));
        }
    }

    return mapBuilder.build();
}

From source file:org.jage.lifecycle.LifecycleMessages.java

/**
 * Creates an instance of the <strong>NOTIFY</strong> {@link LifecycleMessage}.
 *
 * @param sender//from  w w  w  .ja v  a2 s  .c  o  m
 *       a sender of the message (LifecycleManager).
 * @return a new NOTIFY LifecycleMessage.
 */
public static LifecycleMessage createNoInteractiveControllerNotification(final ComponentAddress sender) {
    final LifecycleHeader header = new LifecycleHeader(LifecycleCommand.NOTIFY, sender,
            BroadcastSelector.<ComponentAddress>create());
    final Builder<String, Boolean> builder = ImmutableMap.builder();
    builder.put("interactiveController", false);
    return new LifecycleMessage(header, builder.build());
}

From source file:com.google.idea.blaze.base.experiments.SystemPropertyExperimentLoader.java

@Override
public Map<String, String> getExperiments() {
    // Cache the current values of the experiments so that they don't change in the
    // current ExperimentScope.
    ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
    System.getProperties().stringPropertyNames().stream()
            .filter(name -> name.startsWith(BLAZE_EXPERIMENT_OVERRIDE)).forEach(name -> mapBuilder
                    .put(name.substring(BLAZE_EXPERIMENT_OVERRIDE.length()), System.getProperty(name)));
    return mapBuilder.build();
}

From source file:org.apache.aurora.common.args.Verifiers.java

static Verifiers fromConfiguration(Configuration configuration) {
    ImmutableMap.Builder<Pair<Class<?>, Class<? extends Annotation>>, Verifier<?>> registry = ImmutableMap
            .builder();/*from  ww  w.  j a v  a2s. c om*/

    for (Configuration.VerifierInfo info : configuration.verifierInfo()) {
        Class<?> verifiedType = forName(info.verifiedType);
        Class<? extends Annotation> verifyingAnnotation = forName(info.verifyingAnnotation);
        Class<? extends Verifier<?>> verifierClass = forName(info.verifierClass);
        try {
            registry.put(Pair.<Class<?>, Class<? extends Annotation>>of(verifiedType, verifyingAnnotation),
                    verifierClass.newInstance());
        } catch (InstantiationException e) {
            throw new Configuration.ConfigurationException(e);
        } catch (IllegalAccessException e) {
            throw new Configuration.ConfigurationException(e);
        }
    }
    return new Verifiers(registry.build());
}