Java Code Examples for io.micronaut.core.naming.NameUtils#capitalize()

The following examples show how to use io.micronaut.core.naming.NameUtils#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: PersistentEntity.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * Computes a dot separated property path for the given camel case path.
 * @param camelCasePath The camel case path
 * @return The dot separated version or null if it cannot be computed
 */
default Optional<String> getPath(String camelCasePath) {
    List<String> path = Arrays.stream(CAMEL_CASE_SPLIT_PATTERN.split(camelCasePath))
                              .map(NameUtils::decapitalize)
                              .collect(Collectors.toList());

    if (CollectionUtils.isNotEmpty(path)) {
        Iterator<String> i = path.iterator();
        StringBuilder b = new StringBuilder();
        PersistentEntity currentEntity = this;
        String name = null;
        while (i.hasNext()) {
            name = name == null ? i.next() : name + NameUtils.capitalize(i.next());
            PersistentProperty sp = currentEntity.getPropertyByName(name);
            if (sp == null) {
                PersistentProperty identity = currentEntity.getIdentity();
                if (identity != null) {
                    if (identity.getName().equals(name)) {
                        sp = identity;
                    } else if (identity instanceof Association) {
                        PersistentEntity idEntity = ((Association) identity).getAssociatedEntity();
                        sp = idEntity.getPropertyByName(name);
                    }
                }
            }
            if (sp != null) {
                b.append(name);
                if (i.hasNext()) {
                    b.append('.');
                }
                if (sp instanceof Association) {
                    currentEntity = ((Association) sp).getAssociatedEntity();
                    name = null;
                }
            }
        }

        return b.length() == 0 || b.charAt(b.length() - 1) == '.' ? Optional.empty() : Optional.of(b.toString());

    }
    return Optional.empty();
}
 
Example 2
Source File: PersistentProperty.java    From micronaut-data with Apache License 2.0 2 votes vote down vote up
/**
 * The name with the first letter in upper case as per Java bean conventions.
 * @return The capitilized name
 */
default @NonNull String getCapitilizedName() {
    return NameUtils.capitalize(getName());
}