List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.fhcrc.cpl.toolbox.datastructure.BoundMap.java
private BoundProperty getBoundProperty(String key) { BoundProperty bound = _properties.get(key); if (null == bound && Character.isUpperCase(key.charAt(0))) bound = _properties.get(convertToPropertyName(key)); return bound; }
From source file:org.codehaus.groovy.grails.commons.ClassPropertyFetcher.java
private void init() { FieldCallback fieldCallback = new ReflectionUtils.FieldCallback() { public void doWith(Field field) { if (field.isSynthetic()) { return; }//from w ww . j av a 2 s.co m final int modifiers = field.getModifiers(); if (!Modifier.isPublic(modifiers)) { return; } final String name = field.getName(); if (name.indexOf('$') == -1) { boolean staticField = Modifier.isStatic(modifiers); if (staticField) { staticFetchers.put(name, new FieldReaderFetcher(field, staticField)); } else { instanceFetchers.put(name, new FieldReaderFetcher(field, staticField)); } } } }; MethodCallback methodCallback = new ReflectionUtils.MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (method.isSynthetic()) { return; } if (!Modifier.isPublic(method.getModifiers())) { return; } if (Modifier.isStatic(method.getModifiers()) && method.getReturnType() != Void.class) { if (method.getParameterTypes().length == 0) { String name = method.getName(); if (name.indexOf('$') == -1) { if (name.length() > 3 && name.startsWith("get") && Character.isUpperCase(name.charAt(3))) { name = name.substring(3); } else if (name.length() > 2 && name.startsWith("is") && Character.isUpperCase(name.charAt(2)) && (method.getReturnType() == Boolean.class || method.getReturnType() == boolean.class)) { name = name.substring(2); } PropertyFetcher fetcher = new GetterPropertyFetcher(method, true); staticFetchers.put(name, fetcher); staticFetchers.put(StringUtils.uncapitalize(name), fetcher); } } } } }; List<Class<?>> allClasses = resolveAllClasses(clazz); for (Class<?> c : allClasses) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { try { fieldCallback.doWith(field); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Shouldn't be illegal to access field '" + field.getName() + "': " + ex); } } Method[] methods = c.getDeclaredMethods(); for (Method method : methods) { try { methodCallback.doWith(method); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } } propertyDescriptors = BeanUtils.getPropertyDescriptors(clazz); for (PropertyDescriptor desc : propertyDescriptors) { Method readMethod = desc.getReadMethod(); if (readMethod != null) { boolean staticReadMethod = Modifier.isStatic(readMethod.getModifiers()); if (staticReadMethod) { staticFetchers.put(desc.getName(), new GetterPropertyFetcher(readMethod, staticReadMethod)); } else { instanceFetchers.put(desc.getName(), new GetterPropertyFetcher(readMethod, staticReadMethod)); } } } }
From source file:com.gzj.tulip.jade.rowmapper.BeanPropertyRowMapper.java
/** * Convert a name in camelCase to an underscored name in lower case. * Any upper case letters are converted to lower case with a preceding * underscore.//w w w .j a v a 2 s .c om * * @param camelCaseName the string containing original name * @return the converted name */ private String[] underscoreName(String camelCaseName) { StringBuilder result = new StringBuilder(); if (camelCaseName != null && camelCaseName.length() > 0) { result.append(camelCaseName.substring(0, 1).toLowerCase()); for (int i = 1; i < camelCaseName.length(); i++) { char ch = camelCaseName.charAt(i); if (Character.isUpperCase(ch)) { result.append("_"); result.append(Character.toLowerCase(ch)); } else { result.append(ch); } } } String name = result.toString(); // nameuser1_name2name2user_1_name_2 // user_1_name_2user1Name2 String name2 = null; boolean digitFound = false; for (int i = name.length() - 1; i >= 0; i--) { if (Character.isDigit(name.charAt(i))) { // ??continue,???continue digitFound = true; continue; } // ??? if (digitFound && i < name.length() - 1 && i > 0) { if (name2 == null) { name2 = name; } name2 = name2.substring(0, i + 1) + "_" + name2.substring(i + 1); } digitFound = false; } return new String[] { name, name2 }; }
From source file:banner.tagging.dictionary.DictionaryTagger.java
protected String transform(String str) { // This has been optimized for very fast operation String result = str;//from w w w . j a v a2s . c om if (stemTokens) { String stem = stemmer.stem(str); // System.out.println("Stemmer; original= " + str + ", stemmed= " + stem); str = stem; } if (normalizeMixedCase || normalizeDigits) { char[] chars = str.toCharArray(); if (normalizeMixedCase) { boolean hasUpper = false; boolean hasLower = false; for (int i = 0; i < chars.length && (!hasUpper || !hasLower); i++) { hasUpper |= Character.isUpperCase(chars[i]); hasLower |= Character.isLowerCase(chars[i]); } if (hasUpper && hasLower) for (int i = 0; i < chars.length; i++) chars[i] = Character.toLowerCase(chars[i]); } // Note that this only works on single digits if (normalizeDigits) for (int i = 0; i < chars.length; i++) if (Character.isDigit(chars[i])) chars[i] = '0'; result = new String(chars); } return result; }
From source file:org.cafed00d.subtitle.WordProcessor.java
/** * Examines the word and gather various statistics. *//*from ww w . j a v a 2 s . c om*/ private void gatherStatistics() { while (current < line.length() && (Character.isLetter(line.charAt(current)) || line.charAt(current) == '\'')) { char ch = line.charAt(current); log.trace("@" + current + ":" + ch); if (Character.isUpperCase(ch)) { upperCount++; /* * We are interested in upper case I's only if they are not at the first * character position. Thus we will ignore words such as "I'll" and * words that start sentences. */ if (current != first && ch == UPPER_I) { ICount++; } } else if (ch == '\'') { apostropheCount++; } else { lowerCount++; if (ch == LOWER_l) { lCount++; } } current++; } }
From source file:org.gradle.model.internal.manage.schema.extract.StructStrategy.java
public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext, final ModelSchemaCache cache) { ModelType<R> type = extractionContext.getType(); Class<? super R> clazz = type.getRawClass(); if (clazz.isAnnotationPresent(Managed.class)) { validateType(type, extractionContext); Iterable<Method> methods = Arrays.asList(clazz.getMethods()); if (!clazz.isInterface()) { methods = filterIgnoredMethods(methods); }/* w ww . j a va 2 s.com*/ ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods, new Function<Method, String>() { public String apply(Method method) { return method.getName(); } }); ensureNoOverloadedMethods(extractionContext, methodsByName); List<ModelProperty<?>> properties = Lists.newLinkedList(); List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length); ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering(); for (String methodName : methodsByName.keySet()) { if (methodName.startsWith("get") && !methodName.equals("get")) { ImmutableList<Method> getterMethods = methodsByName.get(methodName); // The overload check earlier verified that all methods for are equivalent for our purposes // So, taking the first one with the most specialized return type is fine. Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods); boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers()); if (sampleMethod.getParameterTypes().length != 0) { throw invalidMethod(extractionContext, "getter methods cannot take parameters", sampleMethod); } Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { throw invalidMethod(extractionContext, "the 4th character of the getter method name must be an uppercase character", sampleMethod); } ModelType<?> returnType = ModelType.returnType(sampleMethod); String propertyNameCapitalized = methodName.substring(3); String propertyName = StringUtils.uncapitalize(propertyNameCapitalized); String setterName = "set" + propertyNameCapitalized; ImmutableList<Method> setterMethods = methodsByName.get(setterName); boolean isWritable = !setterMethods.isEmpty(); if (isWritable) { Method setter = setterMethods.get(0); if (!abstractGetter) { throw invalidMethod(extractionContext, "setters are not allowed for non-abstract getters", setter); } validateSetter(extractionContext, returnType, setter); handled.addAll(setterMethods); } if (abstractGetter) { ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() { public ModelType<?> apply(Method input) { return ModelType.of(input.getDeclaringClass()); } })); boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() { public boolean apply(Method input) { return input.getAnnotation(Unmanaged.class) != null; } }); properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses, unmanaged)); } handled.addAll(getterMethods); } } Iterable<Method> notHandled = Iterables.filter(methodsByName.values(), Predicates.not(Predicates.in(handled))); // TODO - should call out valid getters without setters if (!Iterables.isEmpty(notHandled)) { throw invalidMethods(extractionContext, "only paired getter/setter methods are supported", notHandled); } Class<R> concreteClass = type.getConcreteClass(); Class<? extends R> implClass = classGenerator.generate(concreteClass); final ModelStructSchema<R> schema = ModelSchema.struct(type, properties, implClass); extractionContext.addValidator(new Action<ModelSchemaExtractionContext<R>>() { @Override public void execute(ModelSchemaExtractionContext<R> validatorModelSchemaExtractionContext) { ensureCanBeInstantiated(extractionContext, schema); } }); Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties, new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() { public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) { return toPropertyExtractionContext(extractionContext, property, cache); } }); return new ModelSchemaExtractionResult<R>(schema, propertyDependencies); } else { return null; } }
From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.OrcaRunner.java
private static String formatId(String id) { if (id.length() == 0) { return id; }/* w w w. j a v a2 s .co m*/ id = capitalize(id); List<Integer> breaks = new ArrayList<>(); char[] arr = id.toCharArray(); for (int i = 0; i < arr.length; i++) { char c = arr[i]; if (Character.isUpperCase(c)) { breaks.add(i); } } breaks.add(id.length()); if (breaks.size() == 1) { return id; } List<String> words = new ArrayList<>(); int last = breaks.remove(0); while (breaks.size() > 0) { int curr = breaks.remove(0); String word = id.substring(last, curr); if (last != 0) { word = unCapitalize(word); } words.add(word); last = curr; } return words.stream().reduce("", (a, b) -> a + " " + b).trim(); }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * * @param input/*from ww w .j ava 2 s. c om*/ * @return * @example * * BankAccount => BANK_ACCOUNT Bank_Account => BANK_ACCOUNT */ public static String toConstant(String input) { String constant = EMPTY; Character lastChar = null; for (Character curChar : input.toCharArray()) { if (lastChar == null) { // First character lastChar = Character.toUpperCase(curChar); constant = constant + lastChar; } else { if (Character.isLowerCase(lastChar) && (Character.isUpperCase(curChar) || Character.isDigit(curChar))) { constant = constant + '_' + curChar; } else { constant = constant + Character.toUpperCase(curChar); } lastChar = curChar; } } return constant; }
From source file:io.uengine.util.StringUtils.java
/** * ?? escape ./*from w ww . j a va2 s. c o m*/ * * @param string Escape ? * @return escape ? */ public static String escape(String string) { int i; char j; StringBuilder builder = new StringBuilder(); builder.ensureCapacity(string.length() * 6); for (i = 0; i < string.length(); i++) { j = string.charAt(i); if (Character.isDigit(j) || Character.isLowerCase(j) || Character.isUpperCase(j)) builder.append(j); else if (j < 256) { builder.append("%"); if (j < 16) builder.append("0"); builder.append(Integer.toString(j, 16)); } else { builder.append("%u"); builder.append(Integer.toString(j, 16)); } } return builder.toString(); }
From source file:com.stumbleupon.hbaseadmin.JMXQuery.java
protected String doSubCommand(MBeanServerConnection mbsc, ObjectInstance instance, String subCommand) throws Exception { final MBeanAttributeInfo[] attributeInfo = mbsc.getMBeanInfo(instance.getObjectName()).getAttributes(); final MBeanOperationInfo[] operationInfo = mbsc.getMBeanInfo(instance.getObjectName()).getOperations(); Object result = null;//ww w . ja v a 2 s.com if (Character.isUpperCase(subCommand.charAt(0))) { if ((!(isFeatureInfo(attributeInfo, subCommand))) && (isFeatureInfo(operationInfo, subCommand))) { result = doBeanOperation(mbsc, instance, subCommand, operationInfo); } else { result = doAttributeOperation(mbsc, instance, subCommand, attributeInfo); } } else if ((!(isFeatureInfo(operationInfo, subCommand))) && (isFeatureInfo(attributeInfo, subCommand))) { result = doAttributeOperation(mbsc, instance, subCommand, attributeInfo); } else { result = doBeanOperation(mbsc, instance, subCommand, operationInfo); } if (result instanceof CompositeData) { result = recurseCompositeData(new StringBuffer("\n"), "", "", (CompositeData) result); } else if (result instanceof TabularData) { result = recurseTabularData(new StringBuffer("\n"), "", "", (TabularData) result); } else if (result instanceof String[]) { String[] strs = (String[]) (String[]) result; StringBuffer buffer = new StringBuffer("\n"); for (int i = 0; i < strs.length; ++i) { buffer.append(strs[i]); buffer.append("\n"); } result = buffer; } return result.toString(); }