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:com.contentful.generator.Generator.java

static String normalize(String name, CaseFormat format) {
    String normalized = name.substring(0, 1).toLowerCase();
    if (name.length() > 1) {
        normalized += name.substring(1);
    }/*from   w w w. j  ava2  s. co  m*/
    return CaseFormat.LOWER_CAMEL.to(format, normalized.replaceAll("[^\\w\\d]", ""));
}

From source file:com.facebook.buck.cli.QueryCommand.java

private void collectAndPrintAttributes(CommandRunnerParams params, BuckQueryEnvironment env,
        Set<QueryTarget> queryResult) throws QueryException {
    PatternsMatcher patternsMatcher = new PatternsMatcher(outputAttributes.get());
    SortedMap<String, SortedMap<String, Object>> result = Maps.newTreeMap();
    for (QueryTarget target : queryResult) {
        if (!(target instanceof QueryBuildTarget)) {
            continue;
        }// w  ww . jav  a  2 s  .c  o m
        TargetNode<?, ?> node = env.getNode(target);
        try {
            SortedMap<String, Object> sortedTargetRule = params.getParser()
                    .getRawTargetNode(env.getParserState(), params.getCell(), node);
            if (sortedTargetRule == null) {
                params.getConsole().printErrorText(
                        "unable to find rule for target " + node.getBuildTarget().getFullyQualifiedName());
                continue;
            }
            SortedMap<String, Object> attributes = Maps.newTreeMap();
            if (patternsMatcher.hasPatterns()) {
                for (String key : sortedTargetRule.keySet()) {
                    String snakeCaseKey = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, key);
                    if (patternsMatcher.matches(snakeCaseKey)) {
                        attributes.put(snakeCaseKey, sortedTargetRule.get(key));
                    }
                }
            }

            result.put(node.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName(), attributes);
        } catch (BuildFileParseException e) {
            params.getConsole().printErrorText(
                    "unable to find rule for target " + node.getBuildTarget().getFullyQualifiedName());
            continue;
        }
    }
    StringWriter stringWriter = new StringWriter();
    try {
        params.getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(stringWriter, result);
    } catch (IOException e) {
        // Shouldn't be possible while writing to a StringWriter...
        throw new RuntimeException(e);
    }
    String output = stringWriter.getBuffer().toString();
    params.getConsole().getStdOut().println(output);
}

From source file:com.palantir.typescript.text.reconciler.PresentationReconciler.java

private static Color getForegroundColor(TokenClass classification) {
    String camelClassificationName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,
            classification.name());//from w  w w. j  a  v a  2s  . c  o  m
    String preferenceName = "syntaxColoring." + camelClassificationName + ".color";
    String colorString = TypeScriptPlugin.getDefault().getPreferenceStore().getString(preferenceName);

    if (!colorString.isEmpty()) {
        RGB rgb = StringConverter.asRGB(colorString);

        return COLORS.getUnchecked(rgb);
    }

    return null;
}

From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.java

private void setBindValue(final PreparedStatement preparedStatement, final Collection<String> tableFields,
        final Condition condition) throws SQLException {
    int index = 1;
    if (null != condition.getFields() && !condition.getFields().isEmpty()) {
        for (String each : condition.getFields().keySet()) {
            String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each);
            if (null != condition.getFields().get(each) && tableFields.contains(lowerUnderscore)) {
                preparedStatement.setString(index++, String.valueOf(condition.getFields().get(each)));
            }/*from w w  w .j  a va  2 s  .c om*/
        }
    }
    if (null != condition.getStartTime()) {
        preparedStatement.setTimestamp(index++, new Timestamp(condition.getStartTime().getTime()));
    }
    if (null != condition.getEndTime()) {
        preparedStatement.setTimestamp(index++, new Timestamp(condition.getEndTime().getTime()));
    }
}

From source file:com.jedi.metadata.DatabaseMetadataUtil.java

