List of usage examples for org.apache.commons.lang WordUtils uncapitalize
public static String uncapitalize(String str)
Uncapitalizes all the whitespace separated words in a String.
From source file:gov.redhawk.ide.internal.ui.templates.ResourceControlPanelTemplateSection.java
/** * @param s//from w ww.j a v a 2s .co m * @return */ private String getField(Simple s, boolean prepend) { String field; if (s.getName() != null) { field = s.getName() + "_Text"; field = field.replaceAll("[^a-zA-Z0-9]", "_"); field = field.replaceAll("_*_", "_"); } else { field = s.getId(); field = field.replaceAll("[^a-zA-Z0-9]", "_"); field = field.replaceAll("_*_", "_"); } field = WordUtils.uncapitalize(field.replace(" ", "")); if (prepend) { return "fields." + field; } else { return field; } }
From source file:de.hybris.platform.webservices.util.objectgraphtransformer.impl.AbstractNodeConfig.java
protected String normalizePropertyName(final String propertyName) { return WordUtils.uncapitalize(propertyName); }
From source file:it.alidays.mapengine.codegenerator.MapperEngineCodeGenerator.java
private static void createMapClass(Retrieve retrieve, Map<String, Integer> columns, String packageName, File destinationDir)//from ww w . j a v a 2 s.c o m throws JClassAlreadyExistsException, MapperEngineCodeGeneratorException, IOException { JCodeModel codeModel = new JCodeModel(); JDefinedClass mapClass = codeModel._class(String.format("%s.%sMap", packageName, retrieve.getId())); mapClass.javadoc().append("Auto generated class. Do not modify!"); // Constructor JMethod constructor = mapClass.constructor(JMod.PROTECTED); constructor.param(codeModel.ref(Map.class).narrow(String.class, Object.class), "data"); for (String column : columns.keySet()) { String varName = WordUtils.uncapitalize(column); Class<?> type = null; switch (columns.get(column)) { case Types.INTEGER: type = Integer.class; break; case Types.VARCHAR: type = String.class; break; case Types.DECIMAL: type = BigDecimal.class; break; default: throw new MapperEngineCodeGeneratorException( String.format("Missing Type map for column %s: %d", column, columns.get(column))); } JFieldVar field = mapClass.field(JMod.PRIVATE | JMod.FINAL, type, varName); // Getter JMethod getter = mapClass.method(JMod.PUBLIC, type, String.format("get%s", column)); getter.body()._return(JExpr._this().ref(field)); constructor.body().assign(JExpr._this().ref(varName), JExpr.cast(codeModel.ref(type), JExpr.ref("data").invoke("get").arg(column))); } codeModel.build(destinationDir); }
From source file:es.osoco.grails.plugins.otp.access.AnnotationMultipleVoterFilterInvocationDefinition.java
private void findControllerAnnotations(final GrailsControllerClass controllerClass, final Map<String, Map<String, Set<String>>> actionRoleMap, final Map<String, Set<String>> classRoleMap) { Class<?> clazz = controllerClass.getClazz(); String controllerName = WordUtils.uncapitalize(controllerClass.getName()); Annotation annotation = findAnnotation(clazz.getAnnotations()); if (annotation != null) { classRoleMap.put(controllerName, asSet(getValue(annotation))); }//from w w w. ja va 2 s. co m Map<String, Set<String>> annotatedClosureNames = findActionRoles(clazz); if (annotatedClosureNames != null) { actionRoleMap.put(controllerName, annotatedClosureNames); } }
From source file:au.com.dw.testdatacapturej.reflection.util.ReflectionUtil.java
/** * Generate a field name fragment for the class of an object by extracting the non-qualified * class name of the object./*from w w w .ja v a2 s .com*/ * * If the object's class is: * com.test.TestClass * Then the field name fragment would be: * testClass * * This fragment is meant to be used as the basis for building the full field name. * * @param object * @return */ public static String getObjectFieldName(Object object) { String className = object.getClass().getName(); String fieldName = WordUtils.uncapitalize(className.substring(className.lastIndexOf(".") + 1)); return fieldName; }
From source file:au.com.dw.testdatacapturej.reflection.util.ReflectionUtil.java
/** * Generate a field name fragment for the class of an object by extracting the non-qualified * class name./*from www.j av a 2 s.c o m*/ * * If the class is: * com.test.TestClass * Then the field name fragment would be: * testClass * * This fragment is meant to be used as the basis for building the full field name. * * @param clazz * @return */ public static String getObjectFieldName(Class<?> clazz) { String className = clazz.getName(); String fieldName = WordUtils.uncapitalize(className.substring(className.lastIndexOf(".") + 1)); return fieldName; }
From source file:com.google.flatbuffers.Table.java
@SuppressWarnings("unchecked") @Override// w w w. j a va 2 s.c om public int clone(FlatBufferBuilder builder, Map<String, Object> mutate) throws Exception { int root_table = -1; Class<?> cls = this.getClass(); HashMap<String, Object> v = new HashMap<String, Object>(); try { //b0. phan loai method List<Method> msAdd = new ArrayList<Method>(); List<Method> msGet = new ArrayList<Method>(); HashMap<String, Method> msCreateVector = new HashMap<String, Method>(); Method[] ms = this.getClass().getDeclaredMethods(); for (Method m : ms) { String sMethodName = m.getName(); if (m.getParameterTypes().length == 0 && !sMethodName.endsWith("AsByteBuffer")) msGet.add(m); else if (m.getParameterTypes().length == 2 && sMethodName.startsWith("add")) msAdd.add(m); else if (m.getParameterTypes().length == 2 && sMethodName.startsWith("create") && sMethodName.endsWith("Vector")) msCreateVector.put(sMethodName, m); } //b1. lay ds thuoc tinh va gia tri for (Method m : msGet) { String sMethodName = m.getName(); if (sMethodName.endsWith("Length")) { int ii = sMethodName.lastIndexOf("Length"); String sMethodName1 = sMethodName.substring(0, ii); int iLength = 0; try { iLength = (int) m.invoke(this, new Object[] {}); } catch (Exception e) { } List<Object> l = new ArrayList<>(); for (int i = 0; i < iLength; i++) { Method m1 = this.getClass().getDeclaredMethod(sMethodName1, new Class<?>[] { Integer.TYPE }); Object oKq = m1.invoke(this, new Object[] { i }); l.add(oKq); } v.put(sMethodName1, l); } else { Object oKq = m.invoke(this, new Object[] {}); v.put(sMethodName, oKq); } } //b2. khoi tao gia tri cho builder for (Entry<String, Object> e : v.entrySet()) { String sKey = e.getKey(); Object oValue = e.getValue(); Object oNewValue = mutate != null ? mutate.get(sKey) : null; if (oValue instanceof String || oNewValue instanceof String) { int keyOffset = builder .createString(oNewValue == null ? oValue.toString() : oNewValue.toString()); v.put(sKey, keyOffset); } else if (oValue instanceof List || oNewValue instanceof List) { List<?> oV = (List<?>) (oNewValue == null ? oValue : oNewValue); int iLen = ((List<?>) oV).size(); if (iLen <= 0) v.put(sKey, null); else { Object obj = ((List<?>) oV).get(0); if (obj instanceof Table || obj instanceof Struct) { int[] keyOffsetList = new int[iLen]; boolean isHasValue = false; for (int i = 0; i < iLen; i++) { obj = ((List<?>) oV).get(i); int offset = ((IFlatBuffer) obj).clone(builder, null); if (offset != -1) { keyOffsetList[i] = offset; isHasValue = true; } } if (isHasValue) { int keyOffset = -1; Method m = cls.getDeclaredMethod("create" + WordUtils.capitalize(sKey) + "Vector", new Class<?>[] { FlatBufferBuilder.class, int[].class }); keyOffset = (int) m.invoke(null, new Object[] { builder, keyOffsetList }); if (keyOffset != -1) v.put(sKey, keyOffset); } } else if (obj instanceof String) { int[] keyOffsetList = new int[iLen]; boolean isHasValue = false; for (int i = 0; i < iLen; i++) { obj = ((List<String>) oV).get(i); int offset = builder.createString((CharSequence) obj); if (offset != -1) { keyOffsetList[i] = offset; isHasValue = true; } } if (isHasValue) { int keyOffset = -1; Method m = cls.getDeclaredMethod("create" + WordUtils.capitalize(sKey) + "Vector", new Class<?>[] { FlatBufferBuilder.class, int[].class }); keyOffset = (int) m.invoke(null, new Object[] { builder, keyOffsetList }); if (keyOffset != -1) v.put(sKey, keyOffset); } } else { int keyOffset = -1; Method m = msCreateVector.get("create" + WordUtils.capitalize(sKey) + "Vector"); Class<?> subCls = Class.forName(m.getParameterTypes()[1].getName()); Class<?> objType = subCls.getComponentType(); String objTypeName = objType.getSimpleName(); Method mo = Number.class.getDeclaredMethod(objTypeName + "Value", new Class<?>[] {}); Object aObject = Array.newInstance(objType, iLen); for (int i = 0; i < iLen; i++) Array.set(aObject, i, mo.invoke(((List<Number>) oV).get(i), new Object[] {})); keyOffset = (int) m.invoke(null, new Object[] { builder, aObject }); if (keyOffset != -1) v.put(sKey, keyOffset); } } } else if (oValue instanceof Table || oValue instanceof Struct || oNewValue instanceof Table || oNewValue instanceof Struct) { int keyOffset = -1; if (oNewValue != null) keyOffset = ((IFlatBuffer) oNewValue).clone(builder, mutate); else keyOffset = ((IFlatBuffer) oValue).clone(builder, mutate); if (keyOffset != -1) v.put(sKey, keyOffset); } else { if (oNewValue != null) v.put(sKey, oNewValue); } } //b3. gan gia tri cho clone object Method m = cls.getDeclaredMethod("start" + cls.getSimpleName(), new Class<?>[] { FlatBufferBuilder.class }); m.invoke(null, new Object[] { builder }); for (Method mAdd : msAdd) { String sFieldName = mAdd.getName().replace("add", ""); sFieldName = WordUtils.uncapitalize(sFieldName); Object oFieldValue = v.get(sFieldName); if (oFieldValue != null && !(oFieldValue instanceof Table || oFieldValue instanceof Struct)) { mAdd.invoke(null, new Object[] { builder, oFieldValue }); } } m = cls.getDeclaredMethod("end" + cls.getSimpleName(), new Class<?>[] { FlatBufferBuilder.class }); root_table = (int) m.invoke(null, new Object[] { builder }); } catch (Exception e) { e.printStackTrace(); throw e; } return root_table; }
From source file:ac.elements.parser.ExtendedFunctions.java
/** * Uncapitalize.//from w w w .j a v a2 s. c om * * @param str * the str * * @return the string */ public static String uncapitalize(String str) { return WordUtils.uncapitalize(str); }
From source file:org.apache.any23.util.StringUtils.java
/** * Changes string with following convention: * <ul>/*from w ww. ja v a 2 s . co m*/ * <li>Changes '-' -> '_' * <li>remove space characters and make first letter word uppercase: 'some * string' -> 'someString' * </ul> * If input string does not contains a whitespace than return unchanged. * * @param in an input string to convert to Java code convention * @return the correctly formatter string as per Java spec. */ public static String implementJavaNaming(String in) { in = in.trim().replaceAll("-", "_"); // If no white chars found inside a string return uncapitalized if (in.trim().matches("\\S+")) { return WordUtils.uncapitalize(in); } in = in.toLowerCase(); if (Pattern.matches("\\S+(\\s+\\S+)+", in)) { String[] words = in.split("\\s", 2); in = words[0] + WordUtils.capitalize(words[1]).replaceAll("\\s", ""); } return in; }
From source file:org.apache.openjpa.enhance.stats.FetchStatisticsAuxEnhancer.java
private FieldMetaData getFieldName(String methName, ClassMetaData cmd) { FieldMetaData res = null;//from ww w. j a va2 s . c o m String fieldName = null; if (methName.matches(IGNORE_METHODS_REGEX)) { return res; } else if (methName.startsWith("pcGet")) { // field access fieldName = methName.substring(5); } else if (methName.toLowerCase(Locale.ENGLISH).startsWith("get")) { // property access fieldName = WordUtils.uncapitalize(methName.substring(3)); } else if (methName.startsWith("pcis")) { fieldName = methName.substring(4).toLowerCase(Locale.ENGLISH); } for (FieldMetaData fmd : cmd.getDeclaredFields()) { String fmdName = fmd.getName(); if (fmdName.equals(fieldName)) { return fmd; } } return null; }