Java Code Examples for org.apache.commons.lang3.StringUtils#capitalize()

The following examples show how to use org.apache.commons.lang3.StringUtils#capitalize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaskellHttpClientCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public String toEnumVarName(String value, String datatype) {
    if (!genEnums) return super.toEnumVarName(value, datatype);

    List<String> num = new ArrayList<>(Arrays.asList("integer", "int", "double", "long", "float"));
    if (value.length() == 0) {
        return "'Empty";
    }

    // for symbol, e.g. $, #
    if (getSymbolName(value) != null) {
        return "'" + StringUtils.capitalize(sanitizeName(getSymbolName(value)));
    }

    // number
    if (num.contains(datatype.toLowerCase(Locale.ROOT))) {
        String varName = "Num" + value;
        varName = varName.replaceAll("-", "Minus_");
        varName = varName.replaceAll("\\+", "Plus_");
        varName = varName.replaceAll("\\.", "_Dot_");
        return "'" + StringUtils.capitalize(sanitizeName(varName));
    }

    return "'" + StringUtils.capitalize(sanitizeName(value));
}
 
Example 2
Source File: ReflectionHelper.java    From streamline with Apache License 2.0 6 votes vote down vote up
public static <T> T invokeSetter(String propertyName, Object object, Object valueToSet) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    String methodName = "set" + StringUtils.capitalize(propertyName);
    Method method = null;
    try {
        method = object.getClass().getMethod(methodName, valueToSet.getClass());
    } catch (NoSuchMethodException ex) {
        // try setters that accept super types
        Method[] methods = object.getClass().getMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals(methodName) && methods[i].getParameterCount() == 1) {
                if (methods[i].getParameters()[0].getType().isAssignableFrom(valueToSet.getClass())) {
                    method = methods[i];
                    break;
                }
            }
        }
        if (method == null) {
            throw ex;
        }
    }
    return (T) method.invoke(object, valueToSet);
}
 
Example 3
Source File: BeanUtils.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static <T> T populate(final KeyValue properties, final T obj) {
    Class<?> clazz = obj.getClass();
    try {

        final Set<String> keySet = properties.keySet();
        for (String key : keySet) {
            String[] keyGroup = key.split("\\.");
            for (int i = 0; i < keyGroup.length; i++) {
                keyGroup[i] = keyGroup[i].toLowerCase();
                keyGroup[i] = StringUtils.capitalize(keyGroup[i]);
            }
            String beanFieldNameWithCapitalization = StringUtils.join(keyGroup);
            try {
                setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getString(key));
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
                //ignored...
            }
        }
    } catch (RuntimeException e) {
        log.warn("Error occurs !", e);
    }
    return obj;
}
 
Example 4
Source File: NotifyIssueChangesJob.java    From vk-java-sdk with MIT License 6 votes vote down vote up
private String changedIssueMessage(Issue issue, IssueChange change) {
    String changes = "";
    if (change != null) {
        changes = "Changes:\n";
        for (IssueChangeField field : change.getFields()) {
            if (SKIP_FIELDS.contains(field.getName()) || StringUtils.isEmpty(field.getName())) {
                continue;
            }

            if (field.getName().equals("updaterName")) {
                changes += "Updater: " + field.getValue() + "\n";
            } else {
                changes += StringUtils.capitalize(field.getName()) + ": " + field.getOldValue() + " > " + field.getNewValue() + "\n";
            }
        }

        changes += "\n\n";
    }

    String url = Application.ytHost() + "/issue/" + issue.getId();
    String summary = issue.getFieldValue("summary") != null ? issue.getFieldValue("summary") : "";
    String description = issue.getFieldValue("description") != null ? issue.getFieldValue("description") : "";
    String title = summary.isEmpty() ? description.substring(0, Math.min(description.length(), 100)) + "..." : summary;
    return issue.getId() + "\n" + "Issue updated" + "\n" + issue.getFieldValue("Type") + " - " + title + "\n\n" + changes + url + "\n-------";
}
 
Example 5
Source File: AbstractTask.java    From gocd with Apache License 2.0 5 votes vote down vote up
public String getConditionsForDisplay() {
    if (runIfConfigs.isEmpty()) {
        return StringUtils.capitalize(RunIfConfig.PASSED.toString());
    }
    List<String> capitalized = runIfConfigs.stream().map(f -> StringUtils.capitalize(f.toString())).collect(Collectors.toList());

    return StringUtils.join(capitalized, ", ");
}
 
Example 6
Source File: WrapCopierFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static String getGetterName(Field field) throws Exception {
	if (field.getType() == boolean.class) {
		return IS_PREFIX + StringUtils.capitalize(field.getName());
	} else {
		return GET_PREFIX + StringUtils.capitalize(field.getName());
	}
}
 
Example 7
Source File: ReflectionUtils.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
/**
 * 调用Getter方法.
 * 支持多级,如:对象名.对象名.方法
 */
