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

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

Introduction

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

Prototype

public static String uncapitalize(final String str) 

Source Link

Document

Uncapitalizes a String, changing the first letter to lower case as per Character#toLowerCase(char) .

Usage

From source file:de.crowdcode.kissmda.cartridges.simplejava.InterfaceGenerator.java

/**
 * Generate the Getters and Setters methods.
 * /*ww  w  .j a v  a 2s  .c  o m*/
 * @param clazz
 *            the UML class
 * @param ast
 *            the JDT Java AST
 * @param td
 *            TypeDeclaration Java JDT
 */
public void generateGettersSetters(Classifier clazz, AST ast, TypeDeclaration td) {
    // Create getter and setter for all attributes
    // Without inheritance
    EList<Property> properties = clazz.getAttributes();
    for (Property property : properties) {
        // Create getter for each property
        // Return type?
        Type type = property.getType();
        logger.log(Level.FINE, "Class: " + clazz.getName() + " - " + "Property: " + property.getName() + " - "
                + "Property Upper: " + property.getUpper() + " - " + "Property Lower: " + property.getLower());
        String umlTypeName = type.getName();
        String umlQualifiedTypeName = type.getQualifiedName();

        // Only for parameterized type
        if (dataTypeUtils.isParameterizedType(umlTypeName)) {
            Map<String, String> types = umlHelper.checkParameterizedTypeForTemplateParameterSubstitution(type);
            umlTypeName = types.get("umlTypeName");
            umlQualifiedTypeName = types.get("umlQualifiedTypeName");
        }

        // Check the property name, no content means we have to get the
        // "type" and use it as the name
        if (property.getName().equals("")) {
            Type targetType = property.getType();
            String newPropertyName = "";
            if (property.getUpper() >= 0) {
                // Upper Cardinality 0..1
                newPropertyName = targetType.getName();
            } else {
                // Upper Cardinality 0..*
                newPropertyName = methodHelper.getPluralName(targetType.getName());
            }
            property.setName(StringUtils.uncapitalize(newPropertyName));
        }

        // Create getter for each property
        generateGetterMethod(ast, td, property, umlTypeName, umlQualifiedTypeName);

        if (!property.isReadOnly()) {
            // Create setter method for each property
            generateSetterMethod(ast, td, property, umlTypeName, umlQualifiedTypeName);
        }
    }
}

From source file:com.sunchenbin.store.feilong.core.lang.StringUtil.java

/**
 * ????.//from w ww. j av  a  2  s.  co  m
 * 
 * <p>
 * Example 1: Jinxin ---> jinxin
 * </p>
 * 
 * <pre>
 * StringUtils.capitalize(null)  = null
 * StringUtils.capitalize(&quot;&quot;)    = &quot;&quot;
 * StringUtils.capitalize(&quot;Jinxin&quot;) = &quot;jinxin&quot;
 * StringUtils.capitalize(&quot;CAt&quot;) = &quot;cAt&quot;
 * </pre>
 * 
 * 
 * <h3>?:</h3>
 * 
 * <blockquote>
 * <ol>
 * <li> {@link IntrospectorUtil#decapitalize(String)} .</li>
 * <li>?,?????, ? {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String, char...)}</li>
 * </ol>
 * </blockquote>
 * 
 * @param word
 *            ??
 * @return ????
 * @see org.apache.commons.lang3.StringUtils#uncapitalize(String)
 */
public static String firstCharToLowerCase(String word) {
    return StringUtils.uncapitalize(word);
}

From source file:com.textocat.textokit.io.brat.AutoBratUimaMappingFactory.java

private Feature searchFeatureByBratRoleName(Type uimaType, String roleName) {
    String featName = roleName;/* www . j a  va 2s.  c  o  m*/
    Feature feat = uimaType.getFeatureByBaseName(featName);
    if (feat != null) {
        return feat;
    }
    featName = toProperJavaName(featName);
    feat = uimaType.getFeatureByBaseName(featName);
    if (feat != null) {
        return feat;
    }
    if (featName.length() > 0 && Character.isUpperCase(featName.charAt(0))) {
        featName = StringUtils.uncapitalize(featName);
        feat = uimaType.getFeatureByBaseName(featName);
        if (feat != null) {
            return feat;
        }
    }
    return null;
}