public static CustomTypeInfo getCustomType(Connection connection, String owner, String typeName)
        throws SQLException {
    CustomTypeInfo customTypeInfo = null;
    String sql = "SELECT OWNER," + "       TYPE_NAME," + "       TYPECODE," + "       TYPE_OID"
            + "  FROM ALL_TYPES" + " WHERE OWNER = '" + owner + "' AND TYPE_NAME = '" + typeName + "'";
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(sql);
    resultSet.next();//from w  ww.  j av a2  s .  c  om
    customTypeInfo = new CustomTypeInfo();
    customTypeInfo.setOwner(resultSet.getString("OWNER"));
    customTypeInfo.setName(resultSet.getString("TYPE_NAME"));
    String objectType = resultSet.getString("TYPECODE");
    customTypeInfo.setObjectType(objectType);
    customTypeInfo.setIsCollection("COLLECTION".equals(objectType));
    if (customTypeInfo.isIsCollection()) {
        sql = "SELECT COLL_TYPE, ELEM_TYPE_OWNER, ELEM_TYPE_NAME" + "  FROM ALL_COLL_TYPES"
                + " WHERE ELEM_TYPE_OWNER = '" + owner + "'" + "       AND TYPE_NAME = '" + typeName + "'";
        statement = connection.createStatement();
        resultSet = statement.executeQuery(sql);
        resultSet.next();
        customTypeInfo.setCollectionType(resultSet.getString("COLL_TYPE"));
        typeName = resultSet.getString("ELEM_TYPE_NAME");
        customTypeInfo.setCollectionElementType(typeName);
        owner = resultSet.getString("ELEM_TYPE_OWNER");
        customTypeInfo.setCollectionElementTypeOwner(owner);
    }

    sql = "SELECT OWNER," + "         ATTR_NAME," + "         ATTR_TYPE_OWNER," + "         ATTR_TYPE_NAME,"
            + "         LENGTH," + "         PRECISION," + "         SCALE," + "         ATTR_NO"
            + "    FROM ALL_TYPE_ATTRS" + "   WHERE OWNER = '" + owner + "' AND TYPE_NAME = '" + typeName + "'"
            + "ORDER BY ATTR_NO";
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);
    while (resultSet.next()) {
        CustomTypeArgumentInfo customTypeArgumentInfo = new CustomTypeArgumentInfo();
        String argumentName = resultSet.getString("ATTR_NAME");
        customTypeArgumentInfo.setName(argumentName);
        customTypeArgumentInfo.setOwner(resultSet.getString("OWNER"));
        String dataType = resultSet.getString("ATTR_TYPE_NAME");
        if (dataType != null && !dataType.isEmpty()) {
            dataType = dataType.toUpperCase();
            customTypeArgumentInfo.setDataType(dataType);
        }

        String dataTypeOwner = resultSet.getString("ATTR_TYPE_OWNER");
        customTypeArgumentInfo.setDataTypeOwner(dataTypeOwner);
        customTypeArgumentInfo.setPosition(resultSet.getInt("ATTR_NO"));
        customTypeArgumentInfo.setLength(resultSet.getInt("LENGTH"));
        customTypeArgumentInfo.setPrecision(resultSet.getInt("PRECISION"));
        customTypeArgumentInfo.setScale(resultSet.getInt("SCALE"));

        if (dataTypeOwner != null && !dataTypeOwner.isEmpty()) {
            customTypeArgumentInfo.setIsCustomObject(true);
        }

        customTypeInfo.getArguments().add(customTypeArgumentInfo);

        if (argumentName != null && !argumentName.isEmpty()) {
            argumentName = argumentName.toUpperCase();
            if (argumentName.startsWith("P_")) {
                argumentName = argumentName.substring(2);
            }
            String fieldName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, argumentName);
            customTypeArgumentInfo.setFieldName(fieldName);

            String javaType = getJavaType(dataType);
            customTypeArgumentInfo.setFieldType(javaType);

        }
    }

    return customTypeInfo;
}

From source file:com.github.dozermapper.protobuf.util.ProtoUtils.java

/**
 * Converts name to CamelCase/*from w ww .j  a  v a2 s .  co  m*/
 *
 * @param name name to convert
 * @return converted name to CamelCase
 */
public static String toCamelCase(String name) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
}

From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java

private ImmutableMap<TypeMirror, FieldSpec> getTypeAdapters(ImmutableList<Property> properties) {
    Map<TypeMirror, FieldSpec> typeAdapters = new LinkedHashMap<>();
    NameAllocator nameAllocator = new NameAllocator();
    nameAllocator.newName("CREATOR");
    for (Property property : properties) {
        if (property.typeAdapter != null && !typeAdapters.containsKey(property.typeAdapter)) {
            ClassName typeName = (ClassName) TypeName.get(property.typeAdapter);
            String name = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, typeName.simpleName());
            name = nameAllocator.newName(name, typeName);

            typeAdapters.put(property.typeAdapter,
                    FieldSpec.builder(typeName, NameAllocator.toJavaIdentifier(name), PRIVATE, STATIC, FINAL)
                            .initializer("new $T()", typeName).build());
        }/*  www  . j a va2s .  c o  m*/
    }
    return ImmutableMap.copyOf(typeAdapters);
}

