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

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

Introduction

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

Prototype

CaseFormat LOWER_UNDERSCORE

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

Click Source Link

Document

C++ variable naming convention, e.g., "lower_underscore".

Usage

From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java

public static String getSetterName(Field field) {
    return new StringBuilder().append("set")
            .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).toString();
}

From source file:org.dozer.util.ProtoUtils.java

public static String toCamelCase(String name) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
}

From source file:com.axelor.common.Inflector.java

/**
 * Convert the give word to dasherized form.
 * /*from  www .  j  av  a2s .c o m*/
 * <pre>
 * inflection.tableize(&quot;address_books&quot;); // &quot;address-book&quot;
 * inflection.tableize(&quot;AddressBook&quot;); // &quot;address-book&quot;
 * </pre>
 * 
 * @param word
 *            the string to convert
 * @return converted string
 */
public String dasherize(String word) {
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, underscore(word));
}

From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java

public static String getDefaultValueGetterName(Field field) {
    return new StringBuilder().append("get")
            .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName()))
            .append("DefaultValue").toString();
}

From source file:org.killbill.commons.jdbi.mapper.LowerToCamelBeanMapper.java

public T map(final int row, final ResultSet rs, final StatementContext ctx) throws SQLException {
    final T bean;
    try {//from   ww w.ja va2 s  . com
        bean = type.newInstance();
    } catch (final Exception e) {
        throw new IllegalArgumentException(
                String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e);
    }

    final Class beanClass = bean.getClass();
    final ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
        final String name = metadata.getColumnLabel(i).toLowerCase();

        final PropertyDescriptor descriptor = properties.get(name);

        if (descriptor != null) {
            final Class<?> type = descriptor.getPropertyType();

            Object value;

            if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
                value = rs.getBoolean(i);
            } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) {
                value = rs.getByte(i);
            } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) {
                value = rs.getShort(i);
            } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) {
                value = rs.getInt(i);
            } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) {
                value = rs.getLong(i);
            } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) {
                value = rs.getFloat(i);
            } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) {
                value = rs.getDouble(i);
            } else if (type.isAssignableFrom(BigDecimal.class)) {
                value = rs.getBigDecimal(i);
            } else if (type.isAssignableFrom(DateTime.class)) {
                final Timestamp timestamp = rs.getTimestamp(i);
                value = timestamp == null ? null : new DateTime(timestamp).toDateTime(DateTimeZone.UTC);
            } else if (type.isAssignableFrom(Time.class)) {
                value = rs.getTime(i);
            } else if (type.isAssignableFrom(LocalDate.class)) {
                //
                // We store the LocalDate into a mysql 'date' as a string
                // (See https://github.com/killbill/killbill-commons/blob/master/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java)
                // So we also read it as a String which avoids any kind of transformation
                //
                // Note that we used previously the getDate(index, Calendar) method, but this is not thread safe as we discovered
                // unless maybe -- untested --we pass a new instance of a Calendar each time
                //
                final String dateString = rs.getString(i);
                value = dateString == null ? null : new LocalDate(dateString, DateTimeZone.UTC);
            } else if (type.isAssignableFrom(DateTimeZone.class)) {
                final String dateTimeZoneString = rs.getString(i);
                value = dateTimeZoneString == null ? null : DateTimeZone.forID(dateTimeZoneString);
            } else if (type.isAssignableFrom(String.class)) {
                value = rs.getString(i);
            } else if (type.isAssignableFrom(UUID.class)) {
                final String uuidString = rs.getString(i);
                value = uuidString == null ? null : UUID.fromString(uuidString);
            } else if (type.isEnum()) {
                final String enumString = rs.getString(i);
                //noinspection unchecked
                value = enumString == null ? null : Enum.valueOf((Class<Enum>) type, enumString);
            } else if (type == byte[].class) {
                value = rs.getBytes(i);
            } else {
                value = rs.getObject(i);
            }

            // For h2, transform a JdbcBlob into a byte[]
            if (value instanceof Blob) {
                final Blob blob = (Blob) value;
                value = blob.getBytes(0, (int) blob.length());
            }
            if (rs.wasNull() && !type.isPrimitive()) {
                value = null;
            }

            try {
                final Method writeMethod = descriptor.getWriteMethod();
                if (writeMethod != null) {
                    writeMethod.invoke(bean, value);
                } else {
                    final String camelCasedName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
                    final Field field = getField(beanClass, camelCasedName);
                    field.setAccessible(true); // Often private...
                    field.set(bean, value);
                }
            } catch (final NoSuchFieldException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to find field for " + "property, %s", name), e);
            } catch (final IllegalAccessException e) {
                throw new IllegalArgumentException(
                        String.format("Unable to access setter for " + "property, %s", name), e);
            } catch (final InvocationTargetException e) {
                throw new IllegalArgumentException(String.format(
                        "Invocation target exception trying to " + "invoker setter for the %s property", name),
                        e);
            } catch (final NullPointerException e) {
                throw new IllegalArgumentException(
                        String.format("No appropriate method to " + "write value %s ", value.toString()), e);
            }
        }
    }

    return bean;
}

