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.systematic.healthcare.fhir.generator.Generator.java
private static Class<?> getDSTU2ClassType(@Nullable ElementDefinitionDt.Type input) { try {// w w w. j ava2 s. co m try { return Class .forName(DSTU2_PRIMITIVE_PACKAGE + "." + StringUtils.capitalize(input.getCode()) + "Dt"); } catch (ClassNotFoundException ee) { return Class.forName(DSTU2_COMPOSITE_PACKAGE + "." + input.getCode() + "Dt"); } } catch (ClassNotFoundException e) { throw new IllegalStateException("Cannot locate class", e); } }
From source file:com.rockhoppertech.music.Pitch.java
public static Set<String> getSynonyms(int midiNumber) { Set<String> syn = new TreeSet<String>(); for (Map.Entry<String, Integer> entry : nameMap.entrySet()) { if (entry.getValue() == midiNumber) { // don't really feel like writing custom JUnit matchers String key = entry.getKey(); syn.add(key);//w w w. jav a2 s . c o m syn.add(key.toLowerCase(Locale.ENGLISH)); syn.add(key.toUpperCase(Locale.ENGLISH)); syn.add(StringUtils.capitalize(key.toLowerCase(Locale.ENGLISH))); } } return syn; }
From source file:de.vandermeer.skb.base.message.Message5WH_Tests.java
@Test public void testMessageEnum() { //check the number (increasing), toString (as name().tolower()) and name of the logger for each of the enumerates EMessageType[] values = EMessageType.values(); for (int i = 0; i < values.length; i++) { assertTrue(values[i].getNumber() == i); assertEquals(values[i].name().toLowerCase(), values[i].toString()); String loggerAdd = StringUtils.capitalize(values[i].name().toLowerCase()); assertEquals("SKBLogger" + loggerAdd, values[i].getLoggerName()); }/*from w ww.jav a 2 s . co m*/ }
From source file:br.com.fidias.chance4j.Chance.java
/** * Return a semi-pronounceable random (nonsense) word. * <pre>// ww w . j av a 2s.c o m * chance.word(3, true); * => "Janawuma" * chance.word(3, false); * => "elbizir" * </pre> * * @param numSyllables Number of syllables of the word * @param capitalize Capitalize or not * @return A semi-pronounceable random word */ public String word(int numSyllables, boolean capitalize) { String result = ""; for (int i = 0; i < numSyllables; i++) { result += syllable(); } return (capitalize ? StringUtils.capitalize(result) : result); }
From source file:fr.outadev.android.timeo.TimeoRequestHandler.java
/** * Capitalizes the first letter of every word, like WordUtils.capitalize(); except it does it WELL. * The determinants will not be capitalized, whereas some acronyms will. * * @param str The text to capitalize./* ww w . j a v a 2 s . c o m*/ * @return The capitalized text. */ public static String smartCapitalize(String str) { String newStr = ""; str = str.toLowerCase().trim(); //these words will never be capitalized String[] determinants = new String[] { "de", "du", "des", "au", "aux", "", "la", "le", "les", "d", "et", "l" }; //these words will always be capitalized String[] specialWords = new String[] { "sncf", "chu", "chr", "chs", "crous", "suaps", "fpa", "za", "zi", "zac", "cpam", "efs", "mjc" }; //explode the string with both spaces and apostrophes String[] words = str.split("( |\\-|'|\\/)"); for (String word : words) { if (Arrays.asList(determinants).contains(word)) { //if the word should not be capitalized, just append it to the new string newStr += word; } else if (Arrays.asList(specialWords).contains(word)) { //if the word should be in upper case, do eet newStr += word.toUpperCase(Locale.FRENCH); } else { //if it's a normal word, just capitalize it newStr += StringUtils.capitalize(word); } try { //we don't know if the next character is a blank space or an apostrophe, so we check that char delimiter = str.charAt(newStr.length()); newStr += delimiter; } catch (StringIndexOutOfBoundsException ignored) { //will be thrown for the last word of the string } } return StringUtils.capitalize(newStr); }
From source file:com.xpn.xwiki.objects.classes.PropertyClass.java
/** * Method to find the default custom displayer to use for a specific Property Class. * /*from w w w. j a v a 2s .c o m*/ * @param propertyClassName the type of the property; this is defined in each subclass, such as {@code boolean}, * {@code string} or {@code dblist} * @param context the current request context * @return An identifier for the location of a custom displayer. This can be {@code class} if there's custom display * code specified in the class itself, {@code page:currentwiki:XWiki.BooleanDisplayer} if such a document * exists in the current wiki, {@code page:xwiki:XWiki.StringDisplayer} if such a document exists in the * main wiki, or {@code template:displayer_boolean.vm} if a template on the filesystem or in the current * skin exists. */ protected String getDefaultCustomDisplayer(String propertyClassName, XWikiContext context) { LOGGER.debug("Looking up default custom displayer for property class name [{}]", propertyClassName); try { // First look into the current wiki String pageName = StringUtils.capitalize(propertyClassName) + "Displayer"; DocumentReference reference = new DocumentReference(context.getDatabase(), "XWiki", pageName); if (context.getWiki().exists(reference, context)) { LOGGER.debug("Found default custom displayer for property class name in local wiki: [{}]", pageName); return DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX + "XWiki." + pageName; } // Look in the main wiki if (context.getWiki().isVirtualMode() && !StringUtils.equals(context.getDatabase(), context.getMainXWiki())) { reference = new DocumentReference(context.getMainXWiki(), "XWiki", pageName); if (context.getWiki().exists(reference, context)) { LOGGER.debug("Found default custom displayer for property class name in main wiki: [{}]", pageName); return DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX + context.getMainXWiki() + ":XWiki." + pageName; } } // Look in templates String template = "displayer_" + propertyClassName + ".vm"; String result = ""; try { result = context.getWiki().evaluateTemplate(template, context); if (StringUtils.isNotEmpty(result)) { LOGGER.debug("Found default custom displayer for property class name as template: [{}]", template); return TEMPLATE_DISPLAYER_IDENTIFIER_PREFIX + template; } } catch (IOException e) { } } catch (Throwable e) { // If we fail we consider there is no custom displayer LOGGER.error("Error while trying to evaluate if a property has a custom displayer", e); } return null; }
From source file:edu.usu.sdl.openstorefront.service.PersistenceService.java
private <T> String generateWhereClause(T example, ComplexFieldStack complexFieldStack, GenerateStatementOption generateStatementOption) { StringBuilder where = new StringBuilder(); try {/*ww w . ja va 2 s. c om*/ Map fieldMap = BeanUtils.describe(example); boolean addAnd = false; for (Object field : fieldMap.keySet()) { if ("class".equalsIgnoreCase(field.toString()) == false) { Object value = fieldMap.get(field); if (value != null) { Method method = example.getClass() .getMethod("get" + StringUtils.capitalize(field.toString()), (Class<?>[]) null); Object returnObj = method.invoke(example, (Object[]) null); if (ReflectionUtil.isComplexClass(returnObj.getClass())) { complexFieldStack.getFieldStack().push(field.toString()); if (addAnd) { where.append(generateStatementOption.getCondition()); } else { addAnd = true; where.append(" "); } where.append( generateWhereClause(returnObj, complexFieldStack, generateStatementOption)); complexFieldStack.getFieldStack().pop(); } else { if (addAnd) { where.append(generateStatementOption.getCondition()); } else { addAnd = true; where.append(" "); } String fieldName = complexFieldStack.getQueryFieldName() + field.toString(); where.append(fieldName).append(" ").append(generateStatementOption.getOperation()) .append(" :").append(fieldName.replace(".", PARAM_NAME_SEPARATOR)) .append(generateStatementOption.getParamaterSuffix()); } } } } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } return where.toString(); }
From source file:br.com.fidias.chance4j.Chance.java
/** * Return a random sentence populated by semi-pronounceable random * (nonsense) words.//ww w.j av a2 s. co m * <pre> * chance.sentence(3); * => "Rinket evcaltip wupiir." * </pre> * * @param numWords Number of wrods of the sentence * @return A random sentence * @throws ChanceException */ public String sentence(int numWords) throws ChanceException { String[] words = words(numWords); String join = StringUtils.join(words, " "); String result = StringUtils.capitalize(join); TextOptions options = new TextOptions(); options.setPoolType(TextOptions.PoolType.custom); options.setPool(Character.PUNCTUATION); return result + character(options); }
From source file:edu.usu.sdl.openstorefront.service.OrientPersistenceService.java
private <T> String generateWhereClause(T example, ComplexFieldStack complexFieldStack, GenerateStatementOption generateStatementOption) { StringBuilder where = new StringBuilder(); try {//from ww w . j a v a 2s .c o m Map fieldMap = BeanUtils.describe(example); boolean addAnd = false; for (Object field : fieldMap.keySet()) { if ("class".equalsIgnoreCase(field.toString()) == false) { Object value = fieldMap.get(field); if (value != null) { Method method = example.getClass() .getMethod("get" + StringUtils.capitalize(field.toString()), (Class<?>[]) null); Object returnObj = method.invoke(example, (Object[]) null); if (ReflectionUtil.isComplexClass(returnObj.getClass())) { complexFieldStack.getFieldStack().push(field.toString()); if (addAnd) { where.append(generateStatementOption.getCondition()); } else { addAnd = true; where.append(" "); } where.append( generateWhereClause(returnObj, complexFieldStack, generateStatementOption)); complexFieldStack.getFieldStack().pop(); } else { if (addAnd) { where.append(generateStatementOption.getCondition()); } else { addAnd = true; where.append(" "); } String fieldName = complexFieldStack.getQueryFieldName() + field.toString() + generateStatementOption.getMethod(); String fieldParamName = complexFieldStack.getQueryFieldName() + field.toString(); where.append(fieldName).append(" ").append(generateStatementOption.getOperation()) .append(" :").append(fieldParamName.replace(".", PARAM_NAME_SEPARATOR)) .append(generateStatementOption.getParameterSuffix()); } } } } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } return where.toString(); }
From source file:android.databinding.tool.store.SetterStore.java
private static String getDefaultSetter(String attribute) { return "set" + StringUtils.capitalize(trimAttributeNamespace(attribute)); }