Example usage for com.google.common.base CaseFormat LOWER_CAMEL

List of usage examples for com.google.common.base CaseFormat LOWER_CAMEL

Introduction

In this page you can find the example usage for com.google.common.base CaseFormat LOWER_CAMEL.

Prototype

CaseFormat LOWER_CAMEL

To view the source code for com.google.common.base CaseFormat LOWER_CAMEL.

Click Source Link

Document

Java variable naming convention, e.g., "lowerCamel".

Usage

From source file:stroom.util.config.StroomProperties.java

private static String getEnv(final String propertyName) {
    // Environment variable names are transformations of property names.
    // E.g. stroom.temp => STROOM_TEMP.
    // E.g. stroom.jdbcDriverUsername => STROOM_JDBC_DRIVER_USERNAME
    String environmentVariableName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE,
            propertyName.replace('.', '_'));
    String environmentVariable = System.getenv(environmentVariableName);
    if (StringUtils.isNotBlank(environmentVariable)) {
        return environmentVariable;
    }//w w  w . j av  a 2 s  .c  o m

    return null;
}

From source file:net.simonvt.schematic.compiler.TableWriter.java

public void createValuesBuilder(Filer filer, String outPackage) throws IOException {
    String name = Character.toUpperCase(this.name.charAt(0)) + this.name.substring(1);
    String valuesPackage = outPackage + ".values";
    String className = name + "ValuesBuilder";
    String qualifiedName = outPackage + ".values." + className;

    JavaFileObject jfo = filer.createSourceFile(qualifiedName);
    Writer out = jfo.openWriter();

    TypeSpec.Builder valuesBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC);

    FieldSpec valuesSpec = FieldSpec.builder(Clazz.CONTENT_VALUES, "values")
            .initializer("new $T()", Clazz.CONTENT_VALUES).build();
    valuesBuilder.addField(valuesSpec);/*  ww  w  .  j  ava 2s.c o m*/

    for (VariableElement element : columns) {
        String elmName = element.getSimpleName().toString();
        elmName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, elmName);

        DataType dataType = element.getAnnotation(DataType.class);
        DataType.Type type = dataType.value();

        String column = element.getSimpleName().toString();

        switch (type) {
        case INTEGER:
            valuesBuilder
                    .addMethod(makePutMethodSpec(valuesPackage, className, elmName, column, Integer.class));
            valuesBuilder.addMethod(makePutMethodSpec(valuesPackage, className, elmName, column, Long.class));
            break;

        case REAL:
            valuesBuilder.addMethod(makePutMethodSpec(valuesPackage, className, elmName, column, Float.class));
            valuesBuilder.addMethod(makePutMethodSpec(valuesPackage, className, elmName, column, Double.class));
            break;

        case TEXT:
            valuesBuilder.addMethod(makePutMethodSpec(valuesPackage, className, elmName, column, String.class));
            break;

        case BLOB:
            // TODO: What do I call here?
            break;
        }
    }

    valuesBuilder.addMethod(MethodSpec.methodBuilder("values").returns(Clazz.CONTENT_VALUES)
            .addModifiers(Modifier.PUBLIC).addStatement("return values").build());

    JavaFile javaFile = JavaFile.builder(valuesPackage, valuesBuilder.build()).build();
    javaFile.writeTo(out);
    out.flush();
    out.close();
}

From source file:com.android.utils.SdkUtils.java

/**
 * Translates a camel case name (e.g. xmlName) into a Java / C++ constant name (e.g. XML_NAME)
 * @param camelCaseName the camel case name.
 * @return the equivalent constant name.
 *///from w  w  w. jav  a 2 s .  co m
public static String camelCaseToConstantName(String camelCaseName) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, camelCaseName);
}

From source file:com.tactfactory.harmony.platform.winphone.WinphoneProjectAdapter.java

@Override
public List<IUpdater> getApplicationFiles() {
    List<IUpdater> result = new ArrayList<IUpdater>();

    String applicationName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
            this.adapter.getApplicationMetadata().getName());

    String templatePath = this.adapter.getTemplateSourcePath();
    String filePath = this.adapter.getSourcePath();

    result.add(new SourceFile(templatePath + "TemplateApplicationBase.cs",
            filePath + applicationName + "ApplicationBase.cs", true));

    result.add(new ProjectUpdater(FileType.Compile, applicationName + "ApplicationBase.cs"));

    result.add(new SourceFile(templatePath + "TemplateApplication.xaml.cs",
            filePath + applicationName + "Application.xaml.cs"));

    result.add(new ProjectUpdater(FileType.Compile, applicationName + "Application.xaml.cs",
            applicationName + "Application.xaml"));

    result.add(new SourceFile(templatePath + "TemplateApplication.xaml",
            filePath + applicationName + "Application.xaml"));

    result.add(new ProjectUpdater(FileType.ApplicationDefinition, applicationName + "Application.xaml"));

    return result;
}

