List of usage examples for java.lang Character toLowerCase
public static int toLowerCase(int codePoint)
From source file:io.swagger.inflector.utils.ReflectionUtils.java
public String getMethodName(String path, String httpMethod, Operation operation) { String output = operation.getOperationId(); if (output != null) { return sanitizeToJava(output); }//from w w w. j a va 2 s . c o m String tmpPath = path; tmpPath = tmpPath.replaceAll("\\{", ""); tmpPath = tmpPath.replaceAll("\\}", ""); String[] parts = (tmpPath + "/" + httpMethod).split("/"); StringBuilder builder = new StringBuilder(); if ("/".equals(tmpPath)) { // must be root tmpPath builder.append("root"); } for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (part.length() > 0) { if (builder.toString().length() == 0) { part = Character.toLowerCase(part.charAt(0)) + part.substring(1); } else { part = StringUtils.capitalize(part); } builder.append(part); } } output = builder.toString(); LOGGER.warn("generated operationId " + output); return output; }
From source file:org.agiso.core.i18n.util.I18nUtils.java
private static String findGetterFieldName(Method m) { String name = m.getName();/*from ww w . j a v a 2 s. com*/ if (name.length() > 3 && name.startsWith("get") && Character.isUpperCase(name.charAt(3))) { if (name.length() == 4) { name = String.valueOf(Character.toLowerCase(name.charAt(3))); } else { name = String.valueOf(Character.toLowerCase(name.charAt(3))) + name.substring(4); } } else if (name.length() > 2 && name.startsWith("is") && Character.isUpperCase(name.charAt(2))) { if (name.length() == 3) { name = String.valueOf(Character.toLowerCase(name.charAt(2))); } else { name = String.valueOf(Character.toLowerCase(name.charAt(2))) + name.substring(3); } } return name; }
From source file:com.caocao.util.StringUtils.java
/** * ??splitcamelToSplitName("camelToSplitName",",") return camel,to,split,name * //w w w.j av a 2 s . co m * @author wei * @created 2012-12-4 ?4:11:53 * @since v1.3.1 * @param camelName * @param split * @return */ public static String camelToSplitName(String camelName, String split) { if (camelName == null || camelName.length() == 0) { return camelName; } StringBuilder buf = null; for (int i = 0; i < camelName.length(); i++) { char ch = camelName.charAt(i); if (ch >= 'A' && ch <= 'Z') { if (buf == null) { buf = new StringBuilder(); if (i > 0) { buf.append(camelName.substring(0, i)); } } if (i > 0) { buf.append(split); } buf.append(Character.toLowerCase(ch)); } else if (buf != null) { buf.append(ch); } } return buf == null ? camelName : buf.toString(); }
From source file:org.apdplat.superword.rule.TextAnalysis.java
public static String toHtmlFragment(Map<String, List<String>> data) { StringBuilder html = new StringBuilder(); AtomicInteger i = new AtomicInteger(); data.keySet().stream().forEach(word -> { StringBuilder p = new StringBuilder(); for (char c : word.toCharArray()) { p.append("[").append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append("]{1}"); }//from www. j av a 2 s. c o m html.append(i.incrementAndGet()).append("??? ").append(WordLinker.toLink(word)) .append(" ?<br/>\n"); html.append("<ol>\n"); data.get(word) .forEach(t -> html.append("\t<li>") .append(t.replaceAll(p.toString(), "<font color=\"red\">" + word + "</font>")) .append("</li><br/>\n")); html.append("</ol><br/>\n"); }); return html.toString(); }
From source file:com.facebook.buck.util.Escaper.java
/** * Decode a numeric escape as explained in this page: * <a href="http://en.cppreference.com/w/cpp/language/escape"> * http://en.cppreference.com/w/cpp/language/escape * </a>. The pointed-to substring shouldn't contain the leading backslash + optional 'x' or 'u'. * @param out receives decoded characters * @param escaped the string containing the escape sequence * @param pos starting index of escape (but after the backslash) * @param base number base, e.g. 8 for octal, or 16 for hex or unicode. * @param maxCodes maximum number of sequences of escape numbers to decode. This is mainly * to support unicode escape sequences which might represent one or two characters. * @return position to first character just after the consumed numeric code. Is number of * consumed code bytes + {@code pos} argument. *///from w w w . jav a 2 s . c o m public static int decodeNumericEscape(StringBuilder out, String escaped, int pos, int maxCodeLength, int base, int maxCodes) { final String table = "0123456789abcdef"; for (int code = 0; code < maxCodes; code++) { char c = 0; boolean valid = false; for (int i = 0; i < maxCodeLength && pos < escaped.length(); i++) { final int digit = table.indexOf(Character.toLowerCase(escaped.charAt(pos))); if (digit == -1 || digit >= base) { break; } // "digit" is a valid value for the digit read, in the range [0, base). // Now we can increment the position, consuming that digit. pos++; c = (char) ((c * base) + digit); valid = true; } if (valid) { out.append(c); } } return pos; }
From source file:ca.uhn.fhir.narrative.BaseThymeleafNarrativeGenerator.java
static String cleanWhitespace(String theResult) { StringBuilder b = new StringBuilder(); boolean inWhitespace = false; boolean betweenTags = false; boolean lastNonWhitespaceCharWasTagEnd = false; boolean inPre = false; for (int i = 0; i < theResult.length(); i++) { char nextChar = theResult.charAt(i); if (inPre) { b.append(nextChar);//from w w w . j av a 2 s. co m continue; } else if (nextChar == '>') { b.append(nextChar); betweenTags = true; lastNonWhitespaceCharWasTagEnd = true; continue; } else if (nextChar == '\n' || nextChar == '\r') { // if (inWhitespace) { // b.append(' '); // inWhitespace = false; // } continue; } if (betweenTags) { if (Character.isWhitespace(nextChar)) { inWhitespace = true; } else if (nextChar == '<') { if (inWhitespace && !lastNonWhitespaceCharWasTagEnd) { b.append(' '); } inWhitespace = false; b.append(nextChar); inWhitespace = false; betweenTags = false; lastNonWhitespaceCharWasTagEnd = false; if (i + 3 < theResult.length()) { char char1 = Character.toLowerCase(theResult.charAt(i + 1)); char char2 = Character.toLowerCase(theResult.charAt(i + 2)); char char3 = Character.toLowerCase(theResult.charAt(i + 3)); char char4 = Character .toLowerCase((i + 4 < theResult.length()) ? theResult.charAt(i + 4) : ' '); if (char1 == 'p' && char2 == 'r' && char3 == 'e') { inPre = true; } else if (char1 == '/' && char2 == 'p' && char3 == 'r' && char4 == 'e') { inPre = false; } } } else { lastNonWhitespaceCharWasTagEnd = false; if (inWhitespace) { b.append(' '); inWhitespace = false; } b.append(nextChar); } } else { b.append(nextChar); } } return b.toString(); }
From source file:org.apache.struts2.config.ClasspathPackageProvider.java
/** * Create a default action mapping for a class instance. * * The namespace annotation is honored, if found, otherwise * the Java package is converted into the namespace * by changing the dots (".") to slashes ("/"). * * @param cls Action or POJO instance to process * @param pkgs List of packages that were scanned for Actions *//*from www . j a v a 2 s . com*/ protected void processActionClass(Class<?> cls, String[] pkgs) { String name = cls.getName(); String actionPackage = cls.getPackage().getName(); String actionNamespace = null; String actionName = null; org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls .getAnnotation(org.apache.struts2.config.Action.class); if (actionAnn != null) { actionName = actionAnn.name(); if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) { actionNamespace = ""; } else { actionNamespace = actionAnn.namespace(); } } else { for (String pkg : pkgs) { if (name.startsWith(pkg)) { if (LOG.isDebugEnabled()) { LOG.debug("ClasspathPackageProvider: Processing class " + name); } name = name.substring(pkg.length() + 1); actionNamespace = ""; actionName = name; int pos = name.lastIndexOf('.'); if (pos > -1) { actionNamespace = "/" + name.substring(0, pos).replace('.', '/'); actionName = name.substring(pos + 1); } break; } } // Truncate Action suffix if found if (actionName.endsWith(getClassSuffix())) { actionName = actionName.substring(0, actionName.length() - getClassSuffix().length()); } // Force initial letter of action to lowercase, if desired if ((forceLowerCase) && (actionName.length() > 1)) { int lowerPos = actionName.lastIndexOf('/') + 1; StringBuilder sb = new StringBuilder(); sb.append(actionName.substring(0, lowerPos)); sb.append(Character.toLowerCase(actionName.charAt(lowerPos))); sb.append(actionName.substring(lowerPos + 1)); actionName = sb.toString(); } } PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls); // In case the package changed due to namespace annotation processing if (!actionPackage.equals(pkgConfig.getName())) { actionPackage = pkgConfig.getName(); } List<PackageConfig> parents = findAllParentPackages(cls); if (parents.size() > 0) { pkgConfig.addParents(parents); // Try to guess the namespace from the first package PackageConfig firstParent = parents.get(0); if (StringUtils.isEmpty(pkgConfig.getNamespace()) && StringUtils.isNotEmpty(firstParent.getNamespace())) { pkgConfig.namespace(firstParent.getNamespace()); } } ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig); ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()) .addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build(); pkgConfig.addActionConfig(actionName, actionConfig); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.localworkspace.IgnoreFile.java
/** * Similar to .NET's String.Compare(String, Int32, String, Int32, Int32, * StringComparison), but always does a locale-invariant case-insensitive * comparison instead of honoring a StringComparison arg. * <p>//from w w w . j av a2 s .co m * This method is here and not in {@link LocaleInvariantStringHelpers} * because it does bounds checking in the .NET way, which differs from * Java's {@link String#regionMatches(boolean, int, String, int, int)} * enough to keep it separate. But the match algorithm at the bottom could * be useful in a new method there. */ private int compareCaseInsensitive(final String strA, final int offsetA, final String strB, final int offsetB, final int length) { if (strA == null && strB != null) { return -1; } else if (strA != null && strB == null) { return 1; } // .NET is documented to throw when length > 0 and one is not null else if ((strA == null || strB == null) && length > 0) { throw new IndexOutOfBoundsException("length cannot be > 0 with null string arguments"); //$NON-NLS-1$ } // End values exclusive final int endA = offsetA + length; final int endB = offsetB + length; if (endA > strA.length()) { throw new IndexOutOfBoundsException("offsetA + length is past the end of strA"); //$NON-NLS-1$ } if (endB > strB.length()) { throw new IndexOutOfBoundsException("offsetB + length is past the end of strB"); //$NON-NLS-1$ } /* * We checked that we won't walk off the end of either string, so we can * use just one of the end indices (endA) to limit our loop. */ for (int iA = offsetA, iB = offsetB; iA < endA; iA++, iB++) { char a = strA.charAt(iA); char b = strB.charAt(iB); if (a != b) { // Try both as upper case a = Character.toUpperCase(a); b = Character.toUpperCase(b); if (a != b) { // Try both as lower case a = Character.toLowerCase(a); b = Character.toLowerCase(b); if (a != b) { // Unicode difference works return a - b; } } } } // Got to end of both segments without a difference return 0; }
From source file:org.powertac.logtool.common.DomainObjectReader.java
private String resolveDoubleCaps(String name) { // lowercase first char of field name with two initial caps if (Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) { char[] chars = name.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return (String.valueOf(chars)); }// w w w . ja va 2s. c o m return name; }
From source file:com.zero_x_baadf00d.partialize.Partialize.java
/** * Build a JSON object from data taken from the scanner and * the given class type and instance.//from w w w . java2 s . c om * * @param depth The current depth * @param fields The field names to requests * @param clazz The class of the object to render * @param instance The instance of the object to render * @param partialObject The partial JSON document * @return A JSON Object * @since 16.01.18 */ private ObjectNode buildPartialObject(final int depth, String fields, final Class<?> clazz, final Object instance, final ObjectNode partialObject) { if (depth <= this.maximumDepth) { if (clazz.isAnnotationPresent(com.zero_x_baadf00d.partialize.annotation.Partialize.class)) { final List<String> closedFields = new ArrayList<>(); List<String> allowedFields = Arrays.asList(clazz .getAnnotation(com.zero_x_baadf00d.partialize.annotation.Partialize.class).allowedFields()); List<String> defaultFields = Arrays.asList(clazz .getAnnotation(com.zero_x_baadf00d.partialize.annotation.Partialize.class).defaultFields()); if (allowedFields.isEmpty()) { allowedFields = new ArrayList<>(); for (final Method m : clazz.getDeclaredMethods()) { final String methodName = m.getName(); if (methodName.startsWith("get") || methodName.startsWith("has")) { final char[] c = methodName.substring(3).toCharArray(); c[0] = Character.toLowerCase(c[0]); allowedFields.add(new String(c)); } else if (methodName.startsWith("is")) { final char[] c = methodName.substring(2).toCharArray(); c[0] = Character.toLowerCase(c[0]); allowedFields.add(new String(c)); } } } if (defaultFields.isEmpty()) { defaultFields = allowedFields.stream().map(f -> { if (this.aliases != null && this.aliases.containsValue(f)) { for (Map.Entry<String, String> e : this.aliases.entrySet()) { if (e.getValue().compareToIgnoreCase(f) == 0) { return e.getKey(); } } } return f; }).collect(Collectors.toList()); } if (fields == null || fields.length() == 0) { fields = defaultFields.stream().collect(Collectors.joining(",")); } Scanner scanner = new Scanner(fields); scanner.useDelimiter(com.zero_x_baadf00d.partialize.Partialize.SCANNER_DELIMITER); while (scanner.hasNext()) { String word = scanner.next(); String args = null; if (word.compareTo("*") == 0) { final StringBuilder sb = new StringBuilder(); if (scanner.hasNext()) { scanner.useDelimiter("\n"); sb.append(","); sb.append(scanner.next()); } final Scanner newScanner = new Scanner( allowedFields.stream().filter(f -> !closedFields.contains(f)).map(f -> { if (this.aliases != null && this.aliases.containsValue(f)) { for (Map.Entry<String, String> e : this.aliases.entrySet()) { if (e.getValue().compareToIgnoreCase(f) == 0) { return e.getKey(); } } } return f; }).collect(Collectors.joining(",")) + sb.toString()); newScanner.useDelimiter(com.zero_x_baadf00d.partialize.Partialize.SCANNER_DELIMITER); scanner.close(); scanner = newScanner; } if (word.contains("(")) { while (scanner.hasNext() && (StringUtils.countMatches(word, "(") != StringUtils.countMatches(word, ")"))) { word += "," + scanner.next(); } final Matcher m = this.fieldArgsPattern.matcher(word); if (m.find()) { word = m.group(1); args = m.group(2); } } final String aliasField = word; final String field = this.aliases != null && this.aliases.containsKey(aliasField) ? this.aliases.get(aliasField) : aliasField; if (allowedFields.stream().anyMatch( f -> f.toLowerCase(Locale.ENGLISH).compareTo(field.toLowerCase(Locale.ENGLISH)) == 0)) { if (this.accessPolicyFunction != null && !this.accessPolicyFunction.apply(new AccessPolicy(clazz, instance, field))) { continue; } closedFields.add(aliasField); try { final Method method = clazz.getMethod("get" + WordUtils.capitalize(field)); final Object object = method.invoke(instance); this.internalBuild(depth, aliasField, field, args, partialObject, clazz, object); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignore) { try { final Method method = clazz.getMethod(field); final Object object = method.invoke(instance); this.internalBuild(depth, aliasField, field, args, partialObject, clazz, object); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { if (this.exceptionConsumer != null) { this.exceptionConsumer.accept(ex); } } } } } return partialObject; } else if (instance instanceof Map<?, ?>) { if (fields == null || fields.isEmpty() || fields.compareTo("*") == 0) { for (Map.Entry<?, ?> e : ((Map<?, ?>) instance).entrySet()) { this.internalBuild(depth, String.valueOf(e.getKey()), String.valueOf(e.getKey()), null, partialObject, e.getValue() == null ? Object.class : e.getValue().getClass(), e.getValue()); } } else { final Map<?, ?> tmpMap = (Map<?, ?>) instance; for (final String k : fields.split(",")) { if (k.compareTo("*") != 0) { final Object o = tmpMap.get(k); this.internalBuild(depth, k, k, null, partialObject, o == null ? Object.class : o.getClass(), o); } else { for (Map.Entry<?, ?> e : ((Map<?, ?>) instance).entrySet()) { this.internalBuild(depth, String.valueOf(e.getKey()), String.valueOf(e.getKey()), null, partialObject, e.getValue() == null ? Object.class : e.getValue().getClass(), e.getValue()); } } } } } else { throw new RuntimeException("Can't convert " + clazz.getCanonicalName()); } } return partialObject; }