List of usage examples for org.apache.commons.lang3 StringUtils capitalize
public static String capitalize(final String str)
Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .
From source file:com.google.testing.pogen.generator.test.java.TestCodeGenerator.java
/** * Appends a getter method for the variable specified by the name or the result of invoking the * method described by the given prefix on the variable into the given string builder. * //from ww w. j av a 2 s .co m * @param builder {@link StringBuilder} the generated test code will be appended to * @param variableName the variable name * @param elementSuffixForInvoking the suffix of the {@code WebElement} variable that specifies a * method name with a dot to invoke it, e.g. {@literal".getText()"}, or an empty string to * access the variable directly. * @param returnType the return type of the generated getter method * @param methodNamePrefix the name prefix of the generated method */ private void appendGetter(StringBuilder builder, String variableName, String elementSuffixForInvoking, String returnType, String methodNamePrefix) { appendLine(builder); // TODO(kazuu): Help to select proper one from getFoo, getFoo2, getFoo3 ... appendLine(builder, 1, String.format("public %s get%s%s() {", returnType, methodNamePrefix, StringUtils.capitalize(variableName))); appendLine(builder, 2, String.format("return %s%s;", variableName, elementSuffixForInvoking)); appendLine(builder, 1, "}"); }
From source file:com.aol.one.patch.DefaultPatcher.java
private void invokeRemoveMethod(Object object, String fieldName) throws IllegalAccessException, InvocationTargetException, PatchException { if (object instanceof Patchable) { Patchable patchable = (Patchable) object; patchable.removeValue(fieldName); return;// w w w .j av a2s . c om } boolean isFieldNameNumeric = StringUtils.isNumeric(fieldName); if (isFieldNameNumeric && object instanceof java.util.List) { List tmpList = (List) object; tmpList.remove(Integer.parseInt(fieldName)); return; } if (isFieldNameNumeric && object instanceof java.util.Map) { Map tmpMap = (Map) object; tmpMap.remove(fieldName); return; } // first try to find remove+CapitalizedField List<String> methodNames = new ArrayList<>(); methodNames.add("remove" + StringUtils.capitalize(fieldName)); List<MethodData> methodDataList = generateMethodData(methodNames); // final try, standard method List<Class<?>> argTypes = new ArrayList<>(); argTypes.add(String.class); List<Object> params = new ArrayList<>(); params.add(fieldName); MethodData standardMethodData = new MethodData(STANDARD_REMOVE_METHOD, argTypes, params); methodDataList.add(standardMethodData); invokeMethodFromMethodDataList(object, methodDataList); }
From source file:de.adorsys.forge.gwt.GWTPlugin.java
private void addEventMethod(final PipeOut out, JavaSourceFacet javafacet, Method<JavaInterface> eventMethod, String literalValue) throws FileNotFoundException { String[] presenter = literalValue.replace("{", "").replace("}", "").replaceAll(".class", "").split(","); List<Annotation<JavaInterface>> annotations = eventMethod.getAnnotations(); for (Annotation<JavaInterface> a : annotations) { eventMethod.removeAnnotation(a); }/*from ww w .j av a 2s .co m*/ String eventName = "on" + StringUtils.capitalize(eventMethod.getName()); eventMethod.setName(eventName); eventMethod.setPublic(); String method = eventMethod.toString().replace(';', ' '); String signature = eventMethod.toSignature().replaceFirst(eventMethod.getName(), eventName); for (String presenterName : presenter) { List<Import> imports = eventMethod.getOrigin().getImports(); for (Import imp : imports) { if (imp.getSimpleName().equals(presenterName)) { presenterName = imp.getQualifiedName(); break; } } JavaResource presenterResource = javafacet.getJavaResource(presenterName); if (!presenterResource.exists()) { ShellMessages.error(out, String.format("Presenter not found: %s ", presenterName)); continue; } JavaClass presenterSource = (JavaClass) presenterResource.getJavaSource(); if (!presenterSource.hasMethodSignature(eventMethod)) { presenterSource.addMethod(method + "{\n}"); List<Parameter> parameters = eventMethod.getParameters(); for (Parameter parameter : parameters) { presenterSource.addImport(parameter.getTypeInspector().getQualifiedName()); } ShellMessages.info(out, String.format(" - %s : created event method %s", presenterSource.getName(), signature)); javafacet.saveJavaSource(presenterSource); } } }
From source file:com.marand.thinkmed.medications.dto.report.TherapyDayReportUtils.java
public static String getTherapyApplicationComment(@Nonnull final TherapyDto order, final TherapyPharmacistReviewStatusEnum pharmacistsReviewState, final int line, @Nonnull final Locale locale) { if (line == 0) { final StringBuilder comment = new StringBuilder(); if (order.getComment() != null) { String commentString = StringUtils.capitalize(getDictionaryEntry("comment", locale)); comment.append(commentString).append(": <B>").append(order.getComment()).append("</B> "); }/* w w w . j a v a 2s . c o m*/ if (order.getClinicalIndication() != null) { String indicationString = StringUtils.capitalize(getDictionaryEntry("indication", locale)); comment.append(indicationString).append(": <B>").append(order.getClinicalIndication().getName()) .append("</B> "); } if (order.getClinicalIndication() != null) { String pharmacistReview = null; if (pharmacistsReviewState == TherapyPharmacistReviewStatusEnum.REVIEWED) { pharmacistReview = StringUtils.capitalize(getDictionaryEntry("verified", locale)); } else if (pharmacistsReviewState == TherapyPharmacistReviewStatusEnum.NOT_REVIEWED) { pharmacistReview = StringUtils.capitalize(getDictionaryEntry("unverified", locale)); } else if (pharmacistsReviewState == TherapyPharmacistReviewStatusEnum.REVIEWED_REFERRED_BACK) { final String referredBackString = getDictionaryEntry("referred.back", locale); pharmacistReview = StringUtils.capitalize(getDictionaryEntry("verified", locale)) + " - " + referredBackString; } if (pharmacistReview != null) { final String pharmacyVerificationString = StringUtils .capitalize(getDictionaryEntry("pharmacy.verification", locale)); comment.append(pharmacyVerificationString).append(": <B>").append(pharmacistReview) .append("</B>"); } } return comment.toString(); } else if (line == 1) { final StringBuilder warning = new StringBuilder(); if (order.getCriticalWarnings() != null) { for (final String criticalWarning : order.getCriticalWarnings()) { final String warningOverriddenString = StringUtils .capitalize(getDictionaryEntry("warning.overridden", locale)); warning.append(warningOverriddenString).append(": <B>").append(criticalWarning).append("</B>"); if (order.getCriticalWarnings().size() > 1) { warning.append("<br>"); } } } return warning.toString(); } else { return exceptionToString(new UnsupportedOperationException()); } }
From source file:de.hasait.clap.CLAP.java
private <R> void addPrimitiveConverter(final Class<?> pWrapperClass, final Class<R> pPrimitiveClass) throws Exception { final Method parseMethod = pWrapperClass .getMethod("parse" + StringUtils.capitalize(pPrimitiveClass.getSimpleName()), String.class); //$NON-NLS-1$ final CLAPConverter<R> methodConverter = new CLAPConverter<R>() { @Override//from www.j a v a 2 s. co m public R convert(final String pInput) { try { return (R) parseMethod.invoke(null, pInput); } catch (final Exception e) { throw runtimeException(e); } } }; addConverter(pPrimitiveClass, methodConverter); }
From source file:com.aol.one.patch.DefaultPatcher.java
private Object invokeAccessorMethod(Object object, String fieldName) throws PatchException, IllegalAccessException, InvocationTargetException { Class<?> clazz = object.getClass(); boolean isFieldNameNumeric = StringUtils.isNumeric(fieldName); if (isFieldNameNumeric && object instanceof java.util.List) { List tmpList = (List) object; return tmpList.get(Integer.parseInt(fieldName)); }// w w w.j a va 2 s.c om if (isFieldNameNumeric && object instanceof java.util.Map) { Map tmpMap = (Map) object; return tmpMap.get(fieldName); } // try to find get+CapitalizedField // TODO: improve this to convert from snake_case to CamelCase List<String> methodNames = new ArrayList<>(); methodNames.add("get" + StringUtils.capitalize(fieldName)); methodNames.add(STANDARD_PATCH_OBJ_GETTER); List<MethodData> methodDataList = generateMethodData(methodNames); Set<String> triedMethodNames = new LinkedHashSet<>(); for (MethodData methodData : methodDataList) { Method method; if (methodData.hasParameters()) { method = MethodUtils.getAccessibleMethod(clazz, methodData.methodName, methodData.getParameterTypes().toArray(new Class<?>[0])); if (method != null && methodData.hasArguments()) { return method.invoke(object, methodData.arguments.toArray()); } } else { method = MethodUtils.getAccessibleMethod(clazz, methodData.methodName); if (method != null) { return method.invoke(object); } } triedMethodNames.add(methodData.methodName); } String exMsg = getExMsgForMethodsNotFound(clazz, triedMethodNames.toArray(new String[triedMethodNames.size()])); throw new PatchException(ErrorCodes.ERR_METHOD_TO_PATCH_NOT_FOUND, exMsg); }
From source file:info.magnolia.integrationtests.uitest.SecurityAppUITest.java
/** * Adds an user./*from w w w . j a va 2s.c om*/ */ private void addUser(String username, String password) { getActionBarItem(getAddItemActionName(USER)).click(); waitUntil(dialogIsOpen(StringUtils.capitalize(USER))); sendKeysToDialogField(getItemNameFieldLabel(USER), username); sendKeysToDialogField(getPassword(), password); sendKeysToDialogField(getPasswordConfirmation(), password); getDialogCommitButton().click(); waitUntil(dialogIsClosed(StringUtils.capitalize(USER))); }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static String toCamelCase(final CharSequence sequence, final boolean removeAccents, final boolean capitalizeFirst) { if (sequence == null) { return null; }/*from w w w . j a va 2 s .co m*/ final CharSequence seq = removeAccents ? removeAccents(sequence) : sequence; final Collection<String> tokens = split(seq, CAMELCASE_REGEX, true); final StringBuilder builder = new StringBuilder(length(seq)); int i = 0; for (final String token : tokens) { final String curr = (i > 0 || capitalizeFirst) ? StringUtils.capitalize(token) : token; builder.append(curr); i++; } return builder.toString(); }
From source file:com.systematic.healthcare.fhir.generator.Generator.java
private void addExtensionField(JavaClassSource javaClass, ElementDefinitionDt element, StructureDefinitionProvider resolver) throws Exception { if (element.getType().size() > 1) { throw new IllegalStateException("WTF"); } else {//from w w w . j a v a 2s . c om if (element.getName() == null) { return; } FieldSource<JavaClassSource> field = javaClass.addField() .setName("my" + StringUtils.capitalize(element.getName())).setPrivate(); extensionFieldsAdded.add(field); Class<?> extensionType = getExtensionType(element, resolver); if (extensionType != null) { field.setType(extensionType); } else { field.setType(Roaster.parse("public class " + StringUtils.capitalize(element.getName()) + " {}")); String errMsg = "Replace " + StringUtils.capitalize(element.getName()) + ".class with correct extension name"; addTodoAndDeprecationAnnotation(field, errMsg); } addFieldExtensionAnnotation(element, field); addFieldChildAnnotation(element, element.getName(), field, true); addFieldDescriptionAnnotation(element, field); } }
From source file:fr.evercraft.essentials.command.EEWhois.java
private Text getLocale(final EPlayer player) { return EEMessages.WHOIS_LANGUAGE.getFormat().toText("<langue>", StringUtils.capitalize(player.getLocale().getDisplayLanguage())); }