From source file:com.android.utils.SdkUtils.java

/**
 * Translates a Java / C++ constant name (e.g. XML_NAME) into camel case name (e.g. xmlName)
 * @param constantName the constant name.
 * @return the equivalent camel case name.
 */// w w w .  j a  va  2  s. c  o m
public static String constantNameToCamelCase(String constantName) {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, constantName);
}

From source file:com.shieldsbetter.sbomg.ViewModelGenerator.java

private static void outfitModelWithList(ModelClass dest, String contextName, Set<String> listOptions,
        Object elDesc) {/*from  w  w  w. ja  v  a2 s .  c om*/
    boolean immutableFlag = listOptions.contains("immutable");
    boolean replaceableFlag = listOptions.contains("replaceable");

    ListElementTypeData elTypeData = outfitModelWithListElementType(dest, contextName, elDesc);
    String elTypeRaw = elTypeData.getRawTypeName();
    TypeName elType = ClassName.get("", elTypeRaw);

    String slotTypeRaw = contextName + "Key";
    TypeName slotType = ClassName.get("", slotTypeRaw);

    TypeSpec.Builder keyType = TypeSpec.classBuilder(slotTypeRaw)
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
            .addMethod(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE)
                    .addParameter(elType, "value").addStatement("myValue = value").build())
            .addMethod(MethodSpec.methodBuilder("getValue").addModifiers(Modifier.PRIVATE).returns(elType)
                    .addStatement("return myValue").build());

    if (elTypeData.isFinal() || immutableFlag) {
        keyType.addField(elType, "myValue", Modifier.PRIVATE, Modifier.FINAL);
    } else {
        keyType.addField(elType, "myValue", Modifier.PRIVATE);
        keyType.addMethod(MethodSpec.methodBuilder("setValue").addModifiers(Modifier.PRIVATE)
                .addParameter(elType, "value").addStatement("myValue = value").build());
    }

    dest.addType(keyType.build());

    FieldSpec.Builder field = FieldSpec
            .builder(ParameterizedTypeName.get(ClassName.get("java.util", "List"), slotType),
                    "my" + contextName + "List", Modifier.PRIVATE)
            .initializer("new $T<>()", ClassName.get("java.util", "LinkedList"));

    if (!replaceableFlag) {
        field.addModifiers(Modifier.FINAL);
    }

    dest.addField(field.build());

    dest.addRootMethod("get" + contextName + "Element", elType,
            ImmutableList.of(ImmutablePair.of("index", TypeName.INT)),
            CodeBlock.builder().addStatement("return my$LList.get(index).getValue()", contextName).build());

    dest.addRootMethod("get" + contextName + "Element", elType,
            ImmutableList.of(ImmutablePair.of("key", slotType)),
            CodeBlock.builder().addStatement("int index = my$LList.indexOf(key)", contextName)
                    .addStatement("return my$LList.get(index).getValue()", contextName).build());

    // TODO: Fix this.  The generated field contians keys not elements.
    /*
    dest.addRootMethod("contains" + contextName + "Element",
        TypeName.BOOLEAN, ImmutableList.of(
            ImmutablePair.of("element", elType)),
        renderCodeBlock(LIST_CONTAINS_VALUE_METHOD_TEMPL,
                "fieldName", contextName,
                "valueParam", "element"));
    */

    if (contextName.isEmpty()) {
        String parentInterfaceName = elTypeRaw;
        if (elTypeData.isInnerClass()) {
            parentInterfaceName = dest.getName() + "." + parentInterfaceName;
        }

        dest.addImplements(ParameterizedTypeName.get(ClassName.get("", "Iterable"),
                ClassName.get("", parentInterfaceName)));
        dest.addOverriddenRootMethod("iterator",
                ParameterizedTypeName.get(ClassName.get(Iterator.class), elType), ImmutableList.of(),
                renderCodeBlock(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName", contextName,
                        "baseIterable", "my" + contextName + "List"));
    } else {
        // Gross workaround here.  JavaPoet doesn't provide any way to
        // include a random non-static import.  So we render out a template
        // that happens to include an unresolved $T, then replace it with
        // the type we want to import.
        dest.addRootMethod(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName),
                ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType), ImmutableList.of(),
                CodeBlock.of(
                        renderTemplate(RETURN_LIST_METHOD_TEMPL, "elementType", elTypeRaw, "iteratorCode",
                                renderTemplate(LIST_ITERATOR_TEMPL, "elementType", elTypeRaw, "contextName",
                                        contextName, "baseIterable", "my" + contextName + "List")),
                        ParameterizedTypeName.get(ClassName.get(Iterator.class), elType)));
    }

    if (immutableFlag) {
        String elementParam = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, contextName + "Elements");
        dest.addInitializationParameter(elementParam,
                ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType));

        CodeBlock.Builder init = CodeBlock.builder().beginControlFlow("for ($T e : $L)", elType, elementParam)
                .addStatement("$LKey k = new $LKey(e);", contextName, contextName)
                .addStatement("my$LList.add(k)", contextName);

        if (!elTypeData.isLeaf()) {
            init.addStatement("subscribeIfNotNull(k)");
        }

        init.endControlFlow();
        dest.addInitializationCode(init.build());
    }

    if (replaceableFlag) {
        dest.addListenerEvent(contextName + "Replaced", ImmutableList.of(ImmutablePair.of("newValue",
                ParameterizedTypeName.get(ClassName.get("java.util", "List"), elType))));

        dest.addRootMethod("replace" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("elements",
                        ParameterizedTypeName.get(ClassName.get("", "Iterable"), elType))),
                renderCodeBlock(REPLACE_LIST_METHOD_TEMPL, "contextName", contextName, "elementType", elTypeRaw,
                        "parentType", dest.getName(), "elementsParam", "elements", "leafFlag",
                        elTypeData.isLeaf()));

        dest.addBuildCode(CodeBlock.builder().beginControlFlow("")
                .addStatement("List<$T> valueList = new $T<>()", elType, LinkedList.class)
                .beginControlFlow("for ($T s : my$LList)", slotType, contextName)
                .addStatement("valueList.add(s.getValue())").endControlFlow()
                .addStatement("l.on$LReplaced(this, " + "$T.unmodifiableList(valueList))", contextName,
                        Collections.class)
                .endControlFlow().build());
    }

    if (!elTypeData.isLeaf()) {
        dest.addField(FieldSpec
                .builder(
                        ParameterizedTypeName.get(ClassName.get("java.util", "Map"), slotType,
                                ClassName.get("", elTypeRaw + ".Subscription")),
                        "my" + contextName + "Subscriptions", Modifier.PRIVATE, Modifier.FINAL)
                .initializer("new $T<>()", ClassName.get("java.util", "HashMap")).build());

        dest.addListenerEvent(contextName + "Updated",
                ImmutableList.of(ImmutablePair.of("updatedElement", elType),
                        ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType),
                        ImmutablePair.of("event", ClassName.get("", elTypeRaw + ".Event"))));
        dest.addRootMethod(MethodSpec.methodBuilder("subscribeIfNotNull").returns(TypeName.VOID)
                .addModifiers(Modifier.PRIVATE).addParameter(slotType, "key", Modifier.FINAL)
                .addCode(renderCodeBlock(SUBSCRIBE_IF_NOT_NULL_TEMPL, "keyParam", "key", "fieldName",
                        contextName, "fieldType", elTypeRaw, "parentType", dest.getName()))
                .build());
    }

    if (!immutableFlag) {
        if (!replaceableFlag) {
            dest.addBuildCode(CodeBlock.builder().beginControlFlow("").addStatement("int i = 0")
                    .beginControlFlow("for ($T s : my$LList)", slotType, contextName)
                    .addStatement("l.on$LAdded(this, s.getValue(), i, s)", contextName).addStatement("i++")
                    .endControlFlow().endControlFlow().build());
        }

        dest.addListenerEvent(contextName + "Added", ImmutableList.of(ImmutablePair.of("addedElement", elType),
                ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
        dest.addRootMethod("add" + contextName, slotType,
                ImmutableList.of(ImmutablePair.of("newElement", elType)),
                renderCodeBlock(LIST_ADD_METHOD_TEMPL, "valueParam", "newElement", "fieldName", contextName,
                        "fieldType", elTypeRaw, "leafFlag", elTypeData.isLeaf(), "parentType", dest.getName()));

        dest.addListenerEvent(contextName + "Removed",
                ImmutableList.of(ImmutablePair.of("removedElement", elType),
                        ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
        dest.addRootMethod("remove" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("index", TypeName.INT)), renderCodeBlock(
                        LIST_REMOVE_METHOD_BY_INDEX_TEMPL, "indexParam", "index", "fieldName", contextName));
        dest.addRootMethod("remove" + contextName, TypeName.VOID,
                ImmutableList.of(ImmutablePair.of("key", slotType)),
                renderCodeBlock(LIST_REMOVE_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName));
        dest.addRootMethod(MethodSpec.methodBuilder("remove" + contextName).addModifiers(Modifier.PRIVATE)
                .returns(TypeName.VOID).addParameter(TypeName.INT, "index", Modifier.FINAL)
                .addParameter(slotType, "key", Modifier.FINAL)
                .addCode(renderCodeBlock(LIST_REMOVE_METHOD_CORE_TEMPL, "fieldName", contextName, "keyParam",
                        "key", "indexParam", "index", "leafFlag", elTypeData.isLeaf(), "parentType",
                        dest.getName()))
                .build());

        dest.addRootMethod("clear" + contextName, TypeName.VOID,
                ImmutableList.<ImmutablePair<String, TypeName>>of(),
                renderCodeBlock(LIST_CLEAR_METHOD_TEMPL, "fieldName", contextName));

        if (!elTypeData.isFinal()) {
            dest.addListenerEvent(contextName + "Set",
                    ImmutableList.of(ImmutablePair.of("oldValue", elType), ImmutablePair.of("newValue", elType),
                            ImmutablePair.of("index", TypeName.INT), ImmutablePair.of("key", slotType)));
            dest.addRootMethod("set" + contextName, TypeName.VOID,
                    ImmutableList.of(ImmutablePair.of("index", TypeName.INT),
                            ImmutablePair.of("newValue", elType)),
                    renderCodeBlock(LIST_SET_METHOD_BY_INDEX_TEMPL, "fieldName", contextName, "indexParam",
                            "index", "valueParam", "newValue"));
            dest.addRootMethod("set" + contextName, TypeName.VOID,
                    ImmutableList.of(ImmutablePair.of("key", slotType), ImmutablePair.of("newValue", elType)),
                    renderCodeBlock(LIST_SET_METHOD_BY_KEY_TEMPL, "keyParam", "key", "fieldName", contextName,
                            "valueParam", "newValue"));
            dest.addRootMethod(MethodSpec.methodBuilder("set" + contextName).returns(TypeName.VOID)
                    .addModifiers(Modifier.PRIVATE).addParameter(TypeName.INT, "index", Modifier.FINAL)
                    .addParameter(slotType, "key", Modifier.FINAL).addParameter(elType, "value", Modifier.FINAL)
                    .addCode(renderCodeBlock(LIST_SET_METHOD_CORE_TEMPL, "keyParam", "key", "indexParam",
                            "index", "valueParam", "value", "leafFlag", elTypeData.isLeaf(), "fieldName",
                            contextName, "fieldType", elTypeRaw, "parentType", dest.getName()))
                    .build());
        }
    }
}

From source file:org.jooby.livereload.LiveReload.java

@SuppressWarnings("unchecked")
@Override// w  ww  .ja v a2  s . c o  m
public void configure(final Env env, final Config conf, final Binder binder) throws Throwable {
    boolean enabled = conf.hasPath("livereload.enabled") ? conf.getBoolean("livereload.enabled")
            : "dev".equals(env.name());
    if (enabled) {
        Router router = env.router();
        /**
         * Livereload client:
         */
        String livereloadjs = "/" + LiveReload.class.getPackage().getName().replace(".", "/")
                + "/livereload.js";
        router.assets("/livereload.js", livereloadjs);
        /** {{liveReload}} local variable */
        router.use("*", (req, rsp) -> req.set("liveReload", template(req))).name("livereload");

        String serverName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
                conf.getString("application.name"));

        Queue<WebSocket> broadcast = new ConcurrentLinkedQueue<>();
        AtomicBoolean first = new AtomicBoolean(true);
        /**
         * Websocket:
         */
        router.ws("/livereload", ws -> {
            // add to broadcast
            broadcast.add(ws);

            ws.onMessage(msg -> {
                Map<String, Object> cmd = msg.to(Map.class);
                log.debug("command: {}", cmd);

                Map<String, Object> rsp = handshake(cmd, serverName, V7);
                if (rsp != null) {
                    log.debug("sending: {}", rsp);
                    ws.send(rsp);
                } else {
                    log.trace("ignoring command: {}", cmd);
                    // resync app state after a jooby:run restart
                    if (first.compareAndSet(true, false)) {
                        int counter = Integer.parseInt(System.getProperty("joobyRun.counter", "0"));
                        if (counter > 0) {
                            ws.send(reload("/", true));
                        }
                    }
                }
            });

            // remove from broadcast
            ws.onClose(reason -> broadcast.remove(ws));
        }).consumes(MediaType.json).produces(MediaType.json);

        if (paths.isEmpty()) {
            Path basedir = Paths.get(System.getProperty("user.dir"));
            Path assetsDir;
            if (conf.hasPath("assets.outputDir")) {
                assetsDir = Paths.get(conf.getString("assets.outputDir"));
            } else {
                assetsDir = basedir.resolve("public");
            }
            register(basedir.resolve("public"), "**/*.html", "**/*.ftl", "**/*.hbs", "**/*.jade");
            register(assetsDir, "**/*.css", "**/*.scss", "**/*.sass", "**/*.less", "**/*.js", "**/*.coffee",
                    "**/*.ts");
            register(basedir.resolve("target"), "**/*.class", "**/*.conf", "**/*.properties");
            register(basedir.resolve("build"), "**/*.class", "**/*.conf", "**/*.properties");
        }

        if (paths.size() > 0) {
            FileWatcher watcher = new FileWatcher();
            paths.forEach(it -> watcher.register((Path) it[0], (kind, path) -> {
                Path relative = relative(paths, path.toAbsolutePath());
                log.debug("file changed {}: {}", relative, File.separator);
                Map<String, Object> reload = reload(
                        Route.normalize("/" + relative.toString().replace(File.separator, "/")),
                        css.test(relative));
                for (WebSocket ws : broadcast) {
                    try {
                        log.debug("sending: {}", reload);
                        ws.send(reload);
                    } catch (Exception x) {
                        log.debug("execution of {} resulted in exception", reload, x);
                    }
                }
            }, options -> ((List<String>) it[1]).forEach(options::includes)));
            watcher.configure(env, conf, binder);
        } else {
            log.warn("File watcher is off");
        }
    }
}

From source file:com.gmail.sretof.db.jdbc.processor.CamelBeanProcessor.java

/**
 * The positions in the returned array represent column numbers. The values
 * stored at each position represent the index in the
 * <code>PropertyDescriptor[]</code> for the bean property that matches the
 * column name. If no bean property was found for a column, the position is
 * set to <code>PROPERTY_NOT_FOUND</code>.
 * /* w  ww . j a v a  2  s.  co m*/
 * @param rsmd
 *            The <code>ResultSetMetaData</code> containing column
 *            information.
 * 
 * @param props
 *            The bean property descriptors.
 * 
 * @throws SQLException
 *             if a database access error occurs
 * 
 * @return An int[] with column index to property index mappings. The 0th
 *         element is meaningless because JDBC column indexing starts at 1.
 */
protected int[] mapColumnsToProperties(ResultSetMetaData rsmd, PropertyDescriptor[] props) throws SQLException {
    int cols = rsmd.getColumnCount();
    int[] columnToProperty = new int[cols + 1];
    Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

    for (int col = 1; col <= cols; col++) {
        String columnName = rsmd.getColumnLabel(col);
        if (null == columnName || 0 == columnName.length()) {
            columnName = rsmd.getColumnName(col);
        }
        columnName = columnName.toLowerCase();
        String propertyName = columnToPropertyOverrides.get(columnName);
        if (propertyName == null) {
            propertyName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName);// ?
        }
        for (int i = 0; i < props.length; i++) {
            String prop = props[i].getName();
            if (propertyName.equalsIgnoreCase(prop)) {
                columnToProperty[col] = i;
                break;
            }
        }
    }
    return columnToProperty;
}

From source file:org.jooby.internal.mvc.MvcRoutes.java

private static String attrName(final Annotation annotation, final Method attr) {
    String name = attr.getName();
    if (name.equals("value")) {
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, annotation.annotationType().getSimpleName());
    }/*  w  w w  .  j  av a  2  s .  c  o m*/
    return annotation.annotationType().getSimpleName() + "." + name;
}

From source file:com.google.api.codegen.DiscoveryImporter.java

private static String lowerCamelToUpperCamel(String s) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, s);
}