List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:com.thinkbiganalytics.feedmgr.rest.support.SystemNamingService.java
public static String generateSystemName(String name) { //first trim it String systemName = StringUtils.trimToEmpty(name); if (StringUtils.isBlank(systemName)) { return systemName; }//from w ww . j av a 2s .c o m systemName = systemName.replaceAll(" +", "_"); systemName = systemName.replaceAll("[^\\w_]", ""); int i = 0; StringBuilder s = new StringBuilder(); CharacterIterator itr = new StringCharacterIterator(systemName); for (char c = itr.first(); c != CharacterIterator.DONE; c = itr.next()) { if (Character.isUpperCase(c)) { //if it is upper, not at the start and not at the end check to see if i am surrounded by upper then lower it. if (i > 0 && i != systemName.length() - 1) { char prevChar = systemName.charAt(i - 1); char nextChar = systemName.charAt(i + 1); if (Character.isUpperCase(prevChar) && (Character.isUpperCase(nextChar) || CharUtils.isAsciiNumeric(nextChar) || '_' == nextChar || '-' == nextChar)) { char lowerChar = Character.toLowerCase(systemName.charAt(i)); s.append(lowerChar); } else { s.append(c); } } else if (i > 0 && i == systemName.length() - 1) { char prevChar = systemName.charAt(i - 1); if (Character.isUpperCase(prevChar) && !CharUtils.isAsciiNumeric(systemName.charAt(i))) { char lowerChar = Character.toLowerCase(systemName.charAt(i)); s.append(lowerChar); } else { s.append(c); } } else { s.append(c); } } else { s.append(c); } i++; } systemName = s.toString(); systemName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, systemName); systemName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_UNDERSCORE, systemName); systemName = StringUtils.replace(systemName, "__", "_"); // Truncate length if exceeds Hive limit systemName = (systemName.length() > 128 ? systemName.substring(0, 127) : systemName); return systemName; }
From source file:net.certiv.antlr.project.util.Strings.java
public static String camelCase(String in) { StringBuilder sb = new StringBuilder(in); for (int idx = sb.length() - 1; idx >= 0; idx--) { char c = sb.charAt(idx); if (c == '_') { sb.deleteCharAt(idx);/*from w w w. j a v a2s . c o m*/ sb.setCharAt(idx, Character.toUpperCase(sb.charAt(idx))); } else if (Character.isUpperCase(c)) { sb.setCharAt(idx, Character.toLowerCase(c)); } } sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); return sb.toString(); }
From source file:com.boundary.plugin.sdk.PluginUtil.java
/** * Transform a camel case string into a upper case string with underscores * /*from w ww. j a v a 2s.c o m*/ * @param s {@link String} to transform * @param d replacement character for white space * @return {@link String} */ public static String toUpperUnderscore(String s, Character d) { StringBuilder builder = new StringBuilder(); s = s.trim(); boolean first = true; for (int i = 0; i < s.length(); i++) { if (Character.isWhitespace(s.charAt(i))) { builder.append(d); } else { if (Character.isUpperCase(s.charAt(i))) { if (first == false) { if (i + 1 < s.length() && Character.isLowerCase(s.charAt(i + 1))) { builder.append(d); } } } builder.append(Character.toUpperCase(s.charAt(i))); } first = false; } StringBuilder r = new StringBuilder(); r.append('\\').append(d).append('\\').append(d); return builder.toString().replaceAll(r.toString(), d.toString()); }
From source file:grails.web.CamelCaseUrlConverter.java
public String toUrlElement(String propertyOrClassName) { if (StringUtils.isBlank(propertyOrClassName)) { return propertyOrClassName; }//from w ww. ja v a2 s . co m if (propertyOrClassName.length() > 1 && Character.isUpperCase(propertyOrClassName.charAt(0)) && Character.isUpperCase(propertyOrClassName.charAt(1))) { return propertyOrClassName; } return propertyOrClassName.substring(0, 1).toLowerCase(Locale.ENGLISH) + propertyOrClassName.substring(1); }
From source file:com.qualogy.qafe.util.StyleDomUtil.java
/** * convert for example backgrounColor to background-color * @param style// w w w . ja v a 2s. c o m * @return */ public static String deCamelCaseStyle(String style) { String property = ""; for (int j = 0; j < style.length(); j++) { char character = style.charAt(j); if (Character.isUpperCase(character)) { property += "-" + Character.toLowerCase(character); } else { property += character; } } return property; }
From source file:grails.web.HyphenatedUrlConverter.java
public String toUrlElement(String propertyOrClassName) { if (StringUtils.isBlank(propertyOrClassName)) { return propertyOrClassName; }/*from w w w . ja v a2 s.co m*/ StringBuilder builder = new StringBuilder(); char[] charArray = propertyOrClassName.toCharArray(); for (char c : charArray) { if (Character.isUpperCase(c)) { if (builder.length() > 0) { builder.append("-"); } builder.append(Character.toLowerCase(c)); } else { builder.append(c); } } return builder.toString(); }
From source file:org.moe.gradle.utils.StringUtils.java
@Nullable public static List<String> getElemsInRule(@NotNull String rule, @NotNull String prefix, @NotNull String suffix) { Require.nonNull(rule);// w w w . jav a 2s . c om Require.nonNull(prefix); Require.nonNull(suffix); if (!rule.startsWith(prefix) || !rule.endsWith(suffix)) { return null; } final String base = rule.substring(prefix.length(), rule.length() - suffix.length()); if (base.length() == 0) { return Collections.emptyList(); } List<String> words = new ArrayList<>(); int start = 0; int stop = 1; while (stop < base.length()) { if (Character.isUpperCase(base.charAt(stop))) { words.add(base.substring(start, stop).toLowerCase()); start = stop; } stop++; if (stop >= base.length()) { words.add(base.substring(start, stop).toLowerCase()); } } return words; }
From source file:io.spring.initializr.util.VersionProperty.java
private static String validateFormat(String property) { for (char c : property.toCharArray()) { if (Character.isUpperCase(c)) { throw new IllegalArgumentException( "Invalid property '" + property + "', must not contain upper case"); }/* w ww . j a v a 2 s . c om*/ if (!Character.isLetterOrDigit(c) && !SUPPORTED_CHARS.contains(c)) { throw new IllegalArgumentException("Unsupported character '" + c + "' for '" + property + "'"); } } return property; }
From source file:org.eclim.plugin.jdt.command.include.ImportUtils.java
public static List<String> packageName(ImportDeclaration imprt) { String name = imprt.getName().getFullyQualifiedName(); List<String> pack = new ArrayList<String>(); for (String part : StringUtils.split(name, '.')) { if (Character.isUpperCase(part.charAt(0))) { break; }/* w ww. java 2s . c o m*/ pack.add(part); } return pack; }
From source file:com.vaadin.spring.internal.Conventions.java
private static boolean shouldPrependHyphen(String string, int i) { if (i == 0) { // Never put a hyphen at the beginning return false; } else if (!Character.isUpperCase(string.charAt(i - 1))) { // Append if previous char wasn't upper case return true; } else if (i + 1 < string.length() && !Character.isUpperCase(string.charAt(i + 1))) { // Append if next char isn't upper case return true; } else {//from w w w. j a va 2 s .co m return false; } }