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:edu.berkeley.ground.postgres.util.PostgresUtils.java

public static String executeQueryToJson(Database dbSource, String sql) throws GroundException {
    Logger.debug("executeQueryToJson: {}", sql);

    try {//from w  ww .j  a  v a 2  s .  c  o  m
        Connection con = dbSource.getConnection();
        Statement stmt = con.createStatement();

        final ResultSet resultSet = stmt.executeQuery(sql);
        final long columnCount = resultSet.getMetaData().getColumnCount();
        final List<Map<String, Object>> objList = new ArrayList<>();

        while (resultSet.next()) {
            final Map<String, Object> rowData = new HashMap<>();

            for (int column = 1; column <= columnCount; column++) {
                String key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL,
                        resultSet.getMetaData().getColumnLabel(column));
                rowData.put(key, resultSet.getObject(column));
            }

            objList.add(rowData);
        }

        stmt.close();
        con.close();
        return GroundUtils.listToJson(objList);
    } catch (SQLException e) {
        Logger.error("ERROR:  executeQueryToJson  SQL : {} Message: {} Trace: {}", sql, e.getMessage(),
                e.getStackTrace());
        throw new GroundException(e);
    }
}

From source file:org.jclouds.cloudstack.domain.StorageType.java

@Override
public String toString() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}

From source file:org.jclouds.cloudstack.domain.SystemVmType.java

@Override
public String toString() {
    return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()).toLowerCase();
}

From source file:com.github.ko2ic.plugin.eclipse.taggen.common.domain.valueobject.NameRuleString.java

public String phraseVariableName() {
    String value = str;/*  w  ww  .jav  a  2s  . c o  m*/
    if (Character.isUpperCase(str.charAt(0))) {
        if (str.contains("_")) {
            value = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str);
        } else {
            value = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, str);
        }
    } else {
        if (str.contains("_")) {
            value = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str);
        }
    }
    return value;
}

From source file:org.glowroot.ui.QueryStrings.java

static <T> /*@NonNull*/ T decode(Map<String, List<String>> queryParameters, Class<T> clazz) throws Exception {
    Class<?> immutableClass = getImmutableClass(clazz);
    Method builderMethod = immutableClass.getDeclaredMethod("builder");
    Object builder = builderMethod.invoke(null);
    checkNotNull(builder);//from w ww . j a v  a2 s .  co  m
    Class<?> immutableBuilderClass = builder.getClass();
    Map<String, Method> setters = settersCache.getUnchecked(immutableBuilderClass);
    for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
        String key = entry.getKey();
        key = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key);
        // special rule for "-mbean" so that it will convert to "...MBean"
        key = key.replace("Mbean", "MBean");
        Method setter = setters.get(key);
        checkNotNull(setter, "Unexpected attribute: %s", key);
        Type valueType = setter.getGenericParameterTypes()[0];
        Object value;
        if (valueType instanceof ParameterizedType) {
            // only generic iterable supported
            valueType = ((ParameterizedType) valueType).getActualTypeArguments()[0];
            List<Object> parsedValues = Lists.newArrayList();
            for (String stringValue : entry.getValue()) {
                Object parsedValue = parseString(stringValue, (Class<?>) valueType);
                // ignore empty query param values, e.g. the empty percentile value in
                // percentile=&percentile=95&percentile=99
                if (parsedValue != null) {
                    parsedValues.add(parsedValue);
                }
            }
            value = parsedValues;
        } else {
            value = parseString(entry.getValue().get(0), (Class<?>) valueType);
        }
        setter.invoke(builder, value);
    }
    Method build = immutableBuilderClass.getDeclaredMethod("build");
    @SuppressWarnings("unchecked")
    T decoded = (T) build.invoke(builder);
    return checkNotNull(decoded);
}

From source file:org.elasticsearch.plugin.readonlyrest.acl.blocks.rules.SyncRule.java

protected String mkKey(Class<? extends Rule> c) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, c.getSimpleName().replace("SyncRule", ""));
}

From source file:org.zalando.jpa.eclipselink.customizer.NameUtils.java

/**
 * @param   name/*from   w  w w. j  a  v  a 2  s .  c o m*/
 *
 * @return
 */
public static String camelCaseToUnderscore(final String name) {
    return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
}

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

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

From source file:com.mysema.query.types.path.PathBuilderFactory.java

/**
 * Create a new PathBuilder instance for the given type
 * /*  w ww  . jav a  2  s .  c om*/
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public <T> PathBuilder<T> create(Class<T> clazz) {
    PathBuilder<T> rv = (PathBuilder<T>) paths.get(clazz);
    if (rv == null) {
        rv = new PathBuilder<T>(clazz,
                CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, clazz.getSimpleName()));
        paths.put(clazz, rv);
    }
    return rv;
}

From source file:aritzh.waywia.universe.Universe.java

public static Universe newUniverse(String name, File saveFolder, String defaultWorldName, InGameState state)
        throws IOException {
    String folderName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, name);
    File root = new File(saveFolder, folderName);
    if (!root.exists() && !root.mkdirs())
        throw new IOException("Could not create folder for new universe at: " + root.getAbsolutePath());

    Set<World> worlds = new HashSet<>();
    String worldName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, defaultWorldName);
    World defaultWorld = World.newWorld(worldName, root);

    BDSCompound comp = new BDSCompound("CustomData");

    Universe u = new Universe(name, root, worlds, defaultWorld, comp, state);
    u.toBDS().writeToFile(new File(root, "universe.dat"));
    return u;//from w w w .j  ava2  s.c o m
}