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

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

Introduction

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

Prototype

public static String[] splitByCharacterTypeCamelCase(final String str) 

Source Link

Document

Splits a String by Character type as returned by java.lang.Character.getType(char) .

Usage

From source file:com.sxj.spring.modules.util.CaseFormatUtils.java

/**
 * camel case convert to under score case
 */// w  w w  . j a v a2s  .  c  om
public static String camelToUnderScore(String camelCase) {
    return StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(camelCase), "_").toLowerCase();
}

From source file:name.martingeisse.common.util.string.StringUtil.java

/**
 * Converts a camel-case name to a lower-case underscored name like
 * this: "myFooBar" -> "my_foo_bar".//from  w w w. j  a  va  2s .c o  m
 * @param s the string to convert
 * @return the underscored string
 */
public static String convertCamelCaseToLowercaseUnderscores(String s) {
    String[] segments = StringUtils.splitByCharacterTypeCamelCase(s);
    for (int i = 0; i < segments.length; i++) {
        segments[i] = segments[i].toLowerCase();
    }
    return StringUtils.join(segments, '_');
}

From source file:ctrus.pa.bow.java.CamelcaseTransformer.java

public String transform(String term) {
    String transformedTerm = "";
    String[] split = StringUtils.splitByCharacterTypeCamelCase(term);
    for (String eachTerm : split)
        transformedTerm = transformedTerm + " " + eachTerm;
    return StringUtils.strip(transformedTerm);
}

From source file:com.thoughtworks.go.util.StringUtil.java

public static String humanize(String s) {
    String[] strings = StringUtils.splitByCharacterTypeCamelCase(s);
    for (int i = 0; i < strings.length; i++) {
        String string = strings[i];
        strings[i] = string.toLowerCase();
    }//from w  w w.  j  ava2  s .  co  m
    return StringUtils.join(strings, " ");
}

From source file:kenh.expl.functions.SplitByCharacterType.java

public String[] process(String str, boolean camelCase) {
    if (camelCase)
        return StringUtils.splitByCharacterTypeCamelCase(str);
    else/*from  w  w w.j  av a  2 s  .c  o  m*/
        return StringUtils.splitByCharacterType(str);
}

From source file:com.boundary.plugin.sdk.PluginUtil.java

/**
 * Transforms a camel case string into a string with words separated by a space
 * @param s {@link String} camel case string to transform
 * @return {@link String} transformed to words and spaces
 *//*  w w  w .j a v a  2s  . c  o  m*/
public static String camelCaseToSpaceSeparated(String s) {
    return StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(s), ' ').replaceAll("\\s+", " ");
}

From source file:com.kpb.other.AcmeCorpPhysicalNamingStrategy.java

private LinkedList<String> splitAndReplace(String name) {
    LinkedList<String> result = new LinkedList<String>();
    for (String part : StringUtils.splitByCharacterTypeCamelCase(name)) {
        if (part == null || part.trim().isEmpty()) {
            // skip null and space
            continue;
        }/*w  w w. j  a  v a  2  s .c  om*/
        part = applyAbbreviationReplacement(part);
        result.add(part.toLowerCase(Locale.ROOT));
    }
    return result;
}

From source file:cn.tata.t2s.ssm.util.AcmeCorpPhysicalNamingStrategy.java

private LinkedList<String> splitAndReplace(String name) {
    LinkedList<String> result = new LinkedList<>();
    for (String part : StringUtils.splitByCharacterTypeCamelCase(name)) {
        if (part == null || part.trim().isEmpty()) {
            // skip null and space
            continue;
        }/* w  ww. j  av a 2 s  .  c  om*/
        part = applyAbbreviationReplacement(part);
        result.add(part.toLowerCase(Locale.ROOT));
    }
    return result;
}

From source file:edu.usu.sdl.openstorefront.web.action.APIAction.java

