List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:gov.nih.nci.evs.browser.utils.CodeSearchUtils.java
public String findBestContainsAlgorithm(String matchText) { if (matchText == null) return "nonLeadingWildcardLiteralSubString"; matchText = matchText.trim();//from ww w . j av a2 s. com if (matchText.length() == 0) return "nonLeadingWildcardLiteralSubString"; // or null if (matchText.length() > 1) return "nonLeadingWildcardLiteralSubString"; char ch = matchText.charAt(0); if (Character.isDigit(ch)) return "literal"; else if (Character.isLetter(ch)) return "LuceneQuery"; else return "literalContains"; }
From source file:info.magnolia.cms.core.Path.java
private static boolean isAbsolute(String path) { if (path == null) { return false; }//from ww w. jav a 2 s.c om if (path.startsWith("/") || path.startsWith(File.separator)) { //$NON-NLS-1$ return true; } // windows c: if (path.length() >= 3 && Character.isLetter(path.charAt(0)) && path.charAt(1) == ':') { return true; } return false; }
From source file:org.apache.archiva.common.utils.VersionComparator.java
public static String[] toParts(String version) { if (StringUtils.isBlank(version)) { return ArrayUtils.EMPTY_STRING_ARRAY; }/*from ww w .jav a 2s .co m*/ int modeOther = 0; int modeDigit = 1; int modeText = 2; List<String> parts = new ArrayList<>(); int len = version.length(); int i = 0; int start = 0; int mode = modeOther; while (i < len) { char c = version.charAt(i); if (Character.isDigit(c)) { if (mode != modeDigit) { if (mode != modeOther) { parts.add(version.substring(start, i)); } mode = modeDigit; start = i; } } else if (Character.isLetter(c)) { if (mode != modeText) { if (mode != modeOther) { parts.add(version.substring(start, i)); } mode = modeText; start = i; } } else { // Other. if (mode != modeOther) { parts.add(version.substring(start, i)); mode = modeOther; } } i++; } // Add remainder if (mode != modeOther) { parts.add(version.substring(start, i)); } return parts.toArray(new String[parts.size()]); }
From source file:de.tudarmstadt.ukp.dkpro.core.jazzy.JazzyChecker.java
@Override public void process(final JCas jcas) throws AnalysisEngineProcessException { AnnotationChecker.requireExists(this, jcas, this.getLogger(), Token.class); AnnotationChecker.requireNotExists(this, jcas, this.getLogger(), SpellingAnomaly.class, SuggestedAction.class); for (Token t : select(jcas, Token.class)) { String tokenText = t.getCoveredText(); if (tokenText.matches("[\\.\\?\\!]")) { continue; }/* w w w . j a v a2s .c om*/ if (!dict.isCorrect(tokenText)) { SpellingAnomaly anomaly = new SpellingAnomaly(jcas, t.getBegin(), t.getEnd()); // only try to correct single character tokens if they are letters if (tokenText.length() == 1 && !Character.isLetter(tokenText.charAt(0))) { continue; } @SuppressWarnings("unchecked") List<Word> suggestions = dict.getSuggestions(tokenText, scoreThreshold); SuggestionCostTuples tuples = new SuggestionCostTuples(); for (Word suggestion : suggestions) { String suggestionString = suggestion.getWord(); int cost = suggestion.getCost(); if (suggestionString != null) { tuples.addTuple(suggestionString, cost); } } if (tuples.size() > 0) { FSArray actions = new FSArray(jcas, tuples.size()); int i = 0; for (SuggestionCostTuple tuple : tuples) { SuggestedAction action = new SuggestedAction(jcas); action.setReplacement(tuple.getSuggestion()); action.setCertainty(tuple.getNormalizedCost(tuples.getMaxCost())); actions.set(i, action); i++; } anomaly.setSuggestions(actions); anomaly.addToIndexes(); } } } }
From source file:stg.utils.RandomStringGenerator.java
/** * Sets the special character array.//from w ww .j a v a2 s . co m * The default character array contains ~,`,!,@,#,$,^,.,: in this sequence. * * @param specialCharArray */ public void setSpecialChars(char[] specialCharArray) { if (specialCharArray == null) { throw new NullPointerException(); } ArrayList<Character> list = new ArrayList<Character>(); for (int i = 0; i < specialCharArray.length; i++) { if (Character.isLetter(specialCharArray[i])) { throw new IllegalArgumentException( "Must be a special character. Special chracter any character other than alpahbets and numbers"); } if (Character.isDigit(specialCharArray[i])) { throw new IllegalArgumentException( "Must be a special character. Special chracter any character other than alpahbets and numbers"); } list.add(specialCharArray[i]); } specialCharsList.clear(); specialCharsList.addAll(list); }
From source file:org.kie.workbench.common.services.datamodeller.codegen.GenerationTools.java
private String toJavaName(String name, boolean firstLetterIsUpperCase) { name = name.toLowerCase();/*from ww w . j a v a 2s . c om*/ StringBuffer res = new StringBuffer(); boolean nextIsUpperCase = firstLetterIsUpperCase; for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (nextIsUpperCase) { c = Character.toUpperCase(c); } if (Character.isLetter(c)) { res.append(c); nextIsUpperCase = false; } else { nextIsUpperCase = true; } } return res.toString(); }
From source file:org.castor.cpa.persistence.sql.connection.DataSourceConnectionFactory.java
/** * Build the name of the method to set the parameter value of the given name. The * name of the method is build by preceding given parameter name with 'set' followed * by all letters of the name. In addition the first letter and all letters * following a '-' sign are converted to upper case. * //from ww w. j av a2 s. com * @param name The name of the parameter. * @return The name of the method to set the value of this parameter. */ public static String buildMethodName(final String name) { StringBuffer sb = new StringBuffer("set"); boolean first = true; for (int i = 0; i < name.length(); i++) { char chr = name.charAt(i); if (first && Character.isLowerCase(chr)) { sb.append(Character.toUpperCase(chr)); first = false; } else if (Character.isLetter(chr)) { sb.append(chr); first = false; } else if (chr == '-') { first = true; } } return sb.toString(); }
From source file:net.team2xh.crt.gui.editor.EditorTextPane.java
public EditorTextPane() { // Initialize highlighters lh = new LineHighlighter(Theme.getTheme().COLOR_13); ll = new LineHighlighter(Theme.getTheme().COLOR_14); wh = new WordHighlighter(Theme.getTheme().COLOR_11); eh = new ErrorHighlighter(Color.RED); // Initialise colors initAttributeSets();/*from w w w .j a v a 2 s. co m*/ setOpaque(false); // Background will be drawn later on setFont(font); doc = (DefaultStyledDocument) getDocument(); // Replace all tabs with four spaces // TODO: tab to next multiple of 4 column // TODO: tab whole selection // TODO: insert matching brace doc.setDocumentFilter(new DocumentFilter() { private String process(int offset, String text) { return text.replaceAll("\t", " ").replaceAll("\r", ""); } @Override public void insertString(FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException { super.insertString(fb, offset, process(offset, text), attr); } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attr) throws BadLocationException { super.replace(fb, offset, length, process(offset, text), attr); } }); // Highlight text when text changes doc.addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> highlightText()); changed = true; } @Override public void insertUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> highlightText()); changed = true; } @Override public void changedUpdate(DocumentEvent e) { } }); addCaretListener(new CaretListener() { private boolean isAlphanum(char c) { return Character.isDigit(c) || Character.isLetter(c); } private boolean isAlphanum(String s) { for (char c : s.toCharArray()) // Allow dots in middle of words for floats { if (c != '.' && !isAlphanum(c)) { return false; } } return true; } @Override public void caretUpdate(CaretEvent ce) { try { // Highlight current line highlightCurrentLine(); // Clear previously highlighted occurrences for (Object o : occurrences) { getHighlighter().removeHighlight(o); } repaint(); occurrences.clear(); // Get start and end offsets, swap them if necessary int s = ce.getDot(); int e = ce.getMark(); if (s > e) { s = s + e; e = s - e; s = s - e; } // If there is a selection, if (s != e) { // Check if the char on the left and on the right are not alphanums char f = s == 0 ? ' ' : doc.getText(s - 1, 1).charAt(0); char l = s == doc.getLength() - 1 ? ' ' : doc.getText(e, 1).charAt(0); if (!isAlphanum(f) && !isAlphanum(l)) { String word = doc.getText(s, e - s); if (isAlphanum(word)) { highlightOccurrences(word, s, e); } } } } catch (Exception e) { e.printStackTrace(); } } }); setCaretColor(Theme.getTheme().COLOR_11); highlightText(); }
From source file:eu.crisis_economics.configuration.ObjectReferenceExpression.java
public static List<String> isExpressionOfType(String rawExpression, FromFileConfigurationContext context) { String expression = rawExpression.trim(); if (expression.length() == 0) return null; boolean beginsWithLowercase = Character.isLowerCase(expression.charAt(0)); if (!beginsWithLowercase) return null; int endOfTypename = -1; for (int i = 0; i < expression.length(); ++i) { Character charNow = expression.charAt(i); if (Character.isLetter(charNow) || charNow == '_') continue; endOfTypename = i;//from www . j a v a 2 s . co m break; } if (endOfTypename == -1) return Arrays.asList(expression); // no indexing if (expression.charAt(endOfTypename) == '[') { if (expression.charAt(expression.length() - 1) != ']') return null; String typeDeclExpression = expression.substring(0, endOfTypename); String indexExpression = expression.substring(endOfTypename + 1, expression.length() - 1); if (IntegerPrimitiveExpression.isExpressionOfType(indexExpression, context) == null) return null; // with indexing return Arrays.asList(typeDeclExpression, indexExpression); } else return null; }
From source file:importer.filters.Filter.java
/** * Get the last word of a line excluding punctuation etc * @param line the line in question// w ww . j a va 2 s . c o m * @return the word */ protected String getLastWord(String text) { int len = text.length(); if (len > 0) { int start = 0; int size = 0, i = len - 1; // point beyond trailing hyphen if (len > 1 && text.endsWith("--")) { lastEndsInHyphen = true; return "--"; } else if (text.charAt(len - 1) == '-') { lastEndsInHyphen = true; len--; i--; } else { lastEndsInHyphen = false; // point to last non-space for (; i > 0; i--) { if (!Character.isWhitespace(text.charAt(i))) break; } } int j = i; for (; i > 0; i--) { if (!Character.isLetter(text.charAt(i))) { start = i + 1; size = j - i; break; } } if (i == 0) size = (j - i) + 1; return text.substring(start, start + size); } else return ""; }