List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.plasma.text.lang3gl.java.DefaultFactory.java
protected String firstToUpperCase(String name) { if (!Character.isUpperCase(name.charAt(0))) { return name.substring(0, 1).toUpperCase() + name.substring(1); }/*from w w w . jav a2 s . c o m*/ return name; }
From source file:org.lockss.util.NumberUtil.java
/** * Construct an alphabetical (base-26) sequence by incrementing the first * string alphabetically until it reaches the second string. The start string * is incremented by the given delta; if the delta does not divide into the * Levenstein distance between the start and end strings, an exception is * thrown. The strings must also be the same length. * <p>/* w w w . j av a 2 s . c o m*/ * The string is lower cased before the increment is applied, and then each * character position that was upper case in the original string is upper * cased in the resulting string. It is assumed that the two strings are * capitalised in the same pattern. An exception will be thrown if any * character is outside of a-z after lower casing. * * @param start an alphabetical string (case-insensitive) * @param end an alphabetical string (case-insensitive) * @param delta the increment between strings in the sequence; can be negative * @return a list of strings representing a sequence from <tt>start</tt> to <tt>end</tt> * @throws IllegalArgumentException if the delta does not divide into the gap or the strings are different lengths */ public static List<String> constructAlphabeticSequence(final String start, final String end, int delta) throws IllegalArgumentException { // Ensure the delta is positive if (delta == 0) throw new IllegalArgumentException("Delta cannot be 0."); // If the strings are equal, the sequence will be the single string if (start.equals(end)) return new ArrayList<String>() { { add(start); } }; // Check the string lengths are the same if (start.length() != end.length()) throw new IllegalArgumentException( String.format("Start and end strings are different lengths: %s %s.", start, end)); // Find the integer distance int distance = Math.abs(fromBase26(start) - fromBase26(end)); //int distance = StringUtils.getLevenshteinDistance(start, end); // Check the delta divides into the gap if (distance % delta != 0) { throw new IllegalArgumentException(String.format( "The distance %s between start and end must be " + "divisible by delta %s.", distance, delta)); } // Track the case of each character, so we can reset them before returning BitSet cases = new BitSet(start.length()); for (int i = 0; i < start.length(); i++) { cases.set(i, Character.isUpperCase(start.charAt(i))); } // Increment alphabetically List<String> seq = new ArrayList<String>(); int[] nums = constructSequence(fromBase26(start), fromBase26(end), delta); for (int i = 0; i < nums.length; i++) { String s = toBase26(nums[i]); // Pad the string to the correct length with 'a' s = StringUtils.leftPad(s, start.length(), 'a'); // Re-case the chars char[] carr = s.toCharArray(); for (int pos = 0; pos < cases.length(); pos++) { if (cases.get(pos)) carr[pos] = Character.toUpperCase(carr[pos]); } seq.add(new String(carr)); } return seq; }
From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java
private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module) throws IllegalAccessException { AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory() .getBeanDefinition(beanName); String beanClassName = beanDefinition.getBeanClassName(); String controllerSuffix = null; for (String suffix : MvcConstants.CONTROLLER_SUFFIXES) { if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) { if (suffix.length() == 1 && Character .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) { continue; }//from w w w.ja v a 2 s .co m controllerSuffix = suffix; break; } } if (controllerSuffix == null) { if (beanDefinition.hasBeanClass()) { Class<?> beanClass = beanDefinition.getBeanClass(); if (beanClass.isAnnotationPresent(Path.class)) { throw new IllegalArgumentException( "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, " + "is it a Resource/Controller? wrong spelling? : " + beanClassName); } } // ?l?r?uer?or??? if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor") || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) { // ?throw??? logger.error("", new IllegalArgumentException( "invalid class name end wrong spelling? : " + beanClassName)); } return false; } String[] controllerPaths = null; if (!beanDefinition.hasBeanClass()) { try { beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e); } } final Class<?> clazz = beanDefinition.getBeanClass(); final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz), controllerSuffix); Path reqMappingAnnotation = clazz.getAnnotation(Path.class); if (reqMappingAnnotation != null) { controllerPaths = reqMappingAnnotation.value(); } if (controllerPaths != null) { // controllerPaths.length==0path?controller for (int i = 0; i < controllerPaths.length; i++) { if ("#".equals(controllerPaths[i])) { controllerPaths[i] = "/" + controllerName; } else if (controllerPaths[i].equals("/")) { controllerPaths[i] = ""; } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') { controllerPaths[i] = "/" + controllerPaths[i]; } if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) { if (controllerPaths[i].endsWith("//")) { throw new IllegalArgumentException("invalid path '" + controllerPaths[i] + "' for controller " + beanClassName + ": don't end with more than one '/'"); } controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1); } } } else { // TODO: ?0.91.0?201007?? if (controllerName.equals("index") || controllerName.equals("home") || controllerName.equals("welcome")) { // ??IndexController/HomeController/WelcomeController@Path("") throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName()); } else { controllerPaths = new String[] { "/" + controllerName }; } } // Controller??Context?? // Context??? Object controller = context.getBean(beanName); module.addController(// controllerPaths, clazz, controllerName, controller); if (Proxy.isProxyClass(controller.getClass())) { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': add controller " + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName()); } } else { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() // + "': add controller " + Arrays.toString(controllerPaths) + "= " + controller.getClass().getName()); } } return true; }
From source file:org.opendatakit.common.utils.WebUtils.java
/** * Useful static method for constructing a UPPER_CASE persistence layer name * from a camelCase name. This inserts an underscore before a leading capital * letter and toUpper()s the resulting string. The transformation maps * multiple camelCase names to the same UPPER_CASE name so it is not * reversible.//from ww w . jav a2s .c o m * <ul> * <li>thisURL => THIS_URL</li> * <li>thisUrl => THIS_URL</li> * <li>myFirstObject => MY_FIRST_OBJECT</li> * </ul> * * @param name * @return */ public static final String unCamelCase(String name) { StringBuilder b = new StringBuilder(); boolean lastCap = true; for (int i = 0; i < name.length(); ++i) { char ch = name.charAt(i); if (Character.isUpperCase(ch)) { if (!lastCap) { b.append('_'); } lastCap = true; b.append(ch); } else if (Character.isLetterOrDigit(ch)) { lastCap = false; b.append(Character.toUpperCase(ch)); } else { throw new IllegalArgumentException("Argument is not a valid camelCase name: " + name); } } return b.toString(); }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String toWords(CharSequence str) { StringBuilder res = new StringBuilder(str.length()); for (int i = 0; i < str.length(); i++) { Character ch = str.charAt(i); if (Character.isUpperCase(ch)) { res.append(' ').append(ch); } else {//from w ww . ja v a 2s . c o m res.append(ch); } } char c = Character.toUpperCase(res.charAt(0)); res.replace(0, 1, new String(new char[] { c })); return res.toString(); }
From source file:com.zenesis.qx.remote.ProxyTypeImpl.java
/** * Constructor, used for defining interfaces which are to be proxied * @param className//from w w w. j a v a2 s.c o m * @param methods */ public ProxyTypeImpl(ProxyType superType, Class clazz, Set<ProxyType> interfaces) { super(); if (interfaces == null) interfaces = Collections.EMPTY_SET; this.superType = superType; this.interfaces = interfaces; this.clazz = clazz; MethodsCompiler methodsCompiler = new MethodsCompiler(); // Get a complete list of methods from the interfaces that the new class has to // implement; we include methods marked as DoNotProxy so that we can check for // conflicting instructions if (!clazz.isInterface()) { // Get a full list of the interfaces which our class has to implement HashSet<ProxyType> allInterfaces = new HashSet<ProxyType>(); getAllInterfaces(allInterfaces, interfaces); for (ProxyType ifcType : allInterfaces) { try { methodsCompiler.addMethods(Class.forName(ifcType.getClassName()), true); } catch (ClassNotFoundException e) { throw new IllegalStateException("Cannot find class " + ifcType.getClassName()); } } } boolean defaultProxy = false; if (clazz.isInterface()) defaultProxy = true; else { for (Class tmp = clazz; tmp != null; tmp = tmp.getSuperclass()) { if (factoryMethod == null) { for (Method method : tmp.getDeclaredMethods()) { if (method.isAnnotationPresent(FactoryMethod.class)) { if (!Modifier.isStatic(method.getModifiers())) throw new IllegalStateException("Cannot use method " + method + " as FactoryMethod because it is not static"); factoryMethod = method; method.setAccessible(true); break; } } } if (tmp.isAnnotationPresent(AlwaysProxy.class)) { defaultProxy = true; break; } else if (tmp.isAnnotationPresent(ExplicitProxyOnly.class)) { break; } } } // If the class does not have any proxied interfaces or the class is marked with // the AlwaysProxy annotation, then we take methods from the class definition methodsCompiler.addMethods(clazz, defaultProxy); methodsCompiler.checkValid(); methodsCompiler.removeSuperTypeMethods(); // Load properties HashMap<String, ProxyEvent> events = new HashMap<String, ProxyEvent>(); HashMap<String, ProxyProperty> properties = new HashMap<String, ProxyProperty>(); Properties annoProperties = (Properties) clazz.getAnnotation(Properties.class); if (annoProperties != null) { for (Property anno : annoProperties.value()) { ProxyProperty property = new ProxyPropertyImpl(clazz, anno.value(), anno, annoProperties); properties.put(property.getName(), property); ProxyEvent event = property.getEvent(); if (event != null) events.put(event.getName(), event); } } for (Field field : clazz.getDeclaredFields()) { Property anno = field.getAnnotation(Property.class); if (anno != null) { ProxyProperty property = new ProxyPropertyImpl(clazz, anno.value().length() > 0 ? anno.value() : field.getName(), anno, annoProperties); properties.put(property.getName(), property); ProxyEvent event = property.getEvent(); if (event != null) events.put(event.getName(), event); } } for (Method method : clazz.getDeclaredMethods()) { String name = method.getName(); if (name.length() < 4 || !name.startsWith("get") || !Character.isUpperCase(name.charAt(3))) continue; Property anno = method.getAnnotation(Property.class); if (anno == null) continue; name = Character.toLowerCase(name.charAt(3)) + name.substring(4); if (properties.containsKey(name)) continue; ProxyProperty property = new ProxyPropertyImpl(clazz, anno.value().length() > 0 ? anno.value() : name, anno, annoProperties); properties.put(property.getName(), property); ProxyEvent event = property.getEvent(); if (event != null) events.put(event.getName(), event); } // Classes need to have all inherited properties added if (!clazz.isInterface()) { for (ProxyType ifc : interfaces) addProperties((ProxyTypeImpl) ifc, properties); } // Remove property accessors for (ProxyProperty prop : properties.values()) methodsCompiler.removePropertyAccessors((ProxyPropertyImpl) prop); // Load events if (clazz.isAnnotationPresent(Events.class)) { Events annoEvents = (Events) clazz.getAnnotation(Events.class); for (Event annoEvent : annoEvents.value()) { if (!events.containsKey(annoEvent.value())) events.put(annoEvent.value(), new ProxyEvent(annoEvent)); } } // Classes need to have all inherited events added if (!clazz.isInterface()) { for (ProxyType type : interfaces) addEvents((ProxyTypeImpl) type, events); } // Save this.properties = properties.isEmpty() ? null : properties; this.events = events.isEmpty() ? null : events; this.methods = methodsCompiler.toArray(); }
From source file:com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck.java
/** * Capitalizes a given property name the way we expect to see it in * a setter name./*w w w .j a v a 2s . c o m*/ * @param name a property name * @return capitalized property name */ private static String capitalize(final String name) { String setterName = name; // we should not capitalize the first character if the second // one is a capital one, since according to JavBeans spec // setXYzz() is a setter for XYzz property, not for xYzz one. if (name != null && name.length() > 0 && (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) { setterName = name.substring(0, 1).toUpperCase() + name.substring(1); } return setterName; }
From source file:org.languagetool.dev.bigdata.ProhibitedCompoundRuleEvaluator.java
private List<Map.Entry<Sentence, Map.Entry<Integer, Integer>>> getSentencesFromSource(List<String> inputs, String token, int maxSentences, SentenceSource sentenceSource) { List<Map.Entry<Sentence, Map.Entry<Integer, Integer>>> sentences = new ArrayList<>(); Pattern pattern = Pattern.compile("(?iu)\\b(" + token.toLowerCase() + ")\\p{Alpha}+\\b|\\b\\p{Alpha}+(" + token.toLowerCase() + ")\\b"); while (sentenceSource.hasNext()) { Sentence sentence = sentenceSource.next(); Matcher matcher = pattern.matcher(sentence.getText()); if (matcher.find() && Character.isUpperCase(matcher.group().charAt(0))) { Map.Entry<Integer, Integer> range = new AbstractMap.SimpleEntry<>( // -1 if group did not match anything -> max gets result from group that matched Math.max(matcher.start(1), matcher.start(2)), Math.max(matcher.end(1), matcher.end(2))); sentences.add(new AbstractMap.SimpleEntry<>(sentence, range)); //if (sentences.size() % 250 == 0) { // println("Loaded sentence " + sentences.size() + " with '" + token + "' from " + inputs); //}// ww w . j a va2 s.c o m if (sentences.size() >= maxSentences) { break; } } } println("Loaded " + sentences.size() + " sentences with '" + token + "' from " + inputs); return sentences; }
From source file:org.plasma.text.lang3gl.java.DefaultFactory.java
protected String toConstantName(String name) { name = name.trim();//from w w w. ja va 2 s. c o m StringBuilder buf = new StringBuilder(); char[] array = name.toCharArray(); for (int i = 0; i < array.length; i++) { String lit = reservedJavaCharToLiteralMap.get(Character.valueOf(array[i])); if (lit != null) { buf.append(lit.toUpperCase()); continue; } if (i > 0) { if (Character.isLetter(array[i]) && Character.isUpperCase(array[i])) { if (!Character.isUpperCase(array[i - 1])) buf.append("_"); } } if (Character.isLetterOrDigit(array[i])) { buf.append(Character.toUpperCase(array[i])); } else buf.append("_"); } return buf.toString(); }
From source file:de.pangaea.fixo3.xml.ProcessXmlFiles.java
private String toUri(String s) { s = s.replaceAll(" ", ""); s = s.replaceAll("_", ""); s = s.replaceAll("-", ""); s = s.replaceAll("/", ""); s = s.replaceAll("&", ""); s = s.replaceAll("\\(", ""); s = s.replaceAll("\\)", ""); s = s.replaceAll("", ""); s = s.replaceAll("'", ""); s = s.replaceAll("\\+", ""); if (!Character.isUpperCase(s.codePointAt(0))) { s = s.substring(0, 1).toUpperCase() + s.substring(1); }/* w w w . j ava 2 s. c o m*/ return EYP.ns.toString() + s; }