List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:Main.java
/** * Put common code to deepTrim(String) and deepTrimToLower here. * /*from w w w .ja v a 2s. c o m*/ * @param str * the string to deep trim * @param toLowerCase * how to normalize for case: upper or lower * @return the deep trimmed string * @see StringTools#deepTrim( String ) * * TODO Replace the toCharArray() by substring manipulations */ public static final String deepTrim(String str, boolean toLowerCase) { if ((null == str) || (str.length() == 0)) { return ""; } char ch; char[] buf = str.toCharArray(); char[] newbuf = new char[buf.length]; boolean wsSeen = false; boolean isStart = true; int pos = 0; for (int i = 0; i < str.length(); i++) { ch = buf[i]; // filter out all uppercase characters if (toLowerCase) { if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } } // Check to see if we should add space if (Character.isWhitespace(ch)) { // If the buffer has had characters added already check last // added character. Only append a spc if last character was // not whitespace. if (wsSeen) { continue; } else { wsSeen = true; if (isStart) { isStart = false; } else { newbuf[pos++] = ch; } } } else { // Add all non-whitespace wsSeen = false; isStart = false; newbuf[pos++] = ch; } } return (pos == 0 ? "" : new String(newbuf, 0, (wsSeen ? pos - 1 : pos))); }
From source file:org.eclipse.wb.internal.rcp.databinding.emf.model.bindables.EmfCodeGenUtil.java
/** * Formats a name by parsing it into words separated by underscores and/or mixed-casing and then * recombining them using the specified separator. A prefix can also be given to be recognized as * a separate word or to be trimmed. Leading underscores can be ignored or can cause a leading * separator to be prepended.// w w w . ja va2 s. c o m * * @since 2.2 */ public static String format(String name, char separator, String prefix, boolean includePrefix, boolean includeLeadingSeparator) { String leadingSeparators = includeLeadingSeparator ? getLeadingSeparators(name, '_') : null; if (leadingSeparators != null) { name = name.substring(leadingSeparators.length()); } List<String> parsedName = new ArrayList<String>(); if (prefix != null && name.startsWith(prefix) && name.length() > prefix.length() && Character.isUpperCase(name.charAt(prefix.length()))) { name = name.substring(prefix.length()); if (includePrefix) { parsedName = parseName(prefix, '_'); } } if (name.length() != 0) { parsedName.addAll(parseName(name, '_')); } StringBuilder result = new StringBuilder(); for (Iterator<String> nameIter = parsedName.iterator(); nameIter.hasNext();) { String nameComponent = nameIter.next(); result.append(nameComponent); if (nameIter.hasNext() && nameComponent.length() > 1) { result.append(separator); } } if (result.length() == 0 && prefix != null) { result.append(prefix); } return leadingSeparators != null ? "_" + result.toString() : result.toString(); }
From source file:io.lavagna.model.util.ShortNameGenerator.java
private static int countUpperCase(String s) { int cnt = 0;/*from w w w.jav a2s .c o m*/ for (char c : s.toCharArray()) { if (Character.isUpperCase(c)) { cnt++; } } return cnt; }
From source file:com.autentia.common.util.PasswordUtils.java
private static boolean atLeastOneLowercaseLetter(String pwd) { final char[] pwdChars = pwd.toCharArray(); for (int i = 0; i < pwdChars.length; i++) { if (Character.isUpperCase(pwdChars[i])) { return true; }/*from w ww . j a va 2s .co m*/ } return false; }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Separates with a blank the different tokens that can compose a normal class or method name, like for instance * doSomething into Do something.// w ww . j av a2 s. c o m * * @param str The string to separate. * @return The separated string. */ public static String separeTokens(String str) { StringBuilder b = new StringBuilder(); if (str != null) { for (int i = 0; i < str.length(); i++) { if (i == 0) { b.append(Character.toUpperCase(str.charAt(i))); } else { if (Character.isLowerCase(str.charAt(i - 1)) && Character.isUpperCase(str.charAt(i))) { b.append(' '); if ((i < str.length() - 1) && Character.isUpperCase(str.charAt(i + 1))) { b.append(str.charAt(i)); } else { b.append(Character.toLowerCase(str.charAt(i))); } } else { b.append(str.charAt(i)); } } } } return b.toString(); }
From source file:org.apdplat.superword.rule.SuffixRule.java
public static List<Word> findBySuffix(Collection<Word> words, Suffix suffix, boolean strict) { return words.parallelStream().filter(word -> { String w = word.getWord(); if (Character.isUpperCase(w.charAt(0))) { return false; }// www .ja va 2 s . co m String s = suffix.getSuffix().replace("-", "").toLowerCase(); if (strict) { if (w.endsWith(s) && w.length() - s.length() > 2 && words.contains(new Word(w.substring(0, w.length() - s.length()), ""))) { return true; } } else if (w.endsWith(s)) { return true; } return false; }).sorted().collect(Collectors.toList()); }
From source file:com.sf.ddao.crud.param.CRUDBeanPropsParameter.java
public static String mapPropName2Field(PropertyDescriptor descriptor) { final String s = descriptor.getName(); StringBuilder sb = new StringBuilder(s.length()); for (char ch : s.toCharArray()) { if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); sb.append("_").append(ch); } else {//from ww w . j a va 2 s.c o m sb.append(ch); } } return sb.toString(); }
From source file:corner.util.BeanUtils.java
/** * bean/*w w w. j a va 2 s . c o m*/ * * @param bean * bean. * @param pro * ??. * @return . */ public static Object getProperty(Object bean, String pro) { if (Character.isUpperCase(pro.charAt(0))) { pro = Character.toLowerCase(pro.charAt(0)) + pro.substring(1); } try { return org.apache.commons.beanutils.PropertyUtils.getProperty(bean, pro); } catch (Exception e) { return null; } }
From source file:org.apdplat.superword.rule.PrefixRule.java
public static List<Word> findByPrefix(Collection<Word> words, Prefix prefix, boolean strict) { return words.parallelStream().filter(word -> { String w = word.getWord(); if (Character.isUpperCase(w.charAt(0))) { return false; }/* ww w . ja v a2 s .c o m*/ String p = prefix.getPrefix().replace("-", "").toLowerCase(); if (strict) { if (w.startsWith(p) && w.length() - p.length() > 2 && words.contains(new Word(w.substring(p.length()), ""))) { return true; } } else if (w.startsWith(p)) { return true; } return false; }).sorted().collect(Collectors.toList()); }
From source file:com.acuityph.commons.util.ClassUtils.java
/** * @param methodName/*from w w w .j av a 2s. c o m*/ * the method name to check * @return true if the given method name matches a property getter pattern */ private static boolean isPropertySetterName(final String methodName) { return hasLength(methodName) && methodName.length() > 3 && methodName.startsWith("set") && Character.isUpperCase(methodName.charAt(3)); }