List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:CharUtils.java
/** * True if all letters in a string are uppercase. * // ww w .ja va 2 s . c o m * @param s * String to check for upper case letters. * * @return true if all letters are upper case. * * <p> * Note: non-letters are ignored. The result is false if there are * no letters in the string. * </p> */ public static boolean allLettersCapital(String s) { boolean result = false; String ts = s.trim(); int l = ts.length(); for (int i = 0; i < l; i++) { char ch = ts.charAt(i); if (Character.isLetter(ch)) { if (!Character.isUpperCase(ch)) { result = false; break; } else { result = true; } } } return result; }
From source file:eu.crisis_economics.abm.model.ModelUtils.java
/** * Convert the basename {@code B} of a method to a full setter-type method name.<br><br> * This method is equivalent to the following: * //ww w.jav a2 s . co m * <ul> * <li> If {@code B} has the format {@code setX} where {@code X} * is a {@link String} beginning with an uppercase letter, return {@code B}; * <li> Otherwise return {@code "set" + capitalize(B)}. * </ul> * * @param baseName * The {@link String} {@code B} above. This argument should be * non-<code>null</code> and nonempty. */ public static String asSetter(final String baseName) { if (Preconditions.checkNotNull(baseName).isEmpty()) throw new IllegalArgumentException(); if (baseName.length() > 3 && baseName.startsWith("set") && Character.isUpperCase(baseName.charAt(3))) return baseName; else return "set" + WordUtils.capitalize(baseName); }
From source file:org.opensextant.util.TextUtils.java
/** * Measure character count, upper, lower, non-Character, whitespace * /*from ww w . j a v a 2s .c o m*/ * @param text * text * @return int array with counts. */ public static int[] measureCase(String text) { if (text == null) { return null; } int u = 0, l = 0, ch = 0, nonCh = 0, ws = 0; int[] counts = new int[5]; for (char c : text.toCharArray()) { if (Character.isLetter(c)) { ++ch; if (Character.isUpperCase(c)) { ++u; } else if (Character.isLowerCase(c)) { ++l; } } else if (Character.isWhitespace(c)) { ++ws; } else { ++nonCh; // Other content? } } counts[0] = ch; counts[1] = u; counts[2] = l; counts[3] = nonCh; counts[4] = ws; return counts; }
From source file:CharUtils.java
/** * True if all characters in a string are uppercase. * /* w w w. j av a 2s . com*/ * @param s * String to check for upper case letters. * * @return true if all characters are upper case. * * <p> * All characters are checked, letters and non-letters alike. * </p> */ public static boolean isUpperCase(String s) { boolean result = true; String ts = s.trim(); for (int i = 0; i < ts.length(); i++) { if (!Character.isUpperCase(ts.charAt(i))) { result = false; break; } } return result; }
From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java
/** * Types the given string without checking for event confirmation. Note that * that only alphanumeric characters can be typed using this method. * // w w w . j a v a 2 s.com * @param text The text to type. */ public void nativeTypeString(String text) { // Verify that the string consists of only valid characters // (any change in verification will probably require a change in // how the text is processed) if (MatchUtil.getInstance().match(text, VALID_INPUT, MatchUtil.MATCHES_REGEXP)) { boolean isCapsLockOn = false; try { isCapsLockOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); } catch (UnsupportedOperationException uoe) { // Do nothing. // Querying the status of the Caps Lock key is not possible on // certain platforms (ex. Linux). In this case, we will just // assume that Caps Lock is not active. } for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); boolean holdShift = Character.isUpperCase(c) ^ isCapsLockOn; StringBuffer sb = new StringBuffer(); if (holdShift) { sb.append("shift "); //$NON-NLS-1$ } sb.append(Character.toUpperCase(c)); type(sb.toString(), null, null, null); } } else { throw new StepExecutionException("Invalid input string (only ASCII alphanumeric strings are allowed)", //$NON-NLS-1$ EventFactory.createActionError(TestErrorEvent.INVALID_PARAM_VALUE)); } }
From source file:org.apache.openjpa.lib.identifier.IdentifierUtilImpl.java
public String removeHungarianNotation(IdentifierRule rule, String name) { boolean delimited = isDelimited(rule, name); if (delimited) { name = removeDelimiters(rule, name); }/* w ww . j a va2 s . c om*/ char[] chname = name.toCharArray(); int newStart = 0; for (int i = 0; i < chname.length; i++) { if (Character.isUpperCase(chname[i])) { newStart = i; break; } } name = name.substring(newStart); if (delimited) { name = delimit(rule, name); } return name; }
From source file:org.languagetool.tagging.de.GermanTagger.java
private List<AnalyzedToken> getSubstantivatedForms(String word, List<String> sentenceTokens, int pos) { if (word.endsWith("er")) { List<TaggedWord> lowerCaseTags = getWordTagger().tag(word.toLowerCase()); // do not add tag words whose lower case variant is an adverb (e.g, "Frher") to avoid false negatives for DE_CASE if (lowerCaseTags.stream().anyMatch(t -> t.getPosTag().startsWith("ADV"))) { return Collections.emptyList(); }//from w w w. j av a 2 s.c o m int idx = sentenceTokens.indexOf(word); // is followed by an uppercase word? If 'yes', the word is probably not substantivated while (++idx < sentenceTokens.size()) { String nextWord = sentenceTokens.get(idx); if (StringUtils.isWhitespace(nextWord)) { continue; } if (nextWord.length() > 0 && (Character.isUpperCase(nextWord.charAt(0)) || "als".equals(nextWord))) { return Collections.emptyList(); } break; } String femaleForm = word.substring(0, word.length() - 1); List<TaggedWord> taggedFemaleForm = getWordTagger().tag(femaleForm); boolean isSubstantivatedForm = taggedFemaleForm.stream() .anyMatch(t -> t.getPosTag().equals("SUB:NOM:SIN:FEM:ADJ")); if (isSubstantivatedForm) { List<AnalyzedToken> list = new ArrayList<>(); list.add(new AnalyzedToken(word, "SUB:NOM:SIN:MAS:ADJ", word)); list.add(new AnalyzedToken(word, "SUB:GEN:PLU:MAS:ADJ", word)); return list; } } return Collections.emptyList(); }
From source file:eu.crisis_economics.abm.model.ModelUtils.java
/** * Convert the basename {@code B} of a method to a full getter-type method name.<br><br> * This method is equivalent to the following: * /* www.ja v a2 s . co m*/ * <ul> * <li> If {@code B} has the format {@code getX} where {@code X} * is a {@link String} beginning with an uppercase letter, return {@code B}; * <li> Otherwise return {@code "get" + capitalize(B)}. * </ul> * * @param baseName * The {@link String} {@code B} above. This argument should be * non-<code>null</code> and nonempty. */ public static String asGetter(final String baseName) { if (Preconditions.checkNotNull(baseName).isEmpty()) throw new IllegalArgumentException(); if (baseName.length() > 3 && baseName.startsWith("get") && Character.isUpperCase(baseName.charAt(3))) return baseName; else return "get" + WordUtils.capitalize(baseName); }
From source file:org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.java
/** * Restricts consecutive capital cased string as a rule in camel case. * * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case * @return string without consecutive capital case *//*w ww.j ava 2 s . c om*/ private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) { for (int k = 0; k < consecCapitalCaseRemover.length(); k++) { if (k + 1 < consecCapitalCaseRemover.length()) { if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) { if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) { consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1) + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase() + consecCapitalCaseRemover.substring(k + 2); } } } } return consecCapitalCaseRemover; }
From source file:de.codesourcery.springmass.springmass.SimulationParamsBuilder.java
private String extractParameterName(Method m) { Method methodWithLabel = null; if (isParameterGetter(m)) { // look for @Label on corresponding setter if (m.getName().startsWith("get") || m.getName().startsWith("is")) { final int charsToRemove = m.getName().startsWith("get") ? 3 : 2; final String setterName = "set" + m.getName().substring(charsToRemove); try { methodWithLabel = m.getDeclaringClass().getMethod(setterName, new Class<?>[] { m.getReturnType() }); } catch (NoSuchMethodException | SecurityException e) { /* ok */ } }/* w w w .java 2s .c om*/ } else { methodWithLabel = m; } if (methodWithLabel != null) { final Label label = methodWithLabel.getAnnotation(Label.class); if (label != null && !StringUtils.isBlank(label.value())) { return label.value(); } } String name; if (m.getName().startsWith("set") || m.getName().startsWith("get")) { name = m.getName().substring(3); } else if (m.getName().startsWith("is")) { name = m.getName().substring(2); } else { throw new IllegalArgumentException("Invalid method name: " + m); } name = Character.toUpperCase(name.charAt(0)) + name.substring(1); final List<String> split = new ArrayList<>(); final StringBuffer buffer = new StringBuffer(); for (char s : name.toCharArray()) { if (Character.isUpperCase(s)) { if (buffer.length() > 1) { split.add(buffer.toString()); buffer.setLength(0); buffer.append(Character.toLowerCase(s)); continue; } } if (split.isEmpty()) { buffer.append(s); } else { buffer.append(Character.toLowerCase(s)); } } if (buffer.length() > 0) { split.add(buffer.toString()); } return StringUtils.join(split, " "); }