@DefaultHandler
public Resolution mainPage() {
    ResolverUtil resolverUtil = new ResolverUtil();
    resolverUtil.find(new ResolverUtil.IsA(BaseResource.class), "edu.usu.sdl.openstorefront.web.rest.resource");

    List<Class> classList = new ArrayList<>();
    classList.addAll(resolverUtil.getClasses());
    for (Class apiResourceClass : classList) {
        if (BaseResource.class.getName().equals(apiResourceClass.getName()) == false) {
            LookupModel lookupModel = new LookupModel();
            lookupModel.setCode(apiResourceClass.getSimpleName());
            lookupModel.setDescription(String
                    .join(" ", StringUtils.splitByCharacterTypeCamelCase(apiResourceClass.getSimpleName()))
                    .replace("Resource", "").replace("REST", ""));
            resourceClasses.add(lookupModel);
        }// www  . j av  a  2s. c o m
    }

    resolverUtil = new ResolverUtil();
    resolverUtil.find(new ResolverUtil.IsA(BaseResource.class), "edu.usu.sdl.openstorefront.web.rest.service");

    classList = new ArrayList<>();
    classList.addAll(resolverUtil.getClasses());
    for (Class apiResourceClass : classList) {
        LookupModel lookupModel = new LookupModel();
        lookupModel.setCode(apiResourceClass.getSimpleName());
        lookupModel.setDescription(
                String.join(" ", StringUtils.splitByCharacterTypeCamelCase(apiResourceClass.getSimpleName()))
                        .replace("Service", ""));
        serviceClasses.add(lookupModel);
    }
    resourceClasses
            .sort(new BeanComparator<>(OpenStorefrontConstant.SORT_DESCENDING, LookupModel.DESCRIPTION_FIELD));
    serviceClasses
            .sort(new BeanComparator<>(OpenStorefrontConstant.SORT_DESCENDING, LookupModel.DESCRIPTION_FIELD));

    return new ForwardResolution("/WEB-INF/securepages/api/main.jsp");
}

From source file:edu.usu.sdl.openstorefront.doc.JaxrsProcessor.java

