List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * * @param input/* w w w . j a v a 2s .co m*/ * @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:com.aiblockchain.api.StringUtils.java
/** * Returns whether the given string is a valid Java class name. * * @param string the given string/*from w w w .j a v a 2 s. c o m*/ * * @return whether the given string is a valid Java class name */ public static boolean isJavaClassName(final String string) { if (string == null || string.isEmpty() || !Character.isJavaIdentifierStart(string.charAt(0)) || string.contains("..")) { return false; } for (int i = 1; i < string.length(); i++) { final char ch = string.charAt(i); if (!Character.isJavaIdentifierPart(ch) && ch != '.') { return false; } } final String[] lastNameParts = string.split("\\."); final String lastNamePart = lastNameParts[lastNameParts.length - 1]; return Character.isUpperCase(lastNamePart.charAt(0)); }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext, ModelSchemaStore store, final ModelSchemaCache cache) { ModelType<R> type = extractionContext.getType(); Class<? super R> clazz = type.getRawClass(); if (isTarget(type)) { validateType(type, extractionContext); Iterable<Method> methods = Arrays.asList(clazz.getMethods()); if (!clazz.isInterface()) { methods = filterIgnoredMethods(methods); }/*from w ww . jav a2 s. c om*/ 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(); final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass); 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.qpark.eip.core.spring.security.EipRoleVoter.java
/** * Get the name of the service out of the channel name. * * @param channelName/* w w w . j a va 2 s.c o m*/ * the channel name. * @return the service name. */ public static String getServiceName(final String channelName) { StringBuffer service = new StringBuffer(); if (channelName.startsWith("eip")) { service.append(Character.toLowerCase(channelName.charAt("eip".length()))); char ch; int l = channelName.length(); for (int i = "eip".length() + 1; i < l; i++) { ch = channelName.charAt(i); if (Character.isUpperCase(ch)) { break; } else { service.append(ch); } } } return service.toString(); }
From source file:org.fhcrc.cpl.toolbox.datastructure.BoundMap.java
private String convertToPropertyName(String name) { if (1 == name.length()) return name.toLowerCase(); if (Character.isUpperCase(name.charAt(0)) && !Character.isUpperCase(name.charAt(1))) return Character.toLowerCase(name.charAt(0)) + name.substring(1); else/* w w w.jav a2s .c o m*/ return name; }
From source file:com.prowidesoftware.swift.model.BIC.java
/** * Validates a BIC structure./*from www . j a v a 2s . c o m*/ * It only checks that length is 8 or 11 and that the country code is valid. * This method does not validate against any BIC directory. * * @return <code>true</code> if the BIC is found to be valid and <code>false</code> in other case * @throws IllegalStateException if BIC is <code>null</code> */ public boolean isValid() { if (this.bic8 == null) { this.invalidCause = "BIC is null"; return false; } if (this.bic8.length() != 8) { this.invalidCause = "Expected 8 characters for the institution and country code and found " + this.bic8.length() + " in " + this.bic8; return false; } if (this.branch != null && this.branch.length() != 3) { this.invalidCause = "Expected 3 characters for branch and found " + this.branch.length() + " in " + this.branch; return false; } final String country = this.bic8.substring(4, 6); if (!ISOCountries.getInstance().isValidCode(country.toUpperCase())) { this.invalidCause = "Invalid country code " + country; return false; } final String b11 = getBic11(); for (int i = 0; i < b11.length(); i++) { final char c = b11.charAt(i); final boolean digit = Character.isDigit(c); final boolean uppercase = Character.isUpperCase(c); if (!digit && !uppercase) { this.invalidCause = "BIC characters must be alphanumeric uppercase"; return false; } } return true; }
From source file:org.codehaus.griffon.commons.ClassPropertyFetcher.java
private void init() { FieldCallback fieldCallback = new ReflectionUtils.FieldCallback() { public void doWith(Field field) { if (field.isSynthetic()) return; 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)); }/*from www .jav a 2 s .c o m*/ } } }; 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: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 w w w . j ava2 s .c om*/ * 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.data.metadata.impl.MetadataCommonBase.java
/** * Parses the label from the property name. * * @param propertyName the full property name including separators *//*from w w w . ja va 2 s .c o m*/ protected String getLabelFromPropertyName(String propertyName) { // We only want to include the component after the last property separator if (propertyName.contains(".")) { propertyName = StringUtils.substringAfterLast(propertyName, "."); } StringBuilder label = new StringBuilder(propertyName); // upper case the 1st letter label.replace(0, 1, label.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < label.length(); i++) { if (Character.isUpperCase(label.charAt(i)) || Character.isDigit(label.charAt(i))) { label.insert(i, ' '); i++; } } return label.toString().trim(); }
From source file:com.clust4j.algo.ParallelChunkingTask.java
public String formatName(String str) { StringBuilder sb = new StringBuilder(); boolean hyphen = false; // have we hit the hyphen yet? for (char c : str.toCharArray()) { if (hyphen || Character.isUpperCase(c)) sb.append(c);//from ww w . j a v a2 s . c o m else if ('-' == c) { hyphen = true; sb.append(c); } } return sb.toString(); }