From source file:datamine.storage.idl.generator.java.InterfaceGenerator.java

public static String getListSizeGetterName(Field field) {
    return new StringBuilder().append("get")
            .append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, field.getName())).append("Size")
            .toString();/*from  ww  w.  j  ava2s  .  co m*/
}

From source file:org.jraf.androidcontentprovidergenerator.Main.java

private void loadModel(File inputDir) throws IOException, JSONException {
    JSONObject config = getConfig(inputDir);
    String apiModelJavaPackage = config.getString(Json.API_MODEL_JAVA_PACKAGE);

    File[] entityFiles = inputDir.listFiles(new FileFilter() {
        @Override/* w w  w .  j a v a2  s  .c o  m*/
        public boolean accept(File pathname) {
            return !pathname.getName().startsWith("_") && pathname.getName().endsWith(".json");
        }
    });
    for (File entityFile : entityFiles) {
        if (Config.LOGD) {
            Log.d(TAG, entityFile.getCanonicalPath());
        }
        String entityName = FilenameUtils.getBaseName(entityFile.getCanonicalPath());
        if (Config.LOGD) {
            Log.d(TAG, "entityName=" + entityName);
        }
        Entity entity = new Entity(entityName);
        String fileContents = FileUtils.readFileToString(entityFile);
        JSONObject entityJson = new JSONObject(fileContents);

        // Fields
        JSONArray fieldsJson = entityJson.getJSONArray("fields");
        int len = fieldsJson.length();
        for (int i = 0; i < len; i++) {
            JSONObject fieldJson = fieldsJson.getJSONObject(i);
            if (Config.LOGD) {
                Log.d(TAG, "fieldJson=" + fieldJson);
            }
            String name = fieldJson.getString(Field.Json.NAME);
            String type = fieldJson.getString(Field.Json.TYPE);
            boolean isIndex = fieldJson.optBoolean(Field.Json.INDEX, false);
            boolean isNullable = fieldJson.optBoolean(Field.Json.NULLABLE, true);
            String defaultValue = fieldJson.optString(Field.Json.DEFAULT_VALUE);
            String enumName = fieldJson.optString(Field.Json.ENUM_NAME);
            JSONArray enumValuesJson = fieldJson.optJSONArray(Field.Json.ENUM_VALUES);
            List<EnumValue> enumValues = new ArrayList<EnumValue>();
            if (enumValuesJson != null) {
                int enumLen = enumValuesJson.length();
                for (int j = 0; j < enumLen; j++) {
                    Object enumValue = enumValuesJson.get(j);
                    if (enumValue instanceof String) {
                        // Name only
                        enumValues.add(new EnumValue((String) enumValue, null));
                    } else {
                        // Name and Javadoc
                        JSONObject enumValueJson = (JSONObject) enumValue;
                        String enumValueName = (String) enumValueJson.keys().next();
                        String enumValueJavadoc = enumValueJson.getString(enumValueName);
                        enumValues.add(new EnumValue(enumValueName, enumValueJavadoc));
                    }
                }
            }
            Field field = new Field(name, type, isIndex, isNullable, defaultValue, enumName, enumValues);
            entity.addField(field);
        }

        // API
        JSONObject apiJson = entityJson.optJSONObject("api");
        if (apiJson != null) {
            // Automatic endpoints
            JSONArray autoApiEndpointsJson = apiJson.optJSONArray("autoEndpoints");
            if (autoApiEndpointsJson != null) {
                for (int i = 0; i < autoApiEndpointsJson.length(); i++) {
                    String autoApiEndpointJson = autoApiEndpointsJson.getString(i);
                    ApiParam idParam = new ApiParam("id", Type.fromJsonName("Integer"), "Path");

                    if (autoApiEndpointJson.equals("index")) {
                        entity.addApiMethod(new ApiEndpoint("get" + entity.getNameCamelCase() + "List",
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()),
                                "GET", new ArrayList<ApiParam>(), false, false,
                                Type.fromJsonName("java.util.List<" + entity.getNameCamelCase() + ">"),
                                "Retrieves a list of " + entity.getNameCamelCase() + " models."));
                    } else if (autoApiEndpointJson.equals("get")) {
                        entity.addApiMethod(new ApiEndpoint("get" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}",
                                "GET", new ArrayList<ApiParam>(Arrays.asList(idParam)), false, false,
                                Type.fromJsonName(entity.getNameCamelCase()),
                                "Retrieves an instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("post")) {
                        ArrayList<ApiParam> postParams = new ArrayList<ApiParam>();

                        // @TODO, not the right field
                        for (Field field : entity.getFields()) {
                            postParams.add(
                                    new ApiParam(field.getNameCamelCaseLowerCase(), field.getType(), "Field"));
                        }

                        entity.addApiMethod(new ApiEndpoint("post" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()),
                                "POST", postParams, true, false, Type.fromJsonName(entity.getNameCamelCase()),
                                "Creates a new instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("put")) {
                        ArrayList<ApiParam> putParams = new ArrayList<ApiParam>();
                        putParams.add(idParam);

                        // @TODO, not the right field
                        for (Field field : entity.getFields()) {
                            putParams.add(
                                    new ApiParam(field.getNameCamelCaseLowerCase(), field.getType(), "Field"));
                        }

                        entity.addApiMethod(new ApiEndpoint("put" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}",
                                "POST", putParams, true, false, Type.fromJsonName(entity.getNameCamelCase()),
                                "Updates an instance of a " + entity.getNameCamelCase() + " model."));
                    } else if (autoApiEndpointJson.equals("delete")) {
                        entity.addApiMethod(new ApiEndpoint("delete" + entity.getNameCamelCase(),
                                "/" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,
                                        entity.getNameCamelCase()) + "/{id}/delete",
                                "GET", new ArrayList<ApiParam>(Arrays.asList(idParam)), false, false,
                                Type.fromJsonName(entity.getNameCamelCase()),
                                "Deletes an instance of a " + entity.getNameCamelCase() + " model."));
                    }
                }
            }

            // Specific endpoints
            JSONArray apiEndpointsJson = apiJson.optJSONArray("endpoints");
            if (apiEndpointsJson != null) {
                for (int i = 0; i < apiEndpointsJson.length(); i++) {
                    JSONObject apiEndpointJson = apiEndpointsJson.getJSONObject(i);

                    String name = apiEndpointJson.getString(ApiEndpoint.Json.NAME);
                    String method = apiEndpointJson.getString(ApiEndpoint.Json.METHOD);
                    String endpoint = apiEndpointJson.getString(ApiEndpoint.Json.ENDPOINT);
                    String description = apiEndpointJson.getString(ApiEndpoint.Json.DESCRIPTION);
                    boolean isFormUrlEncoded = apiEndpointJson.optBoolean(ApiEndpoint.Json.IS_FORM_URL_ENCODED,
                            false);
                    boolean isMultipart = apiEndpointJson.optBoolean(ApiEndpoint.Json.IS_MULTIPART, false);
                    Type returnType = Type.fromJsonName(
                            apiEndpointJson.optString(ApiEndpoint.Json.RETURN_TYPE, entity.getNameCamelCase()));

                    List<ApiParam> params = new ArrayList<ApiParam>();
                    JSONArray pathParamsJson = apiEndpointJson.optJSONArray(ApiEndpoint.Json.PARAMETERS);
                    if (pathParamsJson != null) {
                        for (int j = 0; j < pathParamsJson.length(); j++) {
                            JSONObject pathParamJson = pathParamsJson.getJSONObject(j);
                            String paramName = pathParamJson.getString(ApiParam.Json.NAME);
                            Type paramType = Type.fromJsonName(pathParamJson.getString(ApiParam.Json.TYPE));
                            String placement = pathParamJson.optString(ApiParam.Json.PLACEMENT, "Path");
                            params.add(new ApiParam(paramName, paramType, placement));
                        }
                    }

                    entity.addApiMethod(new ApiEndpoint(name, endpoint, method, params, isFormUrlEncoded,
                            isMultipart, returnType, description));
                }
            }

            // API Fields
        }

        // Constraints (optional)
        JSONArray constraintsJson = entityJson.optJSONArray("constraints");
        if (constraintsJson != null) {
            len = constraintsJson.length();
            for (int i = 0; i < len; i++) {
                JSONObject constraintJson = constraintsJson.getJSONObject(i);
                if (Config.LOGD) {
                    Log.d(TAG, "constraintJson=" + constraintJson);
                }
                String name = constraintJson.getString(Constraint.Json.NAME);
                String definition = constraintJson.getString(Constraint.Json.DEFINITION);
                Constraint constraint = new Constraint(name, definition);
                entity.addConstraint(constraint);
            }
        }

        Model.get().addEntity(entity);
    }
    // Header (optional)
    File headerFile = new File(inputDir, "header.txt");
    if (headerFile.exists()) {
        String header = FileUtils.readFileToString(headerFile).trim();
        Model.get().setHeader(header);
    }
    if (Config.LOGD) {
        Log.d(TAG, Model.get().toString());
    }
}

From source file:com.google.cloud.trace.guice.annotation.ManagedTracerSpanInterceptor.java

private String convertJavaName(String name) {
    return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
}

From source file:com.google.api.codegen.util.Name.java

/** Returns the identifier in lower-underscore format. */
public String toLowerUnderscore() {
    return toUnderscore(CaseFormat.LOWER_UNDERSCORE);
}

From source file:io.prestosql.operator.aggregation.AggregationUtils.java

public static String generateAggregationName(String baseName, TypeSignature outputType,
        List<TypeSignature> inputTypes) {
    StringBuilder sb = new StringBuilder();
    sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString()));
    for (TypeSignature inputType : inputTypes) {
        sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString()));
    }//from www  .jav a  2s.c o  m
    sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH)));

    return sb.toString();
}