From source file:com.tactfactory.harmony.platform.android.AndroidProjectAdapter.java

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

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

    String templatePath = this.adapter.getTemplateSourceDataPath();

    String filePath = String.format("%s%s/%s/", this.adapter.getSourcePath(),
            this.adapter.getApplicationMetadata().getProjectNameSpace(), this.adapter.getData());

    result.add(new SourceFile(templatePath + "TemplateSQLiteOpenHelper.java",
            String.format("%s%sSQLiteOpenHelper.java", filePath, applicationName), false));

    result.add(new SourceFile(templatePath + "base/TemplateSQLiteOpenHelperBase.java",
            String.format("%sbase/%sSQLiteOpenHelperBase.java", filePath, applicationName), true));

    result.add(new SourceFile(templatePath + "base/ApplicationSQLiteAdapterBase.java",
            filePath + "base/SQLiteAdapterBase.java", true));
    result.add(new SourceFile(templatePath + "ApplicationSQLiteAdapter.java", filePath + "SQLiteAdapter.java",
            false));//from www.j a v  a 2s  .  c  o  m

    result.add(new SourceFile(templatePath + "data-package-info.java", filePath + "package-info.java", true));

    result.add(new SourceFile(templatePath + "base/data-package-info.java", filePath + "base/package-info.java",
            true));

    return result;
}

From source file:org.abstractmeta.reflectify.plugin.ReflectifyGenerator.java

protected void generateMethodInvokers(JavaTypeBuilder typeBuilder, List<JavaMethod> methods,
        Type reflectifyType) {/* w  ww .  ja  v  a2  s  .  c  o m*/
    Map<String, Integer> methodCounter = new HashMap<String, Integer>();
    JavaMethodBuilder methodBuilder = new JavaMethodBuilder();
    methodBuilder.addAnnotation(new SuppressWarningsImpl("unchecked"));
    methodBuilder.addModifier("protected").setName("registerMethodInvokers").setResultType(void.class);
    methodBuilder.addParameter("methods",
            new ParameterizedTypeImpl(null, Map.class, String.class, new ParameterizedTypeImpl(null, List.class,
                    new ParameterizedTypeImpl(null, MethodInvoker.class, reflectifyType, Object.class))));
    methodBuilder.addBody("\n");
    for (JavaMethod method : methods) {
        if (!method.getModifiers().contains("public")) {
            continue;
        }
        String methodName = method.getName();
        String methodInvokerTypeNamePostfix = getOccurrence(methodCounter, methodName);
        String methodInvokerClassName = StringUtil.format(CaseFormat.UPPER_CAMEL, methodName,
                "invoker" + methodInvokerTypeNamePostfix, CaseFormat.LOWER_CAMEL);
        boolean exceptionHandling = method.getExceptionTypes() != null && !method.getExceptionTypes().isEmpty();
        buildMethodInvokerType(methodBuilder, methodName, methodInvokerClassName,
                ReflectUtil.getObjectType(method.getResultType()), method.getParameterTypes(), reflectifyType,
                exceptionHandling);
        methodBuilder.addBody(String.format(
                String.format("register(methods, \"%s\", new %s());", methodName, methodInvokerClassName)));

    }
    typeBuilder.addMethod(methodBuilder.build());
}

From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.java

private String buildOrder(final Collection<String> tableFields, final String sortName, final String sortOrder) {
    if (Strings.isNullOrEmpty(sortName)) {
        return "";
    }/*from w w  w .  ja  v a 2 s  .c o  m*/
    String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sortName);
    if (!tableFields.contains(lowerUnderscore)) {
        return "";
    }
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" ORDER BY ").append(lowerUnderscore);
    switch (sortOrder.toUpperCase()) {
    case "ASC":
        sqlBuilder.append(" ASC");
        break;
    case "DESC":
        sqlBuilder.append(" DESC");
        break;
    default:
        sqlBuilder.append(" ASC");
    }
    return sqlBuilder.toString();
}