public static APIResourceModel processRestClass(Class resource, String rootPath) {
    APIResourceModel resourceModel = new APIResourceModel();

    resourceModel.setClassName(resource.getName());
    resourceModel.setResourceName(/*from  w  w w .j a v a  2 s. c o  m*/
            String.join(" ", StringUtils.splitByCharacterTypeCamelCase(resource.getSimpleName())));

    APIDescription aPIDescription = (APIDescription) resource.getAnnotation(APIDescription.class);
    if (aPIDescription != null) {
        resourceModel.setResourceDescription(aPIDescription.value());
    }

    Path path = (Path) resource.getAnnotation(Path.class);
    if (path != null) {
        resourceModel.setResourcePath(rootPath + "/" + path.value());
    }

    RequireAdmin requireAdmin = (RequireAdmin) resource.getAnnotation(RequireAdmin.class);
    if (requireAdmin != null) {
        resourceModel.setRequireAdmin(true);
    }

    //class parameters
    mapParameters(resourceModel.getResourceParams(), resource.getDeclaredFields());

    //methods
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    int methodId = 0;
    for (Method method : resource.getDeclaredMethods()) {

        APIMethodModel methodModel = new APIMethodModel();
        methodModel.setId(methodId++);

        //rest method
        List<String> restMethods = new ArrayList<>();
        GET getMethod = (GET) method.getAnnotation(GET.class);
        POST postMethod = (POST) method.getAnnotation(POST.class);
        PUT putMethod = (PUT) method.getAnnotation(PUT.class);
        DELETE deleteMethod = (DELETE) method.getAnnotation(DELETE.class);
        if (getMethod != null) {
            restMethods.add("GET");
        }
        if (postMethod != null) {
            restMethods.add("POST");
        }
        if (putMethod != null) {
            restMethods.add("PUT");
        }
        if (deleteMethod != null) {
            restMethods.add("DELETE");
        }
        methodModel.setRestMethod(String.join(",", restMethods));

        if (restMethods.isEmpty()) {
            //skip non-rest methods
            continue;
        }

        //produces
        Produces produces = (Produces) method.getAnnotation(Produces.class);
        if (produces != null) {
            methodModel.setProducesTypes(String.join(",", produces.value()));
        }

        //consumes
        Consumes consumes = (Consumes) method.getAnnotation(Consumes.class);
        if (consumes != null) {
            methodModel.setConsumesTypes(String.join(",", consumes.value()));
        }

        aPIDescription = (APIDescription) method.getAnnotation(APIDescription.class);
        if (aPIDescription != null) {
            methodModel.setDescription(aPIDescription.value());
        }

        path = (Path) method.getAnnotation(Path.class);
        if (path != null) {
            methodModel.setMethodPath(path.value());
        }

        requireAdmin = (RequireAdmin) method.getAnnotation(RequireAdmin.class);
        if (requireAdmin != null) {
            methodModel.setRequireAdmin(true);
        }

        try {
            if (!(method.getReturnType().getSimpleName().equalsIgnoreCase(Void.class.getSimpleName()))) {
                APIValueModel valueModel = new APIValueModel();
                DataType dataType = (DataType) method.getAnnotation(DataType.class);

                boolean addResponseObject = true;
                if ("javax.ws.rs.core.Response".equals(method.getReturnType().getName()) && dataType == null) {
                    addResponseObject = false;
                }

                if (addResponseObject) {
                    valueModel.setValueObjectName(method.getReturnType().getSimpleName());
                    ReturnType returnType = (ReturnType) method.getAnnotation(ReturnType.class);
                    Class returnTypeClass;
                    if (returnType != null) {
                        returnTypeClass = returnType.value();
                    } else {
                        returnTypeClass = method.getReturnType();
                    }

                    if (!"javax.ws.rs.core.Response".equals(method.getReturnType().getName())) {
                        if (ReflectionUtil.isCollectionClass(method.getReturnType()) == false) {
                            try {
                                valueModel.setValueObject(
                                        objectMapper.writeValueAsString(returnTypeClass.newInstance()));
                                mapValueField(valueModel.getValueFields(),
                                        ReflectionUtil.getAllFields(returnTypeClass).toArray(new Field[0]));
                                mapComplexTypes(valueModel.getAllComplexTypes(),
                                        ReflectionUtil.getAllFields(returnTypeClass).toArray(new Field[0]),
                                        false);

                                aPIDescription = (APIDescription) returnTypeClass
                                        .getAnnotation(APIDescription.class);
                                if (aPIDescription != null) {
                                    valueModel.setValueDescription(aPIDescription.value());
                                }
                            } catch (InstantiationException iex) {
                                log.log(Level.WARNING, MessageFormat.format(
                                        "Unable to instantiated type: {0} make sure the type is not abstract.",
                                        returnTypeClass));
                            }
                        }
                    }

                    if (dataType != null) {
                        String typeName = dataType.value().getSimpleName();
                        if (StringUtils.isNotBlank(dataType.actualClassName())) {
                            typeName = dataType.actualClassName();
                        }
                        valueModel.setTypeObjectName(typeName);
                        try {
                            valueModel.setTypeObject(
                                    objectMapper.writeValueAsString(dataType.value().newInstance()));
                            mapValueField(valueModel.getTypeFields(),
                                    ReflectionUtil.getAllFields(dataType.value()).toArray(new Field[0]));
                            mapComplexTypes(valueModel.getAllComplexTypes(),
                                    ReflectionUtil.getAllFields(dataType.value()).toArray(new Field[0]), false);

                            aPIDescription = (APIDescription) dataType.value()
                                    .getAnnotation(APIDescription.class);
                            if (aPIDescription != null) {
                                valueModel.setTypeDescription(aPIDescription.value());
                            }

                        } catch (InstantiationException iex) {
                            log.log(Level.WARNING, MessageFormat.format(
                                    "Unable to instantiated type: {0} make sure the type is not abstract.",
                                    dataType.value()));
                        }
                    }

                    methodModel.setResponseObject(valueModel);
                }
            }
        } catch (IllegalAccessException | JsonProcessingException ex) {
            log.log(Level.WARNING, null, ex);
        }

        //method parameters
        mapMethodParameters(methodModel.getMethodParams(), method.getParameters());

        //Handle Consumed Objects
        mapConsumedObjects(methodModel, method.getParameters());

        resourceModel.getMethods().add(methodModel);
    }
    Collections.sort(resourceModel.getMethods(), new ApiMethodComparator<>());
    return resourceModel;
}