List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.agiso.core.i18n.util.I18nUtils.java
private static String findGetterFieldName(Method m) { String name = m.getName();//from w w w.j av a 2s . 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:edu.auburn.ppl.cyclecolumbus.TripUploader.java
private String capitalize(String s) { if (s == null || s.length() == 0) { return ""; }/*from www .ja va 2s . c o m*/ char first = s.charAt(0); if (Character.isUpperCase(first)) { return s; } else { return Character.toUpperCase(first) + s.substring(1); } }
From source file:net.sf.jasperreports.engine.design.JRJdtCompiler.java
/** * /*from ww w. j a v a 2s .com*/ */ protected INameEnvironment getNameEnvironment(final JRCompilationUnit[] units) { final INameEnvironment env = new INameEnvironment() { @Override public NameEnvironmentAnswer findType(char[][] compoundTypeName) { StringBuilder result = new StringBuilder(); String sep = ""; for (int i = 0; i < compoundTypeName.length; i++) { result.append(sep); result.append(compoundTypeName[i]); sep = "."; } return findType(result.toString()); } @Override public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { StringBuilder result = new StringBuilder(); String sep = ""; for (int i = 0; i < packageName.length; i++) { result.append(sep); result.append(packageName[i]); sep = "."; } result.append(sep); result.append(typeName); return findType(result.toString()); } private int getClassIndex(String className) { int classIdx; for (classIdx = 0; classIdx < units.length; ++classIdx) { if (className.equals(units[classIdx].getName())) { break; } } if (classIdx >= units.length) { classIdx = -1; } return classIdx; } private NameEnvironmentAnswer findType(String className) { try { int classIdx = getClassIndex(className); if (classIdx >= 0) { ICompilationUnit compilationUnit = new CompilationUnit(units[classIdx].getSourceCode(), className); if (is2ArgsConstr) { return (NameEnvironmentAnswer) constrNameEnvAnsCompUnit2Args .newInstance(new Object[] { compilationUnit, null }); } return (NameEnvironmentAnswer) constrNameEnvAnsCompUnit .newInstance(new Object[] { compilationUnit }); } String resourceName = className.replace('.', '/') + ".class"; InputStream is = getResource(resourceName); if (is != null) { try { byte[] classBytes = JRLoader.loadBytes(is); char[] fileName = className.toCharArray(); ClassFileReader classFileReader = new ClassFileReader(classBytes, fileName, true); if (is2ArgsConstr) { return (NameEnvironmentAnswer) constrNameEnvAnsBin2Args .newInstance(new Object[] { classFileReader, null }); } return (NameEnvironmentAnswer) constrNameEnvAnsBin .newInstance(new Object[] { classFileReader }); } finally { try { is.close(); } catch (IOException e) { // ignore } } } } catch (JRException e) { log.error("Compilation error", e); } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException exc) { log.error("Compilation error", exc); } catch (InvocationTargetException e) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_NAME_ENVIRONMENT_ANSWER_INSTANCE_ERROR, (Object[]) null, e); } catch (IllegalArgumentException e) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_NAME_ENVIRONMENT_ANSWER_INSTANCE_ERROR, (Object[]) null, e); } catch (InstantiationException e) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_NAME_ENVIRONMENT_ANSWER_INSTANCE_ERROR, (Object[]) null, e); } catch (IllegalAccessException e) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_NAME_ENVIRONMENT_ANSWER_INSTANCE_ERROR, (Object[]) null, e); } return null; } private boolean isPackage(String result) { int classIdx = getClassIndex(result); if (classIdx >= 0) { return false; } String resourceName = result.replace('.', '/') + ".class"; boolean isPackage = true; InputStream is = getResource(resourceName); if (is != null)// cannot just test for null; need to read from "is" to avoid bug { // with sun.plugin.cache.EmptyInputStream on JRE 1.5 plugin try // http://sourceforge.net/tracker/index.php?func=detail&aid=1478460&group_id=36382&atid=416703 { isPackage = (is.read() < 0); } catch (IOException e) { //ignore } finally { try { is.close(); } catch (IOException e) { //ignore } } } return isPackage; } @Override public boolean isPackage(char[][] parentPackageName, char[] packageName) { StringBuilder result = new StringBuilder(); String sep = ""; if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { result.append(sep); result.append(parentPackageName[i]); sep = "."; } } if (Character.isUpperCase(packageName[0])) { if (!isPackage(result.toString())) { return false; } } result.append(sep); result.append(packageName); return isPackage(result.toString()); } @Override public void cleanup() { } }; return env; }
From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java
/** * Parse parameters from this request using HTTP. * * @param req The ServletRequest containing all request parameters. * @param cms The OpenCms object.//from w w w .jav a2 s .c o m * @return CmsSpellcheckingRequest object that contains parsed parameters. */ private CmsSpellcheckingRequest parseHttpRequest(final ServletRequest req, final CmsObject cms) { if ((null != cms) && !cms.getRequestContext().getCurrentUser().isGuestUser()) { if (null != req.getParameter(HTTP_PARAMETER_CHECKREBUILD)) { if (CmsSpellcheckDictionaryIndexer.updatingIndexNecessesary(cms)) { parseAndAddDictionaries(cms); } } if (null != req.getParameter(HTTP_PARAMTER_REBUILD)) { parseAndAddDictionaries(cms); } } final String q = req.getParameter(HTTP_PARAMETER_WORDS); if (null == q) { LOG.debug("Invalid HTTP request: No parameter \"" + HTTP_PARAMETER_WORDS + "\" defined. "); return null; } final StringTokenizer st = new StringTokenizer(q); final List<String> wordsToCheck = new ArrayList<String>(); while (st.hasMoreTokens()) { final String word = st.nextToken(); wordsToCheck.add(word); if (Character.isUpperCase(word.codePointAt(0))) { wordsToCheck.add(word.toLowerCase()); } } final String[] w = wordsToCheck.toArray(new String[wordsToCheck.size()]); final String dict = req.getParameter(HTTP_PARAMETER_LANG) == null ? LANG_DEFAULT : req.getParameter(HTTP_PARAMETER_LANG); return new CmsSpellcheckingRequest(w, dict); }
From source file:org.languagetool.tagging.uk.CompoundTagger.java
@Nullable private List<AnalyzedToken> doGuessCompoundTag(String word) { int dashIdx = word.lastIndexOf('-'); if (dashIdx == word.length() - 1) return null; int firstDashIdx = word.indexOf('-'); if (firstDashIdx == 0) return null; boolean startsWithDigit = Character.isDigit(word.charAt(0)); if (!startsWithDigit && dashIdx != firstDashIdx) { int dashCount = StringUtils.countMatches(word, "-"); if (dashCount >= 2 && dashIdx > firstDashIdx + 1) { List<AnalyzedToken> tokens = doGuessMultiHyphens(word, firstDashIdx, dashIdx); if (tokens != null) return tokens; }/*from w w w . jav a2 s . c o m*/ if (dashCount == 2 && dashIdx > firstDashIdx + 1) { return doGuessTwoHyphens(word, firstDashIdx, dashIdx); } return null; } String leftWord = word.substring(0, dashIdx); String rightWord = word.substring(dashIdx + 1); boolean dashPrefixMatch = dashPrefixes.contains(leftWord) || dashPrefixes.contains(leftWord.toLowerCase()) || DASH_PREFIX_LAT_PATTERN.matcher(leftWord).matches(); if (!dashPrefixMatch && (startsWithDigit || word.matches("[XLIV]+-.*"))) { return matchDigitCompound(word, leftWord, rightWord); } if (Character.isDigit(rightWord.charAt(0))) { return matchNumberedProperNoun(word, leftWord, rightWord); } // ..., ... ?? //TODO: : -? if (LEFT_INVALID.contains(leftWord.toLowerCase())) { List<TaggedWord> rightWdList = tagEitherCase(rightWord); rightWdList = PosTagHelper.filter2(rightWdList, Pattern.compile("(noun|adj)(?!.*pron).*")); if (rightWdList.isEmpty()) return null; String lemma = leftWord + "-" + rightWdList.get(0).getLemma(); String extraTag = StringTools.isCapitalizedWord(rightWord) ? "" : ":bad"; rightWdList = PosTagHelper.addIfNotContains(rightWdList, extraTag, lemma); return ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(word, rightWdList); } // wrong: - if (leftWord.equalsIgnoreCase("") && Character.isLowerCase(rightWord.charAt(0))) return null; List<TaggedWord> leftWdList = tagAsIsAndWithLowerCase(leftWord); // ?-, -, -, -, - if (rightPartsWithLeftTagMap.containsKey(rightWord) && !PosTagHelper.hasPosTagPart2(leftWdList, "abbr")) { if (leftWdList.isEmpty()) return null; Pattern leftTagRegex = rightPartsWithLeftTagMap.get(rightWord); List<AnalyzedToken> leftAnalyzedTokens = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(leftWord, leftWdList); List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>(leftAnalyzedTokens.size()); // ignore - if (rightWord.equals("") && LemmaHelper.hasLemma(leftAnalyzedTokens, Arrays.asList("", "", ""))) return null; for (AnalyzedToken analyzedToken : leftAnalyzedTokens) { String posTag = analyzedToken.getPOSTag(); if (posTag != null && (leftWord.equals("") && posTag.contains("adv")) || (leftTagRegex.matcher(posTag).matches())) { newAnalyzedTokens.add(new AnalyzedToken(word, posTag, analyzedToken.getLemma())); } } return newAnalyzedTokens.isEmpty() ? null : newAnalyzedTokens; } // -?, -? if (leftWord.equalsIgnoreCase("") && rightWord.endsWith("?")) { rightWord += ""; } // ??- if (Character.isUpperCase(leftWord.charAt(0)) && LemmaHelper.CITY_AVENU.contains(rightWord)) { return PosTagHelper.generateTokensForNv(word, "f", ":prop"); } List<TaggedWord> rightWdList = tagEitherCase(rightWord); if (rightWdList.isEmpty()) { if (word.startsWith("")) { // ?-? Matcher napivMatcher = Pattern.compile("(.+?)-(.+)").matcher(word); if (napivMatcher.matches()) { List<TaggedWord> napivLeftWdList = tagAsIsAndWithLowerCase(napivMatcher.group(1)); List<TaggedWord> napivRightWdList = tagAsIsAndWithLowerCase(napivMatcher.group(2)); List<AnalyzedToken> napivLeftAnalyzedTokens = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(napivMatcher.group(1), napivLeftWdList); List<AnalyzedToken> napivRightAnalyzedTokens = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(napivMatcher.group(2), napivRightWdList); List<AnalyzedToken> tagMatch = tagMatch(word, napivLeftAnalyzedTokens, napivRightAnalyzedTokens); if (tagMatch != null) { return tagMatch; } } } return null; } List<AnalyzedToken> rightAnalyzedTokens = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(rightWord, rightWdList); // - if (leftWord.length() == 1 && Character.isUpperCase(leftWord.charAt(0)) && LemmaHelper.hasLemma(rightAnalyzedTokens, Arrays.asList(""))) { return generateTokensWithRighInflected(word, leftWord, rightAnalyzedTokens, IPOSTag.adj.getText()); } if (leftWord.equalsIgnoreCase("")) { if (rightWord.endsWith("")) { return poAdvMatch(word, rightAnalyzedTokens, ADJ_TAG_FOR_PO_ADV_MIS); } else if (rightWord.endsWith("?")) { return poAdvMatch(word, rightAnalyzedTokens, ADJ_TAG_FOR_PO_ADV_NAZ); } return null; } // exclude: -, ?- List<AnalyzedToken> leftAnalyzedTokens = ukrainianTagger.asAnalyzedTokenListForTaggedWordsInternal(leftWord, leftWdList); if (PosTagHelper.hasPosTagPart(leftAnalyzedTokens, "&pron") && !PosTagHelper.hasPosTagPart(leftAnalyzedTokens, "numr")) return null; if (!leftWord.equalsIgnoreCase(rightWord) && PosTagHelper.hasPosTag(rightAnalyzedTokens, "(part|conj).*|.*?:&pron.*") && !(PosTagHelper.hasPosTag(leftAnalyzedTokens, "numr.*") && PosTagHelper.hasPosTag(rightAnalyzedTokens, "numr.*"))) return null; // - if (Character.isUpperCase(rightWord.charAt(0))) { if (word.startsWith("-")) { List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>(rightAnalyzedTokens.size()); for (AnalyzedToken rightAnalyzedToken : rightAnalyzedTokens) { String rightPosTag = rightAnalyzedToken.getPOSTag(); if (rightPosTag == null) continue; if (NOUN_SING_V_ROD_REGEX.matcher(rightPosTag).matches()) { for (String vid : PosTagHelper.VIDMINKY_MAP.keySet()) { if (vid.equals("v_kly")) continue; String posTag = rightPosTag.replace("v_rod", vid) + ":ua_1992"; newAnalyzedTokens.add(new AnalyzedToken(word, posTag, word)); } } } return newAnalyzedTokens; } else { // we don't want ?- but want ???-? if (StringTools.isCapitalizedWord(rightWord) || leftWord.endsWith("") || PosTagHelper.hasPosTag(rightAnalyzedTokens, Pattern.compile("adj.*"))) { // tag ?/noun ? adj List<TaggedWord> rightWdList2 = tagAsIsAndWithLowerCase(rightWord); List<AnalyzedToken> rightAnalyzedTokens2 = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(rightWord, rightWdList2); List<AnalyzedToken> match = tryOWithAdj(word, leftWord, rightAnalyzedTokens2); if (match != null) return match; } return null; } } // TODO: ua_2019 // ?-? if (dashPrefixMatch) { List<AnalyzedToken> newTokens = new ArrayList<>(); if (leftWord.length() == 1 && leftWord.matches("[a-zA-Z--]")) { List<AnalyzedToken> newTokensAdj = getNvPrefixLatWithAdjMatch(word, rightAnalyzedTokens, leftWord); if (newTokensAdj != null) { newTokens.addAll(newTokensAdj); } } List<AnalyzedToken> newTokensNoun = getNvPrefixNounMatch(word, rightAnalyzedTokens, leftWord); if (newTokensNoun != null) { newTokens.addAll(newTokensNoun); } return newTokens; } // don't allow: -, -, ?- // allow -! if (!PosTagHelper.hasPosTag(leftAnalyzedTokens, "intj.*")) { String noDashWord = word.replace("-", ""); List<TaggedWord> noDashWordList = tagAsIsAndWithLowerCase(noDashWord); List<AnalyzedToken> noDashAnalyzedTokens = ukrainianTagger .asAnalyzedTokenListForTaggedWordsInternal(noDashWord, noDashWordList); if (!noDashAnalyzedTokens.isEmpty()) return null; } // -, -, - if (!leftWdList.isEmpty() && leftWord.length() > 2) { List<AnalyzedToken> tagMatch = tagMatch(word, leftAnalyzedTokens, rightAnalyzedTokens); if (tagMatch != null) { return tagMatch; } } List<AnalyzedToken> match = tryOWithAdj(word, leftWord, rightAnalyzedTokens); if (match != null) return match; compoundDebugLogger.logUnknownCompound(word); return null; }
From source file:com.xie.javacase.json.JSONObject.java
private void populateInternalMap(Object bean, boolean includeSuperClass) { Class klass = bean.getClass(); /* If klass.getSuperClass is System class then force includeSuperClass to false. */ if (klass.getClassLoader() == null) { includeSuperClass = false;/*from www .j a v a 2 s . c om*/ } Method[] methods = (includeSuperClass) ? klass.getMethods() : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try { Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); String key = ""; if (name.startsWith("get")) { key = name.substring(3); } else if (name.startsWith("is")) { key = name.substring(2); } if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } Object result = method.invoke(bean, (Object[]) null); if (result == null) { map.put(key, NULL); } else if (result.getClass().isArray()) { map.put(key, new JSONArray(result, includeSuperClass)); } else if (result instanceof Collection) { // List or Set map.put(key, new JSONArray((Collection) result, includeSuperClass)); } else if (result instanceof Map) { map.put(key, new JSONObject((Map) result, includeSuperClass)); } else if (isStandardProperty(result.getClass())) { // Primitives, String and Wrapper map.put(key, result); } else { if (result.getClass().getPackage().getName().startsWith("java") || result.getClass().getClassLoader() == null) { map.put(key, result.toString()); } else { // User defined Objects map.put(key, new JSONObject(result, includeSuperClass)); } } } } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:edu.ucsd.sbrg.escher.model.Node.java
/** * @param biggId the biggId to set. Parameter is allowed to be {@code null}. * If the parameter is not {@code null}, this method will attempt to * extract the compartment code from the given BiGG id. *//*from ww w .j av a 2s . co m*/ @JsonProperty("bigg_id") public void setBiggId(String biggId) { this.biggId = biggId; if (biggId != null) { /* ID structure: [prefix]_[abbreviation]_[compartment code]_[tissue code] * prefix and tissue code can be absent; abbreviation and compartment code * are mandatory! * Prefix must be either R or M. */ String id = biggId; if (id.matches("[RrMm]_.*")) { id = id.substring(2); } String idParts[] = id.replace("__", "-").split("_"); if (idParts.length > 1) { compartment = idParts[1]; if ((idParts.length > 2) && ((compartment.length() > 1) || Utils.isNumber(compartment, true) || Character.isUpperCase(compartment.charAt(0)))) { int i = 2; while (Utils.isNumber(idParts[i], true)) { i++; } compartment = idParts[i]; } } else { logger.warning(MessageFormat.format(bundle.getString("Node.invalidCompartmentId"), biggId)); } } else { compartment = null; } }
From source file:org.intermine.metadata.StringUtil.java
/** * Return 'a' or 'an' according to first letter of the given article. If article starts with * a vowel or appears to be an acronym return 'an'. * * @param s the subject of the article/*w w w .j a v a2 s . c om*/ * @return the appropriate indefinite article */ @SuppressWarnings("boxing") public static String indefiniteArticle(String s) { List<Character> vowels = new ArrayList<Character>( Arrays.asList(new Character[] { 'a', 'e', 'i', 'o', 'u' })); String noun = s.trim(); if (vowels.contains(noun.charAt(0))) { return "an"; } List<Character> vowelPronounced = new ArrayList<Character>( Arrays.asList(new Character[] { 'A', 'E', 'F', 'H', 'I', 'L', 'M', 'N', 'O', 'R', 'S', 'X' })); if (Character.isUpperCase(noun.charAt(0))) { if ((noun.length() == 1 || Character.isUpperCase(noun.charAt(1))) && vowelPronounced.contains(noun.charAt(0))) { return "an"; } } return "a"; }
From source file:org.paxml.selenium.rc.SeleniumHelper.java
static String[] getKeyCodes(char ch) { boolean shiftRequired = false; String key = String.valueOf(ch); String value = KEY_CODES_MAP.get(key); if (value != null) { shiftRequired = true;//from w w w .j a v a 2 s. c o m key = value; } else if (Character.isUpperCase(key.charAt(0))) { shiftRequired = true; } else { key = key.toUpperCase(); } KeyStroke ks = KeyStroke.getKeyStroke("pressed " + key.toUpperCase()); int keyCode = 0; if (ks != null && ks.getKeyCode() != 0) { keyCode = ks.getKeyCode(); } else { keyCode = CHAR_TO_KEY_CODE_MAP.get(key); } return shiftRequired ? new String[] { String.valueOf(KeyEvent.VK_SHIFT), String.valueOf(keyCode) } : new String[] { String.valueOf(keyCode) }; }