From source file:com.incapture.rapgen.parser.SampleCodeParser.java

/**
 * Strip leading 'test' from any function names and apply proper capitalization
 * /*from   w w  w  .  ja  va2s  . c o m*/
 * @param functionName
 *            The function to be adjusted
 * @return functionName without leading 'test' and proper capitalization
 */
String stripTestPrefix(String functionName) {
    if (StringUtils.isBlank(functionName)) {
        return null;
    }
    if (StringUtils.startsWithIgnoreCase(functionName, "test")) {
        return StringUtils.uncapitalize(functionName.substring(4));
    }
    return functionName;
}

From source file:com.textocat.textokit.io.brat.AutoBratUimaMappingFactory.java

private Feature searchFeatureByBratName(Type uimaType, String bratName) {
    bratName = rewriteOrSelf(bratName);/*ww w  . ja v a  2s.  c om*/
    Set<String> baseNameCandidates = Sets.newLinkedHashSet();
    baseNameCandidates.add(bratName);
    baseNameCandidates.add(StringUtils.uncapitalize(toProperJavaName(bratName)));
    for (String baseName : baseNameCandidates) {
        Feature f = uimaType.getFeatureByBaseName(baseName);
        if (f != null) {
            return f;
        }
    }
    return null;
}

From source file:com.yunmel.syncretic.core.BaseService.java

/**
 * ????(??)/*from   w  w  w.  j  a v a 2s .  c  o  m*/
 * 
 * @param bean class
 * @param fields 
 * @param values 
 * @return -1?
 */
