All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.db2code.convert.JavaPropertyConverter Maven / Gradle / Ivy

There is a newer version: 1.3.8
Show newest version
package org.db2code.convert;

public class JavaPropertyConverter {
    public static String camelCaseFromSnakeCaseInitCap(String columnName) {
        return camelCaseFromSnakeCase(columnName, true);
    }

    public static String camelCaseFromSnakeCaseInitLow(String columnName) {
        return camelCaseFromSnakeCase(columnName, false);
    }

    private static String camelCaseFromSnakeCase(String columnName, boolean initCap) {
        String[] words = columnName.split("[\\W_]");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if (word == null || word.isBlank()) {
                continue;
            }
            if (i == 0) {
                if (initCap) {
                    sb.append(Character.toUpperCase(word.charAt(0)));
                    sb.append(word.substring(1).toLowerCase());
                } else {
                    sb.append(word.toLowerCase());
                }
            } else {
                sb.append(Character.toUpperCase(word.charAt(0)));
                sb.append(word.substring(1).toLowerCase());
            }
        }
        return sb.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy