List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:nl.ru.cmbi.vase.parse.StockholmParser.java
private static String getPDBRepresentation(PDBResidueInfo pdbResInfo) { String pdbno = pdbResInfo.getResidueNumber(); char finalPDBnoChar = pdbno.charAt(pdbno.length() - 1); if (Character.isLetter(finalPDBnoChar)) { // there's an insertion code, convert it's notation to jmol syntax pdbno = pdbno.substring(0, pdbno.length() - 1) + "^" + finalPDBnoChar; }/*www . j a v a 2s. c o m*/ return String.format("[%s]%s:%c", pdbResInfo.getResidueName(), pdbno, pdbResInfo.getChain()); }
From source file:BayesianAnalyzer.java
private String nextToken(Reader reader) throws java.io.IOException { StringBuffer token = new StringBuffer(); int i;/*w w w .jav a 2s . c om*/ char ch, ch2; boolean previousWasDigit = false; boolean tokenCharFound = false; if (!reader.ready()) { return null; } while ((i = reader.read()) != -1) { ch = (char) i; if (ch == ':') { String tokenString = token.toString() + ':'; if (tokenString.equals("From:") || tokenString.equals("Return-Path:") || tokenString.equals("Subject:") || tokenString.equals("To:")) { return tokenString; } } if (Character.isLetter(ch) || ch == '-' || ch == '$' || ch == '\u20AC' // the EURO symbol || ch == '!' || ch == '\'') { tokenCharFound = true; previousWasDigit = false; token.append(ch); } else if (Character.isDigit(ch)) { tokenCharFound = true; previousWasDigit = true; token.append(ch); } else if (previousWasDigit && (ch == '.' || ch == ',')) { reader.mark(1); previousWasDigit = false; i = reader.read(); if (i == -1) { break; } ch2 = (char) i; if (Character.isDigit(ch2)) { tokenCharFound = true; previousWasDigit = true; token.append(ch); token.append(ch2); } else { reader.reset(); break; } } else if (ch == '\r') { // cr found, ignore } else if (ch == '\n') { // eol found tokenCharFound = true; previousWasDigit = false; token.append(ch); break; } else if (tokenCharFound) { break; } } if (tokenCharFound) { // System.out.println("Token read: " + token); return token.toString(); } else { return null; } }
From source file:org.globus.gatekeeper.jobmanager.AbstractJobManager.java
private static boolean isAbsolutePath(String path) { int length = path.length(); return ((length > 1 && path.charAt(0) == '/') || (length > 2 && path.charAt(1) == ':' && Character.isLetter(path.charAt(0)))); }
From source file:CharUtils.java
/** * True if all letters in a string are uppercase. * /*from w ww . j ava 2s .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:nl.ru.cmbi.vase.parse.StockholmParser.java
private static String getPDBRepresentation(Alignment alignment, char chainID, ResidueInfoSet residueInfoSet, List<PDBResidueInfo> pdbResidues, int columnIndex) { String alignedPDBSeq = getAlignedPDBSeq(alignment); ResidueInfo res = getResidueInfoFor(alignment, chainID, residueInfoSet, columnIndex); if (res != null) { String pdbno = res.getPdbNumber(); char finalPDBnoChar = pdbno.charAt(pdbno.length() - 1); if (Character.isLetter(finalPDBnoChar)) { // there's an insertion code, convert it's notation to jmol syntax pdbno = pdbno.substring(0, pdbno.length() - 1) + "^" + finalPDBnoChar; }/*from w w w.j a va2 s . c o m*/ return String.format("[%s]%s:%c", AminoAcid.aa1to3(alignedPDBSeq.charAt(columnIndex)), pdbno, alignment.getChainID()); } else return ""; // If it's a gap }
From source file:UrlUtils.java
private static boolean isValidScheme(final String scheme) { final int length = scheme.length(); if (length < 1) { return false; }//from w w w .j a v a2s .co m char c = scheme.charAt(0); if (!Character.isLetter(c)) { return false; } for (int i = 1; i < length; i++) { c = scheme.charAt(i); if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' && c != '-') { return false; } } return true; }
From source file:org.apache.oozie.executor.jpa.WorkflowsJobGetJPAExecutor.java
private Date parseCreatedTimeString(String time) throws Exception { Date createdTime = null;/*from ww w . j a va 2 s .c o m*/ int offset = 0; if (Character.isLetter(time.charAt(time.length() - 1))) { switch (time.charAt(time.length() - 1)) { case 'd': offset = Integer.parseInt(time.substring(0, time.length() - 1)); if (offset > 0) { throw new IllegalArgumentException("offset must be minus from currentTime."); } createdTime = org.apache.commons.lang.time.DateUtils.addDays(new Date(), offset); break; case 'h': offset = Integer.parseInt(time.substring(0, time.length() - 1)); if (offset > 0) { throw new IllegalArgumentException("offset must be minus from currentTime."); } createdTime = org.apache.commons.lang.time.DateUtils.addHours(new Date(), offset); break; case 'm': offset = Integer.parseInt(time.substring(0, time.length() - 1)); if (offset > 0) { throw new IllegalArgumentException("offset must be minus from currentTime."); } createdTime = org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), offset); break; case 'Z': createdTime = DateUtils.parseDateUTC(time); break; default: throw new IllegalArgumentException( "Unsupported time format: " + time + StoreStatusFilter.TIME_FORMAT); } } else { throw new IllegalArgumentException( "The format of time is wrong: " + time + StoreStatusFilter.TIME_FORMAT); } return createdTime; }
From source file:com.commander4j.util.JUtility.java
/** * Method capitaliseAll./* w w w . jav a 2 s.c o m*/ * * @param str * String * @return String */ public static String capitaliseAll(String str) { String result = ""; char ch; // One of the characters in str. char prevCh; // The character that comes before ch in the string. int i; // A position in str, from 0 to str.length()-1. if (str != null) { prevCh = '.'; // Prime the loop with any non-letter character. for (i = 0; i < str.length(); i++) { ch = str.charAt(i); if (Character.isLetter(ch) && !Character.isLetter(prevCh)) { result = result + Character.toUpperCase(ch); } else { result = result + ch; } prevCh = ch; // prevCh for next iteration is ch. } } return result; }
From source file:org.opensextant.util.TextUtils.java
/** * Measure character count, upper, lower, non-Character, whitespace * /* w w w .j a v a2 s . 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:com.basetechnology.s0.agentserver.util.XmlUtils.java
public Value parseXml(ScriptState scriptState, String xmlString, boolean unqiuelyNameRepeatedElements, boolean ignoreAttributes) throws RuntimeException { this.xmlString = xmlString; this.len = xmlString.length(); this.nextCharIndex = 0; this.elementNames = new ArrayList<String>(); this.elementValues = new ArrayList<Value>(); this.elementNameCounters = new ArrayList<Map<String, Integer>>(); this.unqiuelyNameRepeatedElements = unqiuelyNameRepeatedElements; this.ignoreAttributes = ignoreAttributes; // Start with empty stack elementNames.add("<top>"); elementNameCounters.add(new HashMap<String, Integer>()); elementValues.add(NullValue.one);//from ww w. j a v a 2s. c o m char ch = getChar(); nextItem = new StringBuilder(); while (ch != 0) { ch = getChar(); if (ch == '<') { ch = getNextChar(); if (ch == '?') { // Parse <? ... /> directive ch = getNextChar(); while (ch != 0 && !(ch == '?' && peekChar(1) == '>')) ch = getNextChar(); // Skip over end of the directive ch = getNextChar(); ch = getNextChar(); } else if (ch == '/') { // End of an element // Skip over the '/' ch = getNextChar(); // Parse the element name String elementName = ""; while (ch != 0 && ch != '>') { elementName += ch; ch = getNextChar(); } // Skip the '> ending the end of the element if (ch == '>') ch = getNextChar(); // Process the whole element now processEndElement(scriptState, elementName); } else { // start of a new element // Parse the element name String elementName = ""; while (ch != 0 && ch != ' ' && ch != '>') { elementName += ch; ch = getNextChar(); } // Parse the element attributes List<FieldValue> attributeValues = new ArrayList<FieldValue>(); char lastCh = 0; ch = getNonBlankChar(); while (ch != 0 && ch != '>') { // Parse the attribute name if (!Character.isLetter(ch)) { // Skip junk lastCh = ch; ch = getNextNonBlankChar(); continue; } StringBuilder attributeNameBuilder = new StringBuilder(); while (ch != 0 && ch != '>' && ch != '=' && ch != ' ') { attributeNameBuilder.append(ch); ch = getNextChar(); } String attributeName = attributeNameBuilder.toString(); // Skip white space ch = getNonBlankChar(); // Parse the '=' and skip any white space if (ch != '=') { // TODO: What to do here for error recovery? } ch = getNextNonBlankChar(); // Parse the attribute value StringBuilder attributeValueBuilder = new StringBuilder(); if (ch == '"') { // Parse the quoted string attribute value ch = getNextChar(); while (ch != 0 && ch != '>' && ch != '"') { if (ch == '\\') ch = getNextChar(); attributeValueBuilder.append(ch); ch = getNextChar(); } // Skip over the closing '"' if (ch == '"') ch = getNextChar(); } else { // Parse the non-quoted attribute value attributeValueBuilder.append(ch); while (ch != 0 && ch != '>' && ch != '=' && ch != ' ') { attributeValueBuilder.append(ch); ch = getNextChar(); } } String attributeValue = unescapeEntities(attributeValueBuilder.toString()); // Store the attribute value FieldValue attributeFieldValueNode = new FieldValue(attributeName, new StringValue(attributeValue)); attributeValues.add(attributeFieldValueNode); // Peek at the next non-white space character after this attribute lastCh = ch; ch = getNonBlankChar(); } // Skip the '> ending the start of the element if (ch == '>') ch = getNextChar(); // Push the new element name on the stack elementNames.add(elementName); // Initialize its text counter elementNameCounters.add(new HashMap<String, Integer>()); // Push the attribute map, or null if no attributes if (attributeValues.size() > 0 && !ignoreAttributes) elementValues.add(new MapValue(ObjectTypeNode.one, (List<Value>) (Object) attributeValues)); else elementValues.add(NullValue.one); // If there is unassociated text floating around, place it into a text element if (nextItem.toString().trim().length() > 0) processUnassociatedText(scriptState); // Start accumulating text for the new element nextItem = new StringBuilder(); // For attribute-only element (ends with "/>"), need to store its value now if (lastCh == '/') { // Process the whole element now processEndElement(scriptState, elementName); } } } else { // Save this character of element text and move on to the next character nextItem.append(ch); ch = getNextChar(); } } // If there is unassociated text floating around, place it into a text element if (nextItem.toString().trim().length() > 0) processUnassociatedText(scriptState); // Return the value on the top of the stack return elementValues.remove(elementValues.size() - 1); }