Example usage for org.apache.commons.lang3 StringUtils capitalize

List of usage examples for org.apache.commons.lang3 StringUtils capitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils capitalize.

Prototype

public static String capitalize(final String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:org.adorsys.waguia.lightxls.loader.SheetColumnToClazzFieldMatching.java

/**
 * I will check if columns name match to fields, and also validate getters/setters methods for properties.
 *///from   ww w  .  j  a  v a  2 s  . c  om
public boolean checkMatching() {
    boolean result = true;
    if (this.sheetColumns == null || this.clazzFields == null || this.clazzMethods == null) {
        throw new RuntimeException("Null value aren't required");
    }
    String[] tempArray = new String[clazzFields.length];//init the array.
    String[] fieldNames = fieldNames(clazzFields);
    //find matching ColumnName-FieldName and save them in a tempArray.
    for (int i = 0; i < this.sheetColumns.length; i++) {
        String sheetColumn = this.sheetColumns[i];
        for (int j = 0; j < fieldNames.length; j++) {
            String fieldName = fieldNames[j];
            if (sheetColumn.equals(fieldName)) {
                tempArray[j] = fieldName;//store matching fieldName/columnName in the array.
                break;
            }
        }
    }
    fieldNames = tempArray;
    if (clazzMethods.length < fieldNames.length)
        result = false;
    //TODO : Find spring's bean validator For getters/setters
    //Here I check if There are appropriate setter for founded fields.
    for (int i = 0; i < fieldNames.length; i++) {
        String fieldName = fieldNames[i];
        if (fieldName == null)
            continue;//check null value in the array.
        String setterMethodName = "set" + StringUtils.capitalize(fieldName);
        boolean methodFound = false;
        for (int j = 0; j < clazzMethods.length; j++) {
            Method method = clazzMethods[j];
            if (method.getName().equals(setterMethodName)) {
                methodFound = true;
                break;
            }
        }
        if (methodFound == false)
            result = false;
    }
    return result;
}

From source file:org.apache.asterix.common.config.ConfigUsageTest.java

public void generateUsage(String startDelim, String midDelim, String endDelim, EnumMap<Column, Boolean> align,
        PrintStream output) {/*from  www. j a  va 2 s.  co m*/
    ConfigManager configManager = getConfigManager();
    StringBuilder buf = new StringBuilder();

    final Column[] columns = Column.values();
    for (Section section : getSections(configManager)) {
        for (IOption option : getSectionOptions(configManager, section)) {
            for (Column column : columns) {
                if (align.computeIfAbsent(column, c -> false)) {
                    calculateMaxWidth(option, column);
                }
            }
        }
    }
    // output header
    for (Column column : columns) {
        buf.append(column.ordinal() == 0 ? startDelim : midDelim);
        pad(buf, StringUtils.capitalize(column.name().toLowerCase()),
                align.computeIfAbsent(column, c -> false) ? calculateMaxWidth(column, column.name()) : 0);
    }
    buf.append(endDelim).append('\n');

    StringBuilder sepLine = new StringBuilder();
    for (Column column : columns) {
        sepLine.append(column.ordinal() == 0 ? startDelim : midDelim);
        pad(sepLine, "", maxWidths.getOrDefault(column, 0), '-');
    }
    sepLine.append(endDelim).append('\n');
    buf.append(sepLine.toString().replace(' ', '-'));

    for (Section section : getSections(configManager)) {
        List<IOption> options = new ArrayList<>(getSectionOptions(configManager, section));
        options.sort(Comparator.comparing(IOption::ini));
        for (IOption option : options) {
            for (Column column : columns) {
                buf.append(column.ordinal() == 0 ? startDelim : midDelim);
                if (column == Column.SECTION) {
                    center(buf, extractValue(column, option), maxWidths.getOrDefault(column, 0));
                } else {
                    pad(buf, extractValue(column, option), maxWidths.getOrDefault(column, 0));
                }
            }
            buf.append(endDelim).append('\n');
        }
    }
    output.println(buf);
}

From source file:org.apache.bval.jsr.xml.ValidationMappingParser.java

private <A> Collection<String> processPropertyLevel(List<GetterType> getters, Class<A> beanClass,
        String defaultPackage, boolean ignoreAnnotatino) {
    List<String> getterNames = new ArrayList<String>();
    for (GetterType getterType : getters) {
        final String getterName = getterType.getName();
        final String methodName = "get" + StringUtils.capitalize(getterType.getName());
        if (getterNames.contains(methodName)) {
            throw new ValidationException(
                    getterName + " is defined more than once in mapping xml for bean " + beanClass.getName());
        }/* w ww.j a  v a  2  s .  c  o m*/
        getterNames.add(methodName);

        final Method method = getGetter(beanClass, getterName);
        if (method == null) {
            throw new ValidationException(
                    beanClass.getName() + " does not contain the property  " + getterName);
        }

        // ignore annotations
        final boolean ignoreGetterAnnotation = getterType.getIgnoreAnnotations() == null ? ignoreAnnotatino
                : getterType.getIgnoreAnnotations();
        factory.getAnnotationIgnores().setIgnoreAnnotationsOnMember(method, ignoreGetterAnnotation);

        // valid
        if (getterType.getValid() != null) {
            factory.addValid(beanClass, new MethodAccess(getterName, method));
        }

        // ConvertGroup
        for (final GroupConversionType conversion : getterType.getConvertGroup()) {
            final Class<?> from = loadClass(conversion.getFrom(), defaultPackage);
            final Class<?> to = loadClass(conversion.getTo(), defaultPackage);
            final MetaConstraint<?, ?> constraint = new MetaConstraint<A, Annotation>(beanClass, method,
                    new AnnotationProxyBuilder.ConvertGroupAnnotation(from, to));
            factory.addMetaConstraint(beanClass, constraint);
        }

        // constraints
        for (ConstraintType constraintType : getterType.getConstraint()) {
            MetaConstraint<?, ?> metaConstraint = createConstraint(constraintType, beanClass, method,
                    defaultPackage);
            factory.addMetaConstraint(beanClass, metaConstraint);
        }
    }

    return getterNames;
}

From source file:org.apache.bval.jsr.xml.ValidationMappingParser.java

@Privileged
private static Method getGetter(Class<?> clazz, String propertyName) {
    try {//  w  ww .j  ava  2s . co m
        final String p = StringUtils.capitalize(propertyName);
        try {
            return clazz.getMethod("get" + p);
        } catch (NoSuchMethodException e) {
            return clazz.getMethod("is" + p);
        }
    } catch (NoSuchMethodException e) {
        return null;
    }
}

From source file:org.apache.drill.common.expression.fn.JodaDateValidator.java

/**
 * Replaces all postgres patterns from {@param pattern},
 * available in postgresToJodaMap keys to jodaTime equivalents.
 *
 * @param pattern date pattern in postgres format
 * @return date pattern with replaced patterns in joda format
 *//*from w ww.jav a 2  s . c  o  m*/
public static String toJodaFormat(String pattern) {
    // replaces escape character for text delimiter
    StringBuilder builder = new StringBuilder(
            pattern.replaceAll(POSTGRES_ESCAPE_CHARACTER, JODA_ESCAPE_CHARACTER));

    int start = 0; // every time search of postgres token in pattern will start from this index.
    int minPos; // min position of the longest postgres token
    do {
        // finds first value with max length
        minPos = builder.length();
        PostgresDateTimeConstant firstMatch = null;
        for (PostgresDateTimeConstant postgresPattern : postgresToJodaMap.keySet()) {
            // keys sorted in length decreasing
            // at first search longer tokens to consider situation where some tokens are the parts of large tokens
            // example: if pattern contains a token "DDD", token "DD" would be skipped, as a part of "DDD".
            int pos;
            // some tokens can't be in upper camel casing, so we ignore them here.
            // example: DD, DDD, MM, etc.
            if (postgresPattern.hasCamelCasing()) {
                // finds postgres tokens in upper camel casing
                // example: Month, Mon, Day, Dy, etc.
                pos = builder.indexOf(StringUtils.capitalize(postgresPattern.getName()), start);
                if (pos >= 0 && pos < minPos) {
                    firstMatch = postgresPattern;
                    minPos = pos;
                    if (minPos == start) {
                        break;
                    }
                }
            }
            // finds postgres tokens in lower casing
            pos = builder.indexOf(postgresPattern.getName().toLowerCase(), start);
            if (pos >= 0 && pos < minPos) {
                firstMatch = postgresPattern;
                minPos = pos;
                if (minPos == start) {
                    break;
                }
            }
            // finds postgres tokens in upper casing
            pos = builder.indexOf(postgresPattern.getName().toUpperCase(), start);
            if (pos >= 0 && pos < minPos) {
                firstMatch = postgresPattern;
                minPos = pos;
                if (minPos == start) {
                    break;
                }
            }
        }
        // replaces postgres token, if found and it does not escape character
        if (minPos < builder.length() && firstMatch != null) {
            String jodaToken = postgresToJodaMap.get(firstMatch);
            // checks that token is not a part of escape sequence
            if (StringUtils.countMatches(builder.subSequence(0, minPos), JODA_ESCAPE_CHARACTER) % 2 == 0) {
                int offset = minPos + firstMatch.getName().length();
                builder.replace(minPos, offset, jodaToken);
                start = minPos + jodaToken.length();
            } else {
                int endEscapeCharacter = builder.indexOf(JODA_ESCAPE_CHARACTER, minPos);
                if (endEscapeCharacter >= 0) {
                    start = endEscapeCharacter;
                } else {
                    break;
                }
            }
        }
    } while (minPos < builder.length());
    return builder.toString();
}

From source file:org.apache.ibatis.reflection.wrapper.MapWrapper.java

/**
  * ??Camel???/*  w  ww  .j av  a2s  . co m*/
  * 
  * input: shop_name
  * output:shopName
  * @param column
  * @return
  */
private String changDBColumnToPropertyName(String column) {
    if (StringUtils.isBlank(column) || column.equals("_parameter")//???
            || column.startsWith("__frch")//foreach
            || column.indexOf("_") == -1) {//??
        return column;
    }

    String[] words = column.toLowerCase().split("_");//???
    StringBuilder builder = new StringBuilder(words[0]);
    for (int i = 1; i < words.length; i++) {
        builder.append(StringUtils.capitalize(words[i]));
    }

    return builder.toString();
}

From source file:org.apache.johnzon.maven.plugin.ExampleToModelMojo.java

private void fieldGetSetMethods(final Writer writer, final String jsonField, final String field,
        final String type, final String prefix, final int arrayLevel, final Collection<String> imports)
        throws IOException {
    final String actualType = buildArrayType(arrayLevel, type);
    final String actualField = buildValidFieldName(jsonField);
    final String methodName = StringUtils.capitalize(actualField);

    if (!jsonField.equals(field)) { // TODO: add it to imports in eager visitor
        imports.add("org.apache.johnzon.mapper.JohnzonProperty");
        writer.append(prefix).append("@JohnzonProperty(\"").append(jsonField).append("\")\n");
    }//from  ww w  .j  a va 2 s .  co m

    writer.append(prefix).append("private ").append(actualType).append(" ").append(actualField).append(";\n");
    writer.append(prefix).append("public ").append(actualType).append(" get").append(methodName)
            .append("() {\n");
    writer.append(prefix).append("    return ").append(actualField).append(";\n");
    writer.append(prefix).append("}\n");
    writer.append(prefix).append("public void set").append(methodName).append("(final ").append(actualType)
            .append(" newValue) {\n");
    writer.append(prefix).append("    this.").append(actualField).append(" = newValue;\n");
    writer.append(prefix).append("}\n");
}

From source file:org.apache.johnzon.maven.plugin.ExampleToModelMojo.java

private void generateFile(final JsonReaderFactory readerFactory, final File source)
        throws MojoExecutionException {
    final String javaName = StringUtils.capitalize(toJavaName(source.getName()));
    final String jsonToClass = packageBase + '.' + javaName;
    final File outputFile = new File(target, jsonToClass.replace('.', '/') + ".java");

    outputFile.getParentFile().mkdirs();
    FileWriter writer = null;/*from  www .ja  v a2  s  .  c o m*/
    try {
        writer = new FileWriter(outputFile);
        generate(readerFactory, source, writer, javaName);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (final IOException e) {
            // no-op
        }
    }
}

From source file:org.apache.johnzon.maven.plugin.ExampleToModelMojo.java

private String toJavaName(final String file) {
    final StringBuilder builder = new StringBuilder();
    boolean nextUpper = false;
    for (final char anIn : file.replace(".json", "").toCharArray()) {
        if (FORBIDDEN_JAVA_NAMES.contains(anIn)) {
            nextUpper = true;/*from w  w w.ja v  a  2 s .  c  o  m*/
        } else if (nextUpper) {
            builder.append(Character.toUpperCase(anIn));
            nextUpper = false;
        } else {
            builder.append(anIn);
        }
    }
    return StringUtils.capitalize(builder.toString());
}

From source file:org.apache.olingo.ext.proxy.utils.CoreUtils.java

private static Class<?> getPropertyClass(final Class<?> entityClass, final String propertyName) {
    Class<?> propertyClass = null;
    try {/*from  ww  w .jav a 2  s  .c om*/
        final Method getter = entityClass.getMethod("get" + StringUtils.capitalize(propertyName));
        if (getter != null) {
            propertyClass = getter.getReturnType();
        }
    } catch (Exception e) {
        LOG.error("Could not determine the Java type of {}", propertyName, e);
    }
    return propertyClass;
}