public <M extends BaseEntity> int beforeDelete(Class<M> bean, Map<String, Object> params) {
    String mapperName = StringUtils.uncapitalize(bean.getSimpleName()) + "Mapper";
    Mapper<M> mapper = SpringUtils.getBean(mapperName);
    M m = null;
    try {
        m = bean.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    m.setAll(params);
    int count = mapper.selectCount(m);
    return count > 0 ? -1 : count;
}

From source file:com.wesleyhome.dao.processor.method.IncludeQueryMethodGenerator.java

/**
 * @param method/*from w  w w  .  j av  a  2s  .c o m*/
 * @param param
 * @param model
 * @param entityJClass
 * @param fieldElement
 * @param fieldType
 * @param entityManagerField
 * @param mappingType
 */
private void createCollectionParameterMethodBody(final JMethod method, final JVar param, final JCodeModel model,
        final JClass entityJClass, final Element fieldElement, final JClass fieldType,
        final JFieldVar entityManagerField, final MappingType mappingType) {
    method.annotate(Override.class);
    JBlock body = method.body();
    JClass valueClass;
    switch (mappingType) {
    case MANY_TO_ONE:
    case OBJECT:
    default:
        valueClass = model.ref(List.class).narrow(entityJClass);
        break;
    case ONE_TO_ONE:
    case UNIQUE_OBJECT:
        valueClass = entityJClass;
    }
    JClass map = model.ref(Map.class).narrow(fieldType, valueClass);
    JVar mapDeclaration = body.decl(map, "map",
            JExpr._new(model.ref(TreeMap.class).narrow(fieldType, valueClass)));
    JConditional emptyIfBlock = body._if(JOp.eq(param, JExpr._null()).cor(param.invoke("isEmpty")));
    emptyIfBlock._then()._return(mapDeclaration);
    JClass cbClass = model.ref(CriteriaBuilder.class);
    if (entityManagerField == null) {
        throw new IllegalStateException("What happened to the entity manager field?!?!?!");
    }
    JInvocation invoke = JExpr._this().invoke("getCriteriaBuilder");
    JVar criteriaBuilderVar = body.decl(cbClass, "cb", invoke);
    JInvocation tupleQueryInvoke = criteriaBuilderVar.invoke("createTupleQuery");
    JClass criteriaQueryRef = model.ref(CriteriaQuery.class);
    JClass cqNarrow = criteriaQueryRef.narrow(Tuple.class);
    JVar cqVar = body.decl(cqNarrow, "cq", tupleQueryInvoke);
    JClass rootRef = model.ref(Root.class);
    JClass rootNarrow = rootRef.narrow(entityJClass);
    JInvocation fromInvoke = cqVar.invoke("from");
    fromInvoke.arg(entityJClass.staticRef("class"));
    JVar rootVar = body.decl(rootNarrow, "root", fromInvoke);
    String entityClassName = entityJClass.fullName();
    String entityMetamodelClassName = entityClassName + "_";
    JClass metamodelClass = model.ref(entityMetamodelClassName);
    String fieldName = fieldElement.getSimpleName().toString();
    JFieldRef fieldMetamodelRef = metamodelClass.staticRef(fieldName);
    JClass pathClass = model.ref(Path.class);
    JClass fieldTypeRef = model.ref(fieldElement.asType().toString());
    JClass pathNarrow = pathClass.narrow(fieldTypeRef);
    JInvocation getInvoke = rootVar.invoke("get");
    getInvoke.arg(fieldMetamodelRef);
    JVar pathVar = body.decl(pathNarrow, fieldName + "Path", getInvoke);
    body.add(cqVar.invoke("multiselect").arg(pathVar).arg(rootVar));
    body.add(cqVar.invoke("where").arg(pathVar.invoke("in").arg(param)));
    JClass listTupleClass = model.ref(List.class).narrow(Tuple.class);
    JVar resultList = body.decl(listTupleClass, "resultList", JExpr._this().invoke("getResultList").arg(cqVar));
    JType tupleType = model.ref(Tuple.class);
    JForEach forEach = body.forEach(tupleType, "tuple", resultList);
    JBlock forEachBody = forEach.body();
    JVar var = forEach.var();
    JInvocation argInvocation = var.invoke("get").arg(pathVar);
    if (String.class.getName().equals(fieldType.binaryName())) {
        argInvocation = argInvocation.invoke("trim");
    } else {
        body.directStatement("// " + fieldType.binaryName());
    }
    JVar keyVar = forEachBody.decl(fieldType, fieldName, argInvocation);
    String varName = "value";
    switch (mappingType) {
    case MANY_TO_ONE:
    case OBJECT:
        varName = "list";
        break;
    case ONE_TO_ONE:
    case UNIQUE_OBJECT:
    default:
    }
    JVar valueVar = forEachBody.decl(entityJClass, StringUtils.uncapitalize(entityJClass.name()),
            var.invoke("get").arg(rootVar));
    switch (mappingType) {
    case MANY_TO_ONE:
    case OBJECT:
    default:
        JVar listVar = forEachBody.decl(valueClass, varName, mapDeclaration.invoke("get").arg(keyVar));
        JConditional ifCondition = forEachBody._if(JExpr._null().eq(listVar));
        JBlock ifBody = ifCondition._then();
        ifBody.assign(listVar, JExpr._new(model.ref(ArrayList.class).narrow(entityJClass)));
        ifBody.add(mapDeclaration.invoke("put").arg(keyVar).arg(listVar));
        forEachBody.invoke(listVar, "add").arg(valueVar);
        break;
    case ONE_TO_ONE:
    case UNIQUE_OBJECT:
        forEachBody.add(mapDeclaration.invoke("put").arg(keyVar).arg(valueVar));
        break;
    }
    body._return(mapDeclaration);
}

From source file:com.minlia.cloud.framework.common.persistence.service.AbstractRawService.java

private Object getRepository() {
    org.springframework.context.ApplicationContext applicationContext = ApplicationContextHolder
            .getApplicationContext();/*from w w  w  .  ja  v a  2 s .  c  o  m*/
    Object object = applicationContext
            .getBean(StringUtils.uncapitalize(this.clazz.getSimpleName()) + "Repository");
    return object;
}

From source file:com.yunmel.syncretic.core.BaseService.java

public <M extends BaseEntity> boolean unique(Class<M> bean, String checkField, Object value, Object id,
        Map<String, Object> params) {
    String mapperName = StringUtils.uncapitalize(bean.getSimpleName()) + "Mapper";
    Mapper<M> mapper = SpringUtils.getBean(mapperName);
    M m = null;//w w w.j av a2  s.co  m
    try {
        m = bean.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    if (id != null) {
        m.set("id", id);
    }
    m.set(checkField, value);
    if (params != null) {
        m.setAll(params);
    }
    // int count = mapper.selectCount(m);
    if (id != null) {
        List<M> lists = mapper.select(m);
        if (lists.size() >= 2) {
            return false;
        } else if ((lists.size() == 1)) {
            return lists.get(0).get("id").toString().equals(id + "");
        } else {
            return true;
        }
    } else {
        int count = mapper.selectCount(m);
        return count <= 0 ? true : false;
    }
}

From source file:com.hesine.manager.generate.Generate.java

public static void execute(File curProjectPath, String packageName, String moduleName,
        Map<String, String> table, List<Map<String, String>> fileds) {
    // ==========  ?? ====================

    // ??????/*www . j  a  v a 2s  . c o  m*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    //        String packageName = "com.hesine.manager";

    //      String moduleName = "function";         // ???sys
    //        String moduleName = "";         // ???sys
    //        String tableName = "tb_product";         // ???sys
    //        String subModuleName = "";            // ?????
    //        String className = "product";         // ??product
    //        String classAuthor = "Jason";      // ThinkGem
    //        String functionName = "?";         // ??
    String tableName = table.get("tableName"); // ???sys
    String subModuleName = ""; // ?????
    String className = table.get("className"); // ??product
    String classAuthor = "Jason"; // ThinkGem
    String functionName = table.get("comment"); // ??

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    //        StringUtils.isBlank(moduleName) ||
    if (StringUtils.isBlank(packageName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = curProjectPath;
    //        while(!new File(projectPath.getPath()+separator+"src"+separator+"main").exists()){
    //            projectPath = projectPath.getParentFile();
    //        }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tmpProjectPath = "/Users/zhanghongbing/Workspaces/Projects/hesine-projects/github-framework/hesine-demo/hesine-portal";
    String tplPath = StringUtils.replace(tmpProjectPath + "/src/main/java/com/hesine/manager/generate/template",
            "/", separator);
    //        String tplPath = StringUtils.replace(projectPath+"/src/main/java/com/hesine/manager/generate/template", "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // Xml
    String xmlPath = StringUtils.replace(projectPath + "/src/main/resources/mybatis", "/", separator);
    logger.info("Xml Path: {}", xmlPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Map<String, Object> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    //      model.put("tableName", model.get("moduleName")+(StringUtils.isNotBlank(subModuleName)
    //            ?"_"+StringUtils.lowerCase(subModuleName):"")+"_"+model.get("className"));
    model.put("tableName", tableName);

    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));
    model.put("fileds", fileds);

    // ? Entity
    FileGenUtils.generateEntity(tplPath, javaPath, model);

    // ? sqlMap
    FileGenUtils.generateSqlMap(tplPath, xmlPath, model);

    // ? Model
    FileGenUtils.generateModel(tplPath, javaPath, model);

    // ? Dao
    FileGenUtils.generateDao(tplPath, javaPath, model);

    // ? Service
    FileGenUtils.generateService(tplPath, javaPath, model);

    // ? ServiceImpl
    FileGenUtils.generateServiceImpl(tplPath, javaPath, model);

    // ? Controller
    FileGenUtils.generateController(tplPath, javaPath, model);
    //
    //        // ? add.ftl
    //        FileGenUtils.generateAddFtl(tplPath, viewPath, model);
    //
    //        // ? edit.ftl
    //        FileGenUtils.generateEditFtl(tplPath, viewPath, model);

    //        // ? list.ftl
    //        FileGenUtils.generateListFtl(tplPath, viewPath, model);

    logger.info("Generate Success.");
}