public static Object invokeGetter(Object obj, String propertyName) {
    Object object = obj;
    for (String name : StringUtils.split(propertyName, ".")) {
        String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
        object = invokeMethod(object, getterMethodName, new Class[]{}, new Object[]{});
    }
    return object;
}
 
Example 8
Source File: TelemetryGenerator.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
private static Target generateTargetObject(Map<String, Object> targetObject) {

    Target target =
        new Target(
            (String) targetObject.get(JsonKey.ID),
            StringUtils.capitalize((String) targetObject.get(JsonKey.TYPE)));
    if (targetObject.get(JsonKey.ROLLUP) != null) {
      target.setRollup((Map<String, String>) targetObject.get(JsonKey.ROLLUP));
    }
    return target;
  }
 
Example 9
Source File: ReflectUtils.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 调用Getter方法.
 * 支持多级,如:对象名.对象名.方法
 */
@SuppressWarnings("unchecked")
public static <E> E invokeGetter(Object obj, String propertyName)
{
    Object object = obj;
    for (String name : StringUtils.split(propertyName, "."))
    {
        String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
        object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
    }
    return (E) object;
}
 
Example 10
Source File: WebAbstractDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void addColumnInternal(ColumnImpl<E> column, int index) {
    Grid.Column<E, ?> gridColumn = component.addColumn(
            new EntityValueProvider<>(column.getPropertyPath()));

    columns.put(column.getId(), column);
    columnsOrder.add(index, column);

    final String caption = StringUtils.capitalize(column.getCaption() != null
            ? column.getCaption()
            : generateColumnCaption(column));
    column.setCaption(caption);

    if (column.getOwner() == null) {
        column.setOwner(this);
    }

    MetaPropertyPath propertyPath = column.getPropertyPath();
    if (propertyPath != null) {
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        String storeName = metadataTools.getStoreName(propertyMetaClass);
        if (metadataTools.isLob(metaProperty)
                && !persistenceManagerClient.supportsLobSortingAndFiltering(storeName)) {
            column.setSortable(false);
        }
    }

    setupGridColumnProperties(gridColumn, column);

    component.setColumnOrder(getColumnOrder());
}
 
Example 11
Source File: FlowCondition.java    From requirementsascode with Apache License 2.0 5 votes vote down vote up
private String getFlowPredicate(Flow flow) {
String predicate = getFlowPosition(flow) + getFlowPredicateSeparator(flow, PREDICATE_SEPARATOR)
	+ getCondition(flow);
String sep = "".equals(predicate) ? "" : PREDICATE_POSTFIX;
String capitalizedPredicateWithColon = StringUtils.capitalize(predicate) + sep;
return capitalizedPredicateWithColon;
   }
 
Example 12
Source File: Reflections.java    From spring-boot-quickstart with Apache License 2.0 4 votes vote down vote up
/**
 * 调用Getter方法.
 */
public static Object invokeGetter(Object obj, String propertyName) {
	String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(propertyName);
	return invokeMethod(obj, getterMethodName, new Class[] {}, new Object[] {});
}
 
Example 13
Source File: SampledPolicy.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public String label() {
  return StringUtils.capitalize(name().toLowerCase(US));
}
 
Example 14
Source File: Strings.java    From startup-os with Apache License 2.0 4 votes vote down vote up
public static String capitalize(String string) {
  return StringUtils.capitalize(string);
}
 
Example 15
Source File: AbstractResponseGenerator.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
AbstractResponseGenerator(MetaResource metaResource) {
  this.metaResource = metaResource;
  prefix = StringUtils.capitalize(metaResource.getResourceType());
}
 
Example 16
Source File: AuditEventToGrpcAuditEventConverter.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String formatAuditEventName(AuditEvent source) {
    String camelCaseFormat = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, source.getEventName().name());
    return StringUtils.capitalize(camelCaseFormat);
}
 
Example 17
Source File: MotorizedDoorProxyModel.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public String label() {
    return StringUtils.capitalize(StringUtils.lowerCase(name()));
}
 
Example 18
Source File: Res.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String getWithCap(String key) {
    return StringUtils.capitalize(get(key));
}
 
Example 19
Source File: FieldNameValidator.java    From conjure with Apache License 2.0 2 votes vote down vote up
/**
 * Converts this {@link FieldName} to an upper camel case string (e.g. myVariant -> MyVariant).
 * Note that the resultant string is no longer a valid {@link FieldName}.
 */
public static String capitalize(FieldName fieldName) {
    return StringUtils.capitalize(fieldName.get());
}
 
Example 20
Source File: MagicFormat.java    From MtgDesktopCompanion with GNU General Public License v3.0 2 votes vote down vote up
public void setFormat(FORMATS standard) {
	format = StringUtils.capitalize(standard.name().toLowerCase());
	
}