List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:CharUtils.java
/** * Check if character is a capital letter. * /* w ww.j av a 2 s .co m*/ * @param c * Character to test. * * @return true if character is a capital letter. */ public static boolean isCapitalLetter(char c) { return Character.isLetter(c) && Character.isUpperCase(c); }
From source file:com.textocat.textokit.io.brat.AutoBratUimaMappingFactory.java
private Feature searchFeatureByBratRoleName(Type uimaType, String roleName) { String featName = roleName;//w ww . jav a 2 s . c o m Feature feat = uimaType.getFeatureByBaseName(featName); if (feat != null) { return feat; } featName = toProperJavaName(featName); feat = uimaType.getFeatureByBaseName(featName); if (feat != null) { return feat; } if (featName.length() > 0 && Character.isUpperCase(featName.charAt(0))) { featName = StringUtils.uncapitalize(featName); feat = uimaType.getFeatureByBaseName(featName); if (feat != null) { return feat; } } return null; }
From source file:org.apache.hadoop.gateway.config.impl.DefaultConfigurationInjector.java
private static String getConfigName(Method method) { String methodName = method.getName(); if (methodName != null) { StringBuilder name = new StringBuilder(methodName.length()); if (methodName.length() > 3 && methodName.startsWith("set") && Character.isUpperCase(methodName.charAt(3))) { name.append(methodName.substring(3)); name.setCharAt(0, Character.toLowerCase(name.charAt(0))); } else {//from w ww . j a v a 2 s . co m name.append(name); } return name.toString(); } return null; }
From source file:org.kuali.rice.devtools.generators.dd.MaintDocDDCreator.java
public static String camelCaseToHelpParm(String className) { StringBuffer newName = new StringBuffer(className); // lower case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toLowerCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, '_'); i++;/*from w ww .j av a 2 s. co m*/ } } return newName.toString().toUpperCase().trim(); }
From source file:org.dasein.persist.riak.RiakCache.java
public String getBucket() { if (bucketName == null) { String entityName = getEntityName(); if (entityName != null) { bucketName = entityName;/*from w w w . j a v a 2 s. co m*/ return bucketName; } String name = getEntityClassName(); int idx = name.lastIndexOf('.'); while (idx == 0 && name.length() > 1) { name = name.substring(1); idx = name.lastIndexOf('.'); } while (idx == (name.length() - 1) && name.length() > 1) { name = name.substring(0, name.length() - 1); idx = name.lastIndexOf('.'); } if (idx == -1 || name.length() < 2) { return name; } name = name.substring(idx + 1); StringBuilder s = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (Character.isUpperCase(c) && i > 0) { s.append("_"); } s.append(Character.toLowerCase(c)); } bucketName = s.toString(); } return bucketName; }
From source file:com.nebkat.plugin.text.TextPlugin.java
@EventHandler @CommandFilter("text") public void onCommand(CommandEvent e) { if (e.getParams().length < 2) { e.showUsage(getBot());/* w w w.j a va2s . co m*/ return; } String action = e.getParams()[0]; String text = e.getRawParams().substring(action.length() + 1); String result = "Algorithm unsupported"; if (action.equalsIgnoreCase("invert")) { result = new StringBuilder(text).reverse().toString(); } else if (action.equalsIgnoreCase("wordinvert")) { String[] words = text.split(" "); for (int i = 0; i < words.length; i++) { words[i] = new StringBuilder(words[i]).reverse().toString(); } result = Utils.implode(words, " "); } else if (action.equalsIgnoreCase("upsidedown")) { StringBuilder upside = new StringBuilder(); for (int i = 0; i < text.length(); i++) { String character = text.substring(i, i + 1); character = UPSIDE_DOWN_MAP.getOrDefault(character, character); upside.insert(0, character); } result = upside.toString(); } else if (action.equalsIgnoreCase("bubble")) { StringBuilder bubble = new StringBuilder(); for (int i = 0; i < text.length(); i++) { String character = text.substring(i, i + 1); character = BUBBLE_MAP.getOrDefault(character, character); bubble.append(character); } result = bubble.toString(); } else if (action.equals("uppercase") || action.equals("upper")) { result = text.toUpperCase(); } else if (action.equals("lowercase") || action.equals("lower")) { result = text.toLowerCase(); } else if (action.equals("randcase")) { StringBuilder randcase = new StringBuilder(); for (int i = 0; i < text.length(); i++) { randcase.append(Math.random() < 0.5 ? text.substring(i, i + 1).toLowerCase() : text.substring(i, i + 1).toUpperCase()); } result = randcase.toString(); } else if (action.equalsIgnoreCase("switchcase")) { StringBuilder switchcase = new StringBuilder(); for (int i = 0; i < text.length(); i++) { switchcase.append(Character.isUpperCase(text.charAt(i)) ? text.substring(i, i + 1).toLowerCase() : text.substring(i, i + 1).toUpperCase()); } result = switchcase.toString(); } else if (action.equalsIgnoreCase("wordcapitalise")) { String[] words = text.split(" "); for (int i = 0; i < words.length; i++) { if (words[i].length() > 0) { words[i] = words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase(); } } result = Utils.implode(words, " "); Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + Utils.implode(words, " ")); } Irc.message(e.getSession(), e.getTarget(), e.getSource().getNick() + ": " + result); }
From source file:net.minder.config.impl.DefaultConfigurationInjector.java
private static String getConfigName(Method method) { String methodName = method.getName(); StringBuilder name = new StringBuilder(methodName.length()); if (methodName != null && methodName.length() > 3 && methodName.startsWith("set") && Character.isUpperCase(methodName.charAt(3))) { name.append(methodName.substring(3)); name.setCharAt(0, Character.toLowerCase(name.charAt(0))); } else {//from w ww . java 2 s. c om name.append(name); } return name.toString(); }
From source file:org.dbpedia.spotlight.spot.CoOccurrenceBasedSelector.java
/** * Filter the list of surface form occurrences, removing all occurrences that are considered * common./*w w w . j av a 2 s.c o m*/ * * @param surfaceFormOccurrences spotted surface form occurrences * @return List of non-common surface form occurrences */ public List<SurfaceFormOccurrence> select(List<SurfaceFormOccurrence> surfaceFormOccurrences) { List<SurfaceFormOccurrence> selectedOccurrences = new LinkedList<SurfaceFormOccurrence>(); FilterPOS filterPOS = new FilterPOS(); FilterTermsize unigramFilter = new FilterTermsize(FilterTermsize.Termsize.unigram); FilterPattern filterPattern = new FilterPattern(); SpotClassifier unigramClassifier = ClassifierFactory.getClassifierInstanceUnigram(); SpotClassifier ngramClassifier = ClassifierFactory.getClassifierInstanceNGram(); assert unigramClassifier != null; assert ngramClassifier != null; //ngramClassifier.setVerboseMode(true); f //unigramClassifier.setVerboseMode(true); List<String> decisions = new LinkedList<String>(); for (SurfaceFormOccurrence surfaceFormOccurrence : surfaceFormOccurrences) { if (surfaceFormOccurrence.surfaceForm().name().trim().length() == 0) { LOG.warn("I have an occurrence with empty surface form. :-O Ignoring."); LOG.error(surfaceFormOccurrence); continue; } if (!(surfaceFormOccurrence.context() instanceof TaggedText)) { //FIXME added this to avoid breaking, but code below will never run if we don't pass the taggedtext LOG.error(String.format("SurfaceFormOccurrence did not contain TaggedText. Cannot apply %s", this.getClass())); selectedOccurrences.add(surfaceFormOccurrence); continue; } if (unigramFilter.applies(surfaceFormOccurrence)) { /** * Unigram (n = 1) */ if (!filterPOS.applies(surfaceFormOccurrence)) { /** * The Surface Form is on the POS blacklist, i.e. a single adjective, * verb, etc. */ if (Character.isUpperCase(surfaceFormOccurrence.surfaceForm().name().charAt(0))) { TaggedToken taggedToken = ((TaggedText) surfaceFormOccurrence.context()) .taggedTokenProvider().getTaggedTokens(surfaceFormOccurrence).get(0); /** * Add uppercase adjectives (e.g. Canadian tv star) */ if (taggedToken.getPOSTag() != null && taggedToken.getPOSTag().startsWith("j")) selectedOccurrences.add(surfaceFormOccurrence); } else { decisions.add("Dropped by POS filter: " + surfaceFormOccurrence); } } else if (!filterPattern.applies(surfaceFormOccurrence)) { decisions.add("Dropped by Pattern filter: " + surfaceFormOccurrence); } else { SpotClassification spotClassification; try { spotClassification = unigramClassifier.classify(surfaceFormOccurrence); if (spotClassification.getCandidateClass() == SpotClass.valid) { selectedOccurrences.add(surfaceFormOccurrence); //LOG.info(("Kept by UnigramClassifier (Confidence: " + spotClassification.getConfidence() + "): " + surfaceFormOccurrence); } else { decisions.add("Dropped by UnigramClassifier (Confidence: " + spotClassification.getConfidence() + "): " + surfaceFormOccurrence); } } catch (Exception e) { LOG.error("Exception when classifying unigram candidate: " + e); } } } else { /** * n > 1 */ SpotClassification spotClassification; try { spotClassification = ngramClassifier.classify(surfaceFormOccurrence); } catch (Exception e) { LOG.error("Exception when classifying ngram candidate: " + e); continue; } if (spotClassification.getCandidateClass() == SpotClass.valid) { selectedOccurrences.add(surfaceFormOccurrence); //LOG.info("Kept by nGramClassifier (Confidence: " + spotClassification.getConfidence() + "): " + surfaceFormOccurrence); } else { decisions.add("Dropped by NGramClassifier: " + surfaceFormOccurrence); } } } if (LOG.isDebugEnabled()) for (String decision : decisions) { LOG.debug(decision); } return selectedOccurrences; }
From source file:org.intermine.metadata.StringUtil.java
/** * Returns a string with the same initial letter case as the template string * * @param n the String to convert// ww w. j a v a 2 s . c om * @param template the String to base the conversion on * @return the new String, capitalised like template */ public static String toSameInitialCase(String n, String template) { if (n == null) { throw new NullPointerException("String to convert cannot be null"); } if (template == null) { return n; } StringBuffer sb = new StringBuffer(); if (Character.isUpperCase(template.charAt(0))) { sb.append(Character.toUpperCase(n.charAt(0))); } if (Character.isLowerCase(template.charAt(0))) { sb.append(Character.toLowerCase(n.charAt(0))); } if (n.length() > 1) { sb.append(n.substring(1, n.length())); } return sb.toString(); }
From source file:de.unidue.inf.is.ezdl.dlcore.utils.StringUtils.java
/** * Returns true if all characters in the String are upper case. * /* ww w . j a v a2s. c om*/ * @param str * the String to check * @return true, if all characters are upper case. Else false. */ public static boolean allCaps(String str) { int charCount = str.length(); for (int i = 0; (i < charCount); i++) { char ch = str.charAt(i); if (!Character.isUpperCase(ch)) { return false; } } return true; }