List of usage examples for org.apache.commons.lang StringUtils uncapitalize
public static String uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .
From source file:org.jdto.impl.BeanPropertyUtils.java
/** * Remove the accessor prefix from name and the bean capitalization. * This can be used by getters and setters. * @param method/* w w w . j a v a 2 s. c om*/ * @return */ private static String convertToPropertyName(Method method) { String methodName = method.getName(); if (StringUtils.startsWith(methodName, "set")) { methodName = StringUtils.removeStart(methodName, "set"); } else if (StringUtils.startsWith(methodName, "is")) { methodName = StringUtils.removeStart(methodName, "is"); } else if (StringUtils.startsWith(methodName, "get")) { methodName = StringUtils.removeStart(methodName, "get"); } //remove the first capital return StringUtils.uncapitalize(methodName); }
From source file:org.jdto.tools.AnnotationConfigVerifier.java
private SourceConfiguration extractSourceProperty(TypeElement element, Element getter, Messager msg) { //check for annotations. Source annot = getter.getAnnotation(Source.class); if (annot != null) { return new SourceConfiguration(annot.value(), getter); }/* w ww. j av a2 s . co m*/ //normalize the value. String name = getter.getSimpleName().toString(); name = (name.startsWith("is")) ? name.substring(2) : name.substring(3); //uncapitalize. name = StringUtils.uncapitalize(name); //config might be on the setter which is incorrect. Element setter = ModelUtils.findSetterOnType(element, name); annot = setter.getAnnotation(Source.class); if (annot != null) { msg.printMessage(Diagnostic.Kind.MANDATORY_WARNING, "@Source or @Sources annotation must not appear on setters", setter); } //at this point the annotaiton is either on the field or not present. Element field = ModelUtils.findFieldOnType(element, name); //if no field is found, that is a valid configuration. return the name of the property. if (field == null) { return new SourceConfiguration(name, getter); } //if no annotation is present on the field then also return the field name. annot = field.getAnnotation(Source.class); if (annot == null) { return new SourceConfiguration(name, field); } //if the field is annotated, issue a compiler warning for performance. msg.printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Annotations on getters perform better than annotations on fields.", field); return new SourceConfiguration(annot.value(), field); }
From source file:org.jdto.tools.ModelUtils.java
public static ExecutableElement findGetterOnType(TypeElement element, String name) { for (Element enclosedElement : element.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; }//from w ww. j a va2s .co m String elementName = enclosedElement.getSimpleName().toString(); if (elementName.startsWith("get")) { elementName = StringUtils.uncapitalize(elementName.substring(3)); if (name.equals(elementName)) { return (ExecutableElement) enclosedElement; } } if (elementName.startsWith("is")) { elementName = StringUtils.uncapitalize(elementName.substring(2)); if (name.equals(elementName)) { return (ExecutableElement) enclosedElement; } } } return null; }
From source file:org.jdto.tools.ModelUtils.java
public static ExecutableElement findSetterOnType(TypeElement element, String name) { for (Element enclosedElement : element.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; }/*from w w w.j ava 2 s. co m*/ String elementName = enclosedElement.getSimpleName().toString(); if (elementName.startsWith("set")) { elementName = StringUtils.uncapitalize(elementName.substring(3)); if (name.equals(elementName)) { return (ExecutableElement) enclosedElement; } } } return null; }
From source file:org.kuali.ext.mm.common.sys.context.SpringContext.java
/** * Use this method to retrieve a spring bean when one of the following is the case. Pass in the type of the service interface, * NOT the service implementation. 1. there is only one bean of the specified type in our spring context 2. there is only one * bean of the specified type in our spring context, but you want the one whose bean id is the same as type.getSimpleName() with * the exception of the first letter being lower case in the former and upper case in the latter, For example, there are two * beans of type DateTimeService in our context dateTimeService and testDateTimeService. To retrieve the former, you should * specific DateTimeService.class as the type. To retrieve the latter, you should specify ConfigurableDateService.class as the * type. Unless you are writing a unit test and need to down cast to an implementation, you do not need to cast the result of * this method.//from w w w .j ava 2 s . c o m * * @param <T> * @param type * @return an object that has been defined as a bean in our spring context and is of the specified type */ public static <T> T getBean(Class<T> type) { verifyProperInitialization(); T bean = null; if (SINGLETON_BEANS_BY_TYPE_CACHE.containsKey(type)) { bean = (T) SINGLETON_BEANS_BY_TYPE_CACHE.get(type); } else { if (LOG.isDebugEnabled()) { LOG.debug("Bean not already in cache: " + type + " - calling getBeansOfType() "); } Collection<T> beansOfType = getBeansOfType(type).values(); if (!beansOfType.isEmpty()) { if (beansOfType.size() > 1) { bean = getBean(type, StringUtils.uncapitalize(type.getSimpleName())); } else { bean = beansOfType.iterator().next(); } } else { // unable to find bean - check GRL // this is needed in case no beans of the given type exist locally if (LOG.isDebugEnabled()) { LOG.debug("Bean not found in local context: " + type.getName() + " - calling GRL"); } Object remoteServiceBean = getService(StringUtils.uncapitalize(type.getSimpleName())); if (remoteServiceBean != null) { if (type.isAssignableFrom(remoteServiceBean.getClass())) { bean = (T) remoteServiceBean; } } } if (bean != null) { if (SINGLETON_TYPES.contains(type) || hasSingletonSuperType(type)) { SINGLETON_TYPES.add(type); SINGLETON_BEANS_BY_TYPE_CACHE.put(type, bean); } } else { throw new RuntimeException( "Request for non-existent bean. Unable to find in local context on on the GRL: " + type.getName()); } } return bean; }
From source file:org.kuali.kfs.sys.context.SpringContext.java
/** * Use this method to retrieve a spring bean when one of the following is the case. Pass in the type of the service interface, * NOT the service implementation. 1. there is only one bean of the specified type in our spring context 2. there is only one * bean of the specified type in our spring context, but you want the one whose bean id is the same as type.getSimpleName() with * the exception of the first letter being lower case in the former and upper case in the latter, For example, there are two * beans of type DateTimeService in our context dateTimeService and testDateTimeService. To retrieve the former, you should * specific DateTimeService.class as the type. To retrieve the latter, you should specify ConfigurableDateService.class as the * type. Unless you are writing a unit test and need to down cast to an implementation, you do not need to cast the result of * this method.//from w w w. j a v a 2 s . c o m * * @param <T> * @param type * @return an object that has been defined as a bean in our spring context and is of the specified type */ public static <T> T getBean(Class<T> type) { verifyProperInitialization(); T bean = null; if (SINGLETON_BEANS_BY_TYPE_CACHE.containsKey(type)) { bean = (T) SINGLETON_BEANS_BY_TYPE_CACHE.get(type); } else { if (LOG.isDebugEnabled()) { LOG.debug("Bean not already in cache: " + type + " - calling getBeansOfType() "); } Collection<T> beansOfType = getBeansOfType(type).values(); if (!beansOfType.isEmpty()) { if (beansOfType.size() > 1) { bean = getBean(type, StringUtils.uncapitalize(type.getSimpleName())); } else { bean = beansOfType.iterator().next(); } } else { try { bean = getBean(type, StringUtils.uncapitalize(type.getSimpleName())); } catch (Exception ex) { // do nothing, let fall through } if (bean == null) { // unable to find bean - check GRL // this is needed in case no beans of the given type exist locally if (LOG.isDebugEnabled()) { LOG.debug("Bean not found in local context: " + type.getName() + " - calling GRL"); } Object remoteServiceBean = getService(StringUtils.uncapitalize(type.getSimpleName())); if (remoteServiceBean != null) { if (type.isAssignableFrom(remoteServiceBean.getClass())) { bean = (T) remoteServiceBean; } } } } if (bean != null) { synchronized (SINGLETON_TYPES) { if (SINGLETON_TYPES.contains(type) || hasSingletonSuperType(type, SINGLETON_TYPES)) { SINGLETON_TYPES.add(type); SINGLETON_BEANS_BY_TYPE_CACHE.put(type, bean); } } } else { throw new RuntimeException( "Request for non-existent bean. Unable to find in local context or on the GRL: " + type.getName()); } } return bean; }
From source file:org.kuali.rice.core.api.criteria.CriteriaSupportUtils.java
static String findDynName(String name) { String correctedName = StringUtils.uncapitalize(name).replace("Predicate", ""); //null is a keyword therefore they are called isNull & isNotNull if (correctedName.equals("null")) { correctedName = "isNull"; } else if (correctedName.equals("notNull")) { correctedName = "isNotNull"; }//from ww w. j ava2 s.c o m return correctedName; }
From source file:org.kuali.rice.core.api.util.xml.XmlHelper.java
public static org.w3c.dom.Element propertiesToXml(org.w3c.dom.Document doc, Object o, String elementName) throws Exception { Class<?> c = o.getClass(); org.w3c.dom.Element wrapper = doc.createElement(elementName); Method[] methods = c.getMethods(); for (Method method : methods) { String name = method.getName(); if ("getClass".equals(name)) { continue; }/* w w w . j av a2 s. co m*/ // The post processor could be in another server and we would be unable to retrieve it. if ("getPostProcessor".equals(name)) { continue; } if (!name.startsWith("get") || method.getParameterTypes().length > 0) { continue; } name = name.substring("get".length()); name = StringUtils.uncapitalize(name); try { Object result = method.invoke(o); final String value; if (result == null) { LOG.debug("value of " + name + " method on object " + o.getClass() + " is null"); value = ""; } else { value = result.toString(); } org.w3c.dom.Element fieldE = doc.createElement(name); fieldE.appendChild(doc.createTextNode(value)); wrapper.appendChild(fieldE); } catch (Exception e) { throw new XmlException("Error accessing method '" + method.getName() + "' of instance of " + c, e); } } return wrapper; }
From source file:org.kuali.rice.krad.data.provider.annotation.impl.AnnotationMetadataProviderImpl.java
/** * Used to find the property name from a getter method. * /*from www .j av a 2s.c o m*/ * <p>(Not using PropertyUtils since it required an instance of the class.)</p> * * @param m the method from which to get the property name. * @return the property name. */ protected String getPropertyNameFromGetterMethod(Method m) { String propertyName = ""; if (m.getName().startsWith("get")) { propertyName = StringUtils.uncapitalize(StringUtils.removeStart(m.getName(), "get")); } else { // must be "is" propertyName = StringUtils.uncapitalize(StringUtils.removeStart(m.getName(), "is")); } return propertyName; }
From source file:org.languagetool.dev.bigdata.ProhibitedCompoundRuleEvaluator.java
@SuppressWarnings("ConstantConditions") private void evaluate(List<Map.Entry<Sentence, Map.Entry<Integer, Integer>>> sentences, boolean isCorrect, String token, String homophoneToken, List<Long> evalFactors) throws IOException { println("======================"); printf("Starting evaluation on " + sentences.size() + " sentences with %s/%s (%s):\n", token, homophoneToken, String.valueOf(isCorrect)); JLanguageTool lt = new JLanguageTool(language); List<Rule> allActiveRules = lt.getAllActiveRules(); for (Rule activeRule : allActiveRules) { lt.disableRule(activeRule.getId()); }/*from www . ja v a 2 s .co m*/ for (Map.Entry<Sentence, Map.Entry<Integer, Integer>> sentenceMatch : sentences) { Sentence sentence = sentenceMatch.getKey(); String plainText = sentence.getText(); int matchStart = sentenceMatch.getValue().getKey(); int matchEnd = sentenceMatch.getValue().getValue(); String match = plainText.substring(matchStart, matchEnd); String textToken = Character.isUpperCase(match.charAt(0)) ? StringUtils.capitalize(token) : StringUtils.uncapitalize(token); String evaluated = plainText; if (!isCorrect) { evaluated = plainText.substring(0, matchStart) + textToken + plainText.substring(matchEnd); } //printf("%nCorrect: %s%nPlain text: %s%nToken: %s%nHomophone: %s%nMatch: '%s'%nReplacement: %s%n%n", String.valueOf(isCorrect), plainText, token, homophoneToken, match, replacement); AnalyzedSentence analyzedSentence = lt.getAnalyzedSentence(evaluated); for (Long factor : evalFactors) { rule.setConfusionPair(new ProhibitedCompoundRule.Pair(homophoneToken, "", token, "")); RuleMatch[] matches = rule.match(analyzedSentence); String displayStr = plainText.substring(0, matchStart) + token.toUpperCase() + plainText.substring(matchStart + (isCorrect ? token.length() : homophoneToken.length())); boolean consideredCorrect = matches.length == 0; if (consideredCorrect && isCorrect) { evalValues.get(factor).trueNegatives++; //println("true negative: " + displayStr); } else if (!consideredCorrect && isCorrect) { evalValues.get(factor).falsePositives++; //println("false positive: " + displayStr); } else if (consideredCorrect && !isCorrect) { //println("false negative: " + displayStr); evalValues.get(factor).falseNegatives++; } else { evalValues.get(factor).truePositives++; //System.out.println("true positive: " + displayStr); } } } }