List of usage examples for java.lang Character isLowerCase
public static boolean isLowerCase(int codePoint)
From source file:hsa.awp.common.util.StaticInitializerBeanFactoryPostProcessor.java
/** * Returns the standard setter name for the given field name. * * @param fieldName the name of the field * @return the name of the setter// w w w. j a va 2 s . com */ private String setterName(String fieldName) { String nameToUse = null; if (fieldName.length() == 1) { if (Character.isLowerCase(fieldName.charAt(0))) { nameToUse = fieldName.toUpperCase(); } else { nameToUse = fieldName; } } else { if (Character.isLowerCase(fieldName.charAt(0)) && Character.isLowerCase(fieldName.charAt(1))) { nameToUse = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); } else { nameToUse = fieldName; } } return "set" + nameToUse; }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * * @param input//from www . jav a2s.c om * @return * @example * * BankAccount => Bank Account Bank_Account => Bank_Account */ public static String toNatural(String input) { String natural = EMPTY; Character lastChar = null; for (Character curChar : input.toCharArray()) { if (lastChar == null) { // First character lastChar = Character.toUpperCase(curChar); natural = natural + lastChar; } else { if (Character.isLowerCase(lastChar) && (Character.isUpperCase(curChar)) || Character.isDigit(curChar)) { natural = natural + " " + curChar; } else { natural = natural + curChar; } lastChar = curChar; } } return natural; }
From source file:jetx.ext.common.StringMethods.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>//from ww w . j a v a 2 s . c o m * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre> * StringMethods.swapCase(null) = null * StringMethods.swapCase("") = "" * StringMethods.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, {@code null} if null String input */ public static String swapCase(String str) { if (isEmpty(str)) { return str; } char[] buffer = str.toCharArray(); for (int i = 0; i < buffer.length; i++) { char ch = buffer[i]; if (Character.isUpperCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { buffer[i] = Character.toUpperCase(ch); } } return new String(buffer); }
From source file:org.ofbiz.base.util.ObjectType.java
/** * Loads a class with the specified classloader. * @param className The name of the class to load * @param loader The ClassLoader to use/*from w ww . j av a 2s.c o m*/ * @return The requested class * @throws ClassNotFoundException */ public static Class<?> loadClass(String className, ClassLoader loader) throws ClassNotFoundException { Class<?> theClass = null; // if it is a primitive type, return the object from the "primitives" map if (primitives.containsKey(className)) { return primitives.get(className); } int genericsStart = className.indexOf("<"); if (genericsStart != -1) className = className.substring(0, genericsStart); // Handle array classes. Details in http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/types.html#wp16437 if (className.endsWith("[]")) { if (Character.isLowerCase(className.charAt(0)) && className.indexOf(".") < 0) { String prefix = className.substring(0, 1).toUpperCase(); // long and boolean have other prefix than first letter if (className.startsWith("long")) { prefix = "J"; } else if (className.startsWith("boolean")) { prefix = "Z"; } className = "[" + prefix; } else { Class<?> arrayClass = loadClass(className.replace("[]", ""), loader); className = "[L" + arrayClass.getName().replace("[]", "") + ";"; } } // if className is an alias (e.g. "String") then replace it with the proper class name (e.g. "java.lang.String") if (classAlias.containsKey(className)) { className = classAlias.get(className); } if (loader == null) loader = Thread.currentThread().getContextClassLoader(); theClass = Class.forName(className, true, loader); return theClass; }
From source file:org.gbif.portal.harvest.workflow.activity.taxonomy.RankAndScientificNameHandlerActivity.java
/** * @see org.gbif.portal.util.workflow.Activity#execute(org.gbif.portal.util.workflow.ProcessContext) *//*from w ww . j av a2s. c om*/ @SuppressWarnings("unchecked") public ProcessContext execute(ProcessContext context) throws Exception { String rankString = (String) context.get(getContextKeyRank(), String.class, false); if (rankString != null) { Integer rank = taxonRankMapping.mapToCode(StringUtils.chomp(rankString, ".")); if (rank == null) { StringBuffer sb = new StringBuffer(); sb.append(rankString); sb.append(": rank string not mapped"); if (getContextKeyRawOccurrenceRecord() != null) { RawOccurrenceRecord ror = (RawOccurrenceRecord) context.get(getContextKeyRawOccurrenceRecord(), RawOccurrenceRecord.class, false); if (ror != null) { sb.append(" raw occurrence record: "); sb.append(ror.getId()); if (ror.getCollectionCode() != null) { sb.append("; collection code: "); sb.append(ror.getCollectionCode()); } if (ror.getInstitutionCode() != null) { sb.append("; catalogue number: "); sb.append(ror.getInstitutionCode()); } if (ror.getCatalogueNumber() != null) { sb.append("; catalogue number: "); sb.append(ror.getCatalogueNumber()); } } } GbifLogMessage message = gbifLogUtils.createGbifLogMessage(context, LogEvent.EXTRACT_TAXONRANKPARSEISSUE, sb.toString()); message.setCountOnly(true); logger.error(message); throw new UnknownRankException("Could not find a mapping for rank string: " + rankString); } context.put(getContextKeyParsedRank(), rank); String contextKey = (String) ranksToNameContextKeys.get(rank.toString()); if (contextKey != null && !contextKey.equals(getContextKeyScientificName())) { String scientificName = (String) context.get(getContextKeyScientificName(), String.class, false); // If the name is of species rank or lower and starts with an upper case // character, assume it is a full scientific name if (scientificName != null && (rank < 7000 || Character.isLowerCase(scientificName.charAt(0)))) { String rankValue = (String) context.get(contextKey, String.class, false); if (rankValue == null) { context.put(contextKey, scientificName); context.remove(getContextKeyScientificName()); } } } contextKey = (String) ranksToAuthorContextKeys.get(rank.toString()); if (contextKey != null && !contextKey.equals(getContextKeyAuthor())) { String author = (String) context.get(getContextKeyAuthor(), String.class, false); if (author != null) { String rankValue = (String) context.get(contextKey, String.class, false); if (rankValue == null) { context.put(contextKey, author); context.remove(getContextKeyAuthor()); } } } String infraspecificMarker = (String) ranksToInfraspecificMarkers.get(rank); if (infraspecificMarker != null) { String currentMarker = (String) context.get(getContextKeyInfraspecificMarker(), String.class, false); if (currentMarker == null) { context.put(getContextKeyInfraspecificMarker(), infraspecificMarker); } } } return context; }
From source file:org.nuxeo.runtime.datasource.DataSourceFactory.java
@Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!DataSource.class.getName().equals(ref.getClassName())) { return null; }//ww w . j a v a2s . c om TransactionManager transactionManager; try { transactionManager = TransactionHelper.lookupTransactionManager(); } catch (NamingException e) { transactionManager = null; } boolean xa = ref.get(BasicManagedDataSourceFactory.PROP_XADATASOURCE) != null; log.info(String.format("Creating pooled %s datasource: %s/%s", xa ? "XA" : "non-XA", nameCtx.getNameInNamespace(), name)); if (xa && transactionManager == null) { throw new RuntimeException( "Cannot configure XA datasource " + name + " without an available transaction manager"); } // extract properties from Reference Map<String, String> properties = new HashMap<String, String>(); Enumeration<RefAddr> refAddrs = ref.getAll(); while (refAddrs.hasMoreElements()) { RefAddr ra = refAddrs.nextElement(); String key = ra.getType(); String value = ra.getContent().toString(); if (key.startsWith(DataSourceDescriptor.PROP_PREFIX)) { key = key.substring(DataSourceDescriptor.PROP_PREFIX.length()); properties.put(key, value); } } DataSource ds; if (!xa) { // fetch url from properties for (Entry<String, String> en : properties.entrySet()) { // often misspelled, thus the ignore case if (URL_LOWER.equalsIgnoreCase(en.getKey())) { ref.add(new StringRefAddr(URL_LOWER, en.getValue())); } } ObjectFactory factory = new BasicDataSourceFactory(); ds = (DataSource) factory.getObjectInstance(ref, name, nameCtx, env); BasicDataSource bds = (BasicDataSource) ds; // set properties for (Entry<String, String> en : properties.entrySet()) { String key = en.getKey(); if (URL_LOWER.equalsIgnoreCase(key)) { continue; } bds.addConnectionProperty(key, en.getValue()); } } else { ObjectFactory factory = new BasicManagedDataSourceFactory(); ds = (DataSource) factory.getObjectInstance(obj, name, nameCtx, env); if (ds == null) { return null; } BasicManagedDataSource bmds = (BasicManagedDataSource) ds; // set transaction manager bmds.setTransactionManager(transactionManager); // set properties XADataSource xaDataSource = bmds.getXaDataSourceInstance(); if (xaDataSource == null) { return null; } for (Entry<String, String> en : properties.entrySet()) { String key = en.getKey(); // proper JavaBean convention for initial cap if (Character.isLowerCase(key.charAt(1))) { key = Character.toLowerCase(key.charAt(0)) + key.substring(1); } String value = en.getValue(); boolean ok = false; try { BeanUtils.setProperty(xaDataSource, key, value); ok = true; } catch (Exception e) { if (URL_LOWER.equals(key)) { // commonly misspelled try { BeanUtils.setProperty(xaDataSource, URL_UPPER, value); ok = true; } catch (Exception ee) { // log error below } } } if (!ok) { log.error(String.format("Cannot set %s = %s on %s", key, value, xaDataSource.getClass().getName())); } } } return ds; }
From source file:eu.crisis_economics.configuration.ObjectReferenceExpression.java
public static List<String> isExpressionOfType(String rawExpression, FromFileConfigurationContext context) { String expression = rawExpression.trim(); if (expression.length() == 0) return null; boolean beginsWithLowercase = Character.isLowerCase(expression.charAt(0)); if (!beginsWithLowercase) return null; int endOfTypename = -1; for (int i = 0; i < expression.length(); ++i) { Character charNow = expression.charAt(i); if (Character.isLetter(charNow) || charNow == '_') continue; endOfTypename = i;/*from w w w.j a v a2 s . c o m*/ break; } if (endOfTypename == -1) return Arrays.asList(expression); // no indexing if (expression.charAt(endOfTypename) == '[') { if (expression.charAt(expression.length() - 1) != ']') return null; String typeDeclExpression = expression.substring(0, endOfTypename); String indexExpression = expression.substring(endOfTypename + 1, expression.length() - 1); if (IntegerPrimitiveExpression.isExpressionOfType(indexExpression, context) == null) return null; // with indexing return Arrays.asList(typeDeclExpression, indexExpression); } else return null; }
From source file:org.castor.cpa.persistence.sql.connection.DataSourceConnectionFactory.java
/** * Build the name of the method to set the parameter value of the given name. The * name of the method is build by preceding given parameter name with 'set' followed * by all letters of the name. In addition the first letter and all letters * following a '-' sign are converted to upper case. * // w ww. j a v a2 s . co m * @param name The name of the parameter. * @return The name of the method to set the value of this parameter. */ public static String buildMethodName(final String name) { StringBuffer sb = new StringBuffer("set"); boolean first = true; for (int i = 0; i < name.length(); i++) { char chr = name.charAt(i); if (first && Character.isLowerCase(chr)) { sb.append(Character.toUpperCase(chr)); first = false; } else if (Character.isLetter(chr)) { sb.append(chr); first = false; } else if (chr == '-') { first = true; } } return sb.toString(); }
From source file:org.jspresso.framework.util.bean.PropertyHelper.java
/** * Whenever a property name starts with a single lowercase letter, the actual * java bean property starts with an upper case letter. * * @param prop//from ww w . ja v a 2 s. c o m * the property name. * @return the fixed java bean property name. */ public static String toJavaBeanPropertyName(String prop) { if (prop != null && prop.length() >= 2) { if (Character.isLowerCase(prop.charAt(0)) && Character.isUpperCase(prop.charAt(1))) { StringBuilder fixedProp = new StringBuilder(prop.substring(0, 1).toUpperCase()); fixedProp.append(prop.substring(1)); return fixedProp.toString(); } } return prop; }
From source file:org.kuali.rice.krad.util.KRADUtils.java
/** * Retrieve the title for a business object class * * <p>// w w w . ja v a 2 s. co m * The title is a nicely formatted version of the simple class name. * </p> * * @param clazz business object class * @return title of the business object class */ public final static String getBusinessTitleForClass(Class<? extends Object> clazz) { if (clazz == null) { throw new IllegalArgumentException( "The getBusinessTitleForClass method of KRADUtils requires a non-null class"); } String className = clazz.getSimpleName(); StringBuffer label = new StringBuffer(className.substring(0, 1)); for (int i = 1; i < className.length(); i++) { if (Character.isLowerCase(className.charAt(i))) { label.append(className.charAt(i)); } else { label.append(" ").append(className.charAt(i)); } } return label.toString().trim(); }