List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.eclipse.wb.internal.core.utils.StringUtilities.java
/** * Extract camel words from specified string. * /* w w w . j ava2 s . co m*/ * <pre> * Example: NullPointException --> [Null, Pointer, Exception] * Example: null --> [] * * <pre> */ public static String[] extractCamelWords(String string) { if (string == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } int length = string.length(); // int count = 0; for (int i = 0; i < length; i++) { char ch = string.charAt(i); if (Character.isUpperCase(ch)) { count++; } } // String[] words = new String[count]; int wordNum = 0; int begin = -1; for (int i = 0; i < length; i++) { char ch = string.charAt(i); boolean isLast = i == length - 1; if (Character.isUpperCase(ch) || isLast) { if (begin >= 0) { int end = i; if (isLast) { end++; } String word = string.substring(begin, end); words[wordNum++] = word; } begin = i; } } return words; }
From source file:org.apdplat.superword.tools.TextAnalyzer.java
/** * ?/*from ww w . j ava 2 s.c o m*/ * @param sentence * @return */ public static List<String> seg(String sentence) { List<String> data = new ArrayList<>(); //?? String[] words = sentence.trim().split("[^a-zA-Z0-9]"); StringBuilder log = new StringBuilder(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("??:" + sentence); } for (String word : words) { if (StringUtils.isBlank(word) || word.length() < 2) { continue; } List<String> list = new ArrayList<>(); //?? if (word.length() < 6 //PostgreSQL || (Character.isUpperCase(word.charAt(word.length() - 1)) && Character.isUpperCase(word.charAt(0))) //P2P,Neo4j || PATTERN.matcher(word).find() || StringUtils.isAllUpperCase(word)) { word = word.toLowerCase(); } //??? int last = 0; for (int i = 1; i < word.length(); i++) { if (Character.isUpperCase(word.charAt(i)) && Character.isLowerCase(word.charAt(i - 1))) { list.add(word.substring(last, i)); last = i; } } if (last < word.length()) { list.add(word.substring(last, word.length())); } list.stream().map(w -> w.toLowerCase()).forEach(w -> { if (w.length() < 2) { return; } w = irregularity(w); if (StringUtils.isNotBlank(w)) { data.add(w); if (LOGGER.isDebugEnabled()) { log.append(w).append(" "); } } }); } LOGGER.debug("?" + log); return data; }
From source file:com.github.jgility.core.project.Person.java
private boolean checkCapitalFirstLetter(String string) { return StringUtils.isNotBlank(string) && Character.isUpperCase(string.charAt(0)); }
From source file:com.kantenkugel.discordbot.jdocparser.JDocParser.java
static void parse(final String jdocBase, final String name, final InputStream inputStream, Map<String, ClassDocumentation> docs) { final String[] pathSplits = name.split("/"); final String fileName = pathSplits[pathSplits.length - 1]; if (!Character.isUpperCase(fileName.charAt(0))) { //ignore jdoc structure html return;//from ww w . j av a 2s . c o m } final String[] nameSplits = fileName.split("\\."); final String className = nameSplits[nameSplits.length - 2]; final String fullName = fileName.substring(0, fileName.length() - nameSplits[nameSplits.length - 1].length() - 1); try (BufferedReader buffer = new BufferedReader(new InputStreamReader(inputStream))) { //create dom Document final String content = buffer.lines().collect(Collectors.joining("\n")); Document document = Jsoup.parse(content); //classDocument (classname, package, description) Element titleElem = getSingleElementByClass(document, "title"); final String classSig = JDocUtil.fixSpaces(titleElem.text()); Element packageElem = titleElem.previousElementSibling(); if (packageElem.children().size() > 1) { packageElem = packageElem.children().last(); } final String pack = JDocUtil.fixSpaces(packageElem.text()); final String link = JDocUtil.getLink(jdocBase, pack, fullName); Element descriptionElement = null; Elements descriptionCandidates = document.select(".description .block"); if (descriptionCandidates.size() > 1) { List<Element> removed = descriptionCandidates.stream().map(elem -> elem.child(0)) .filter(child -> child != null && !child.className().startsWith("deprecat")) .map(Element::parent).collect(Collectors.toList()); if (removed.size() != 1) throw new RuntimeException("Found too many description candidates"); descriptionElement = removed.get(0); } else if (descriptionCandidates.size() == 1) { descriptionElement = descriptionCandidates.get(0); } final String description = descriptionElement == null ? "" : JDocUtil.formatText(descriptionElement.html(), link); final ClassDocumentation classDoc = new ClassDocumentation(pack, fullName, classSig, description, classSig.startsWith("Enum")); //methods, fields final Element details = document.getElementsByClass("details").first(); if (details != null) { //methods Element tmp = getSingleElementByQuery(details, "a[name=\"method.detail\"]"); List<DocBlock> docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { Set<MethodDocumentation> mdocs = classDoc.methodDocs .computeIfAbsent(block.title.toLowerCase(), key -> new HashSet<>()); mdocs.add(new MethodDocumentation(classDoc, block.signature, block.hashLink, block.description, block.fields)); } } //vars tmp = getSingleElementByQuery(details, "a[name=\"field.detail\"]"); docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { classDoc.classValues.put(block.title.toLowerCase(), new ValueDocumentation(classDoc, block.title, block.hashLink, block.signature, block.description)); } } //enum-values tmp = getSingleElementByQuery(details, "a[name=\"enum.constant.detail\"]"); docBlock = getDocBlock(jdocBase, tmp, classDoc); if (docBlock != null) { for (DocBlock block : docBlock) { classDoc.classValues.put(block.title.toLowerCase(), new ValueDocumentation(classDoc, block.title, block.hashLink, block.signature, block.description)); } } } final Element methodSummary = getSingleElementByQuery(document, "a[name=\"method.summary\"]"); classDoc.inheritedMethods.putAll(getInheritedMethods(methodSummary)); //storing if (nameSplits.length > 2) { if (!docs.containsKey(nameSplits[0].toLowerCase())) docs.put(nameSplits[0].toLowerCase(), new ClassDocumentation(null, null, null, null, false)); ClassDocumentation parent = docs.get(nameSplits[0].toLowerCase()); for (int i = 1; i < nameSplits.length - 2; i++) { if (!parent.subClasses.containsKey(nameSplits[i].toLowerCase())) parent.subClasses.put(nameSplits[i].toLowerCase(), new ClassDocumentation(null, null, null, null, false)); parent = parent.subClasses.get(nameSplits[i].toLowerCase()); } if (parent.subClasses.containsKey(className.toLowerCase())) classDoc.subClasses.putAll(parent.subClasses.get(className.toLowerCase()).subClasses); parent.subClasses.put(className.toLowerCase(), classDoc); } if (docs.containsKey(fullName.toLowerCase())) { ClassDocumentation current = docs.get(fullName.toLowerCase()); if (current.classSig != null) throw new RuntimeException("Got a class-name conflict with classes " + classDoc.classSig + "(" + classDoc.className + ") AND " + current.classSig + "(" + current.className + ")"); classDoc.subClasses.putAll(current.subClasses); } docs.put(fullName.toLowerCase(), classDoc); } catch (final IOException | NullPointerException ex) { JDocUtil.LOG.error("Got excaption for element {}", fullName, ex); } try { inputStream.close(); } catch (final IOException e) { JDocUtil.LOG.error("Error closing inputstream", e); } }
From source file:de.jcup.egradle.core.util.GradleResourceLinkCalculator.java
private GradleHyperLinkResult internalCreateLink(String line, int offsetInLine) { /* e.g. abc defg Test abc */ /* ^-- Test must be identified */ String rightSubString = line.substring(offsetInLine); StringBuilder content = new StringBuilder(); for (char c : rightSubString.toCharArray()) { if (Character.isWhitespace(c)) { break; }//from ww w .j av a2 s . co m if (c == '{') { break; } if (c == ',') { break; } if (c == '(') { break; } if (c == ')') { break; } if (c == '[') { break; } if (c == '<') { break; } if (c == '>') { break; } if (c == '.') { break; } if (!Character.isJavaIdentifierPart(c)) { return null; } content.append(c); } if (StringUtils.isBlank(content)) { return null; } String leftSubString = line.substring(0, offsetInLine); char[] leftCharsArray = leftSubString.toCharArray(); ArrayUtils.reverse(leftCharsArray); int startPos = offsetInLine; for (char c : leftCharsArray) { if (c == '(') { break; } if (c == '<') { break; } if (c == '.') { break; } if (Character.isWhitespace(c)) { break; } if (!Character.isJavaIdentifierPart(c)) { return null; } startPos--; content.insert(0, c); } String linkContent = content.toString(); char firstChar = linkContent.charAt(0); if (!Character.isJavaIdentifierStart(firstChar)) { return null; } /* * currently this calculator only supports correct Type syntax means * first char MUST be upper cased */ if (!Character.isUpperCase(firstChar)) { return null; } GradleHyperLinkResult result = new GradleHyperLinkResult(); result.linkOffsetInLine = startPos; result.linkContent = linkContent; result.linkLength = linkContent.length(); return result; }
From source file:org.gradle.model.internal.manage.schema.store.ModelSchemaExtractor.java
public <T> ExtractedModelSchema<T> extract(ModelType<T> type) { validateType(type);//from w w w . j av a 2 s .com List<Method> methodList = Arrays.asList(type.getRawClass().getDeclaredMethods()); if (methodList.isEmpty()) { return new ExtractedModelSchema<T>(type, Collections.<ModelPropertyFactory<?>>emptyList()); } List<ModelPropertyFactory<?>> propertyFactories = Lists.newLinkedList(); Map<String, Method> methods = Maps.newHashMap(); for (Method method : methodList) { String name = method.getName(); if (methods.containsKey(name)) { throw invalidMethod(type, name, "overloaded methods are not supported"); } methods.put(name, method); } List<String> methodNames = Lists.newLinkedList(methods.keySet()); List<String> handled = Lists.newArrayList(); for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) { String methodName = iterator.next(); Method method = methods.get(methodName); if (methodName.startsWith("get") && !methodName.equals("get")) { if (method.getParameterTypes().length != 0) { throw invalidMethod(type, methodName, "getter methods cannot take parameters"); } Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { throw invalidMethod(type, methodName, "the 4th character of the getter method name must be an uppercase character"); } ModelType<?> returnType = ModelType.of(method.getGenericReturnType()); if (isManaged(returnType.getRawClass())) { propertyFactories .add(extractPropertyOfManagedType(type, methods, methodName, returnType, handled)); } else { propertyFactories .add(extractPropertyOfUnmanagedType(type, methods, methodName, returnType, handled)); } iterator.remove(); } } methodNames.removeAll(handled); // TODO - should call out valid getters without setters if (!methodNames.isEmpty()) { throw invalid(type, "only paired getter/setter methods are supported (invalid methods: [" + Joiner.on(", ").join(methodNames) + "])"); } return new ExtractedModelSchema<T>(type, propertyFactories); }
From source file:org.apache.camel.itest.karaf.AbstractFeatureTest.java
public static String extractName(Class clazz) { String name = clazz.getName(); int id0 = name.indexOf("Camel") + "Camel".length(); int id1 = name.indexOf("Test"); StringBuilder sb = new StringBuilder(); for (int i = id0; i < id1; i++) { char c = name.charAt(i); if (Character.isUpperCase(c) && sb.length() > 0) { sb.append("-"); }/*from www. ja v a 2 s. c o m*/ sb.append(Character.toLowerCase(c)); } return sb.toString(); }
From source file:org.apdplat.superword.rule.TextAnalysis.java
/** * ?// w ww. j a va2s .c o m * @param sentence * @param debug ??? * @return */ public static List<String> seg(String sentence, boolean debug) { List<String> data = new ArrayList<>(); //?? String[] words = sentence.trim().split("[^a-zA-Z]"); StringBuilder log = new StringBuilder(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("??:" + sentence); } for (String word : words) { if (StringUtils.isBlank(word)) { continue; } List<String> list = new ArrayList<String>(); //?6??? if (word.length() < 6 || StringUtils.isAllUpperCase(word)) { word = word.toLowerCase(); } //??? int last = 0; for (int i = 1; i < word.length(); i++) { if (Character.isUpperCase(word.charAt(i)) && Character.isLowerCase(word.charAt(i - 1))) { list.add(word.substring(last, i)); last = i; } } if (last < word.length()) { list.add(word.substring(last, word.length())); } list.stream().map(w -> w.toLowerCase()).forEach(w -> { if (w.length() < 2) { return; } w = irregularity(w); if (StringUtils.isNotBlank(w)) { data.add(w); if (LOGGER.isDebugEnabled()) { log.append(w).append(" "); } } }); } LOGGER.debug("?" + log); return data; }
From source file:org.nuxeo.ecm.webengine.model.impl.GroovyTypeLoader.java
protected void scan(File root, String path, Writer cache) { for (File file : root.listFiles()) { String name = file.getName(); if (file.isDirectory() && !"skin".equals(name) && !"samples".equals(name)) { scan(file,/*from w ww.j av a 2 s. com*/ path == null ? name : new StringBuilder().append(path).append('.').append(name).toString(), cache); } else if (name.endsWith(".groovy") && Character.isUpperCase(name.charAt(0))) { String className = null; if (path == null) { className = name.substring(0, name.length() - 7); } else { StringBuilder buf = new StringBuilder().append(path).append('.').append(name); buf.setLength(buf.length() - 7); className = buf.toString(); } try { TypeDescriptor td = loadTypeAndRecord(cache, className); if (td != null) { typeReg.registerTypeDescriptor(td); } } catch (Exception e) { throw WebException.wrap(e); } } } }
From source file:eu.annocultor.converters.europeana.EuropeanaLabelExtractor.java
private boolean specialCharacterFilter(String label) { // in full-text labels should be capitalised if (fullTextMode && !Character.isUpperCase(label.charAt(0))) { return false; }/*from ww w .j ava2s .c om*/ // otherwise make it lower case label = label.toLowerCase(); for (int i = 0; i < label.length(); i++) { int words = 0; char c = label.charAt(i); if (Character.isLetter(c) || c == ' ' || c == '-') { if (c == ' ' || c == '-') { words++; } if (words > 3) { // multi-word names sound suspicious return false; } // ok } else { return false; } } return true; }