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:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch.java

private String buildWhere(final String tableName, final Collection<String> tableFields,
        final Condition condition) {
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append(" WHERE 1=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)) {
                sqlBuilder.append(" AND ").append(lowerUnderscore).append("=?");
            }/*from   w  ww. ja v  a 2  s. co m*/
        }
    }
    if (null != condition.getStartTime()) {
        sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append(">=?");
    }
    if (null != condition.getEndTime()) {
        sqlBuilder.append(" AND ").append(getTableTimeField(tableName)).append("<=?");
    }
    return sqlBuilder.toString();
}

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

/**
 * Returns a new Name containing the pieces from this Name plus the given identifier added on the
 * end./*from w  ww  . j  a v a 2s  . c om*/
 */
public Name join(String identifier) {
    validateLowerUnderscore(identifier);
    List<NamePiece> newPieceList = new ArrayList<>();
    newPieceList.addAll(namePieces);
    newPieceList.add(new NamePiece(identifier, CaseFormat.LOWER_UNDERSCORE));
    return new Name(newPieceList);
}

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 w  w .j  av  a  2s  . 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.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  v  a2 s  .  com
        }
    }
    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.github.dozermapper.protobuf.util.ProtoUtils.java

/**
 * Converts name to CamelCase/*www.  j a  va 2s. c om*/
 *
 * @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.google.api.codegen.transformer.SampleTransformer.java

/**
 * Creates a region tag from the spec, replacing any {@code %m}, {@code %c}, and {@code %v}
 * placeholders with the method name, calling form name, and value set id, respectively.
 *//* www  .  j a  v a 2s  .c  o m*/
private static String regionTagFromSpec(String spec, String methodName, CallingForm callingForm,
        String valueSetId) {
    final String DEFAULT_REGION_SPEC = "sample";

    if (Strings.isNullOrEmpty(spec)) {
        spec = DEFAULT_REGION_SPEC;
    }
    return spec.replace("%m", CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, methodName))
            .replace("%c", callingForm.toLowerCamel()).replace("%v", valueSetId);
}

From source file:com.geemvc.taglib.form.FormTagSupport.java

public String getName() {
    if (name == null)
        name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, handlerMethod().getName());

    return name;
}

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   ww w  .  j  a v  a  2s .  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();
}

From source file:com.cinchapi.concourse.shell.ConcourseShell.java

/**
 * Attempt to return the {@link #ACCESSIBLE_API_METHODS API method} that is
 * the closest match for the specified {@code alias}.
 * <p>/*from  w w  w .j a  v  a2 s.co  m*/
 * This method can be used to take a user supplied method name that does not
 * match any of the {@link #ACCESSIBLE_API_METHODS provided} ones, but can
 * be reasonably assumed to be a valid alias of some sort (i.e. an API
 * method name in underscore case as opposed to camel case).
 * </p>
 * 
 * @param alias the method name that may be an alias for one of the provided
 *            API methods
 * @return the actual API method that {@code alias} should resolve to, if it
 *         is possible to determine that; otherwise {@code null}
 */
@Nullable
private static String tryGetCorrectApiMethod(String alias) {
    String camel = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, alias);
    String expanded = com.cinchapi.concourse.util.Strings.ensureStartsWith(camel, "concourse.");
    return methods.contains(expanded) && !camel.equals(alias) ? camel : null;
}

From source file:brooklyn.util.flags.TypeCoercions.java

/**
 * Type coercion {@link Function function} for {@link Enum enums}.
 * <p>//from  w  w w . j  a  v  a 2s  . c  o m
 * Tries to convert the string to {@link CaseFormat#UPPER_UNDERSCORE} first,
 * handling all of the different {@link CaseFormat format} possibilites. Failing 
 * that, it tries a case-insensitive comparison with the valid enum values.
 * <p>
 * Returns {@code defaultValue} if the string cannot be converted.
 *
 * @see TypeCoercions#coerce(Object, Class)
 * @see Enum#valueOf(Class, String)
 */
public static <E extends Enum<E>> Function<String, E> stringToEnum(final Class<E> type,
        @Nullable final E defaultValue) {
    return new Function<String, E>() {
        @Override
        public E apply(String input) {
            Preconditions.checkNotNull(input, "input");
            List<String> options = ImmutableList.of(input,
                    CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, input),
                    CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, input),
                    CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input),
                    CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, input));
            for (String value : options) {
                try {
                    return Enum.valueOf(type, value);
                } catch (IllegalArgumentException iae) {
                    continue;
                }
            }
            Maybe<E> result = Enums.valueOfIgnoreCase(type, input);
            return (result.isPresent()) ? result.get() : defaultValue;
        }
    };
}