List of usage examples for java.lang Character isLetter
public static boolean isLetter(int codePoint)
From source file:org.nmrfx.processor.gui.RefManager.java
String getPropValue(int dim, String propName, boolean getDefault) { String dimName = "" + (dim + 1); String nameWithDim = propName + dimName; NMRData nmrData = getNMRData();/*from www . j av a 2s. com*/ if (nmrData == null) { return ""; } String value; if (!getDefault && refMap.containsKey(nameWithDim)) { value = refMap.get(nameWithDim).toString(); } else { switch (propName) { case "sw": value = nmrData.getSWNames()[dim]; break; case "skip": if (nmrData.getSize(dim) > 1) { value = "0"; } else { value = "1"; } break; case "tdsize": if (getDefault) { value = String.valueOf(nmrData.getSize(dim)); } else { value = "0"; } break; case "acqsize": if (getDefault) { value = String.valueOf(nmrData.getSize(dim)); } else { value = "0"; } break; case "acqarray": if (getDefault) { value = "0"; } else { value = "0"; } break; case "sf": value = nmrData.getSFNames()[dim]; break; case "label": value = nmrData.getLabelNames()[dim]; break; case "ref": if (dim == 0) { value = ""; } else { String tn = nmrData.getTN(dim); value = ""; for (int i = 0; i < tn.length(); i++) { if (Character.isLetter(tn.charAt(i))) { value = String.valueOf(tn.charAt(i)); } } } break; default: value = ""; } } return value; }
From source file:com.ing.connector.util.WStringUtil.java
/** * checkForZip --> uppercases the state code where appropriate *///from ww w .jav a 2 s .com private String checkForZip(String aString) { String lString = aString; String lStateSubString = null; int lLength = lString.length(); int lStateIndex = 0; boolean lHasStateCode = true; boolean lState = false; if (lLength >= 5) { for (int i = 0; i < lLength - 4; i++) { //various 5 char strings to test for zip codes String lZipSubString = lString.substring(i, (i + 5)); char[] lZipSubArray = lZipSubString.toCharArray(); boolean lZip = true; for (int j = 0; j < 5; j++) { if (!Character.isDigit(lZipSubArray[j])) { lZip = false; } } if (lZip) { if (i > 0) { String lPreZipSubString = lString.substring(0, i); if (lPreZipSubString.length() >= 2) { for (int k = lPreZipSubString.length() - 2; k >= 0; k--) { //various 2 char strings to test for state codes lStateSubString = lPreZipSubString.substring(k, (k + 2)); char[] lStateSubArray = lStateSubString.toCharArray(); lState = true; for (int m = 0; m < 2; m++) { if (!Character.isLetter(lStateSubArray[m])) { lState = false; } } if (lState) { //we have found a state code! lStateIndex = k; break; } } } if (lState) { if (lStateSubString.equalsIgnoreCase("AL") || lStateSubString.equalsIgnoreCase("AK") || lStateSubString.equalsIgnoreCase("AZ") || lStateSubString.equalsIgnoreCase("AR") || lStateSubString.equalsIgnoreCase("CA") || lStateSubString.equalsIgnoreCase("CO") || lStateSubString.equalsIgnoreCase("CT") || lStateSubString.equalsIgnoreCase("DE") || lStateSubString.equalsIgnoreCase("DC") || lStateSubString.equalsIgnoreCase("FL") || lStateSubString.equalsIgnoreCase("GA") || lStateSubString.equalsIgnoreCase("HI") || lStateSubString.equalsIgnoreCase("ID") || lStateSubString.equalsIgnoreCase("IL") || lStateSubString.equalsIgnoreCase("IN") || lStateSubString.equalsIgnoreCase("IA") || lStateSubString.equalsIgnoreCase("KS") || lStateSubString.equalsIgnoreCase("KY") || lStateSubString.equalsIgnoreCase("LA") || lStateSubString.equalsIgnoreCase("ME") || lStateSubString.equalsIgnoreCase("MD") || lStateSubString.equalsIgnoreCase("MA") || lStateSubString.equalsIgnoreCase("MI") || lStateSubString.equalsIgnoreCase("MN") || lStateSubString.equalsIgnoreCase("MS") || lStateSubString.equalsIgnoreCase("MO") || lStateSubString.equalsIgnoreCase("MT") || lStateSubString.equalsIgnoreCase("NE") || lStateSubString.equalsIgnoreCase("NV") || lStateSubString.equalsIgnoreCase("NH") || lStateSubString.equalsIgnoreCase("NJ") || lStateSubString.equalsIgnoreCase("NM") || lStateSubString.equalsIgnoreCase("NY") || lStateSubString.equalsIgnoreCase("NC") || lStateSubString.equalsIgnoreCase("ND") || lStateSubString.equalsIgnoreCase("OH") || lStateSubString.equalsIgnoreCase("OK") || lStateSubString.equalsIgnoreCase("OR") || lStateSubString.equalsIgnoreCase("PA") || lStateSubString.equalsIgnoreCase("PR") || lStateSubString.equalsIgnoreCase("RI") || lStateSubString.equalsIgnoreCase("SC") || lStateSubString.equalsIgnoreCase("SD") || lStateSubString.equalsIgnoreCase("TN") || lStateSubString.equalsIgnoreCase("TX") || lStateSubString.equalsIgnoreCase("UT") || lStateSubString.equalsIgnoreCase("VT") || lStateSubString.equalsIgnoreCase("VA") || lStateSubString.equalsIgnoreCase("WA") || lStateSubString.equalsIgnoreCase("WV") || lStateSubString.equalsIgnoreCase("WI") || lStateSubString.equalsIgnoreCase("WY")) { char[] lCharArray = lString.toCharArray(); lCharArray[lStateIndex] = Character.toUpperCase(lCharArray[lStateIndex]); lCharArray[lStateIndex + 1] = Character.toUpperCase(lCharArray[lStateIndex + 1]); lString = new String(lCharArray); } // if (lStateSubString.equalsIgnoreCase("AL") || ... } // if(lState) } // if(i > 0) } // if (lZip) } // for (int i=0; i < lLength - 4; i++) } // if(lLength >= 5) return lString; }
From source file:org.jraf.irondad.handler.pixgame.PixGameHandler.java
private static String rot13(String s) { int len = s.length(); StringBuilder res = new StringBuilder(len); for (int i = 0; i < len; i++) { char ch = s.charAt(i); if (!Character.isLetter(ch)) { res.append(ch);// w ww . j ava2s . com } else if (Character.isUpperCase(ch)) { res.append((char) ((ch - 'A' + 13) % 26 + 'A')); } else { res.append((char) ((ch - 'a' + 13) % 26 + 'a')); } } return res.toString(); }
From source file:pyromaniac.IO.MMFastaImporter.java
/** * _read sequence.// w ww . j a va2 s . co m * * @param pyrotagBlock the pyrotag block * @param pos the pos * @return the array list * @throws SeqFormattingException the seq formatting exception */ public ArrayList<Character> _readSequence(char[] pyrotagBlock, MutableInteger pos) throws SeqFormattingException { ArrayList<Character> characters = new ArrayList<Character>(); char curr; int index = pos.value(); while (index < pyrotagBlock.length) { curr = pyrotagBlock[index]; curr = Character.toUpperCase(curr); //reads are read in upper case if (Character.isLetter((char) curr)) { if (ACCEPTIBLE_IUPAC_CHARS.indexOf(curr) == -1) { throw new SeqFormattingException("Non-IUPAC character (" + curr + ") in sequence", this.seqFile); } else { characters.add(curr); } } index++; } pos.update(index); return characters; }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
/** * Create MultiProtocolURL/*w w w. j a v a 2 s . c om*/ * * decoding exception: if url string contains http url with char '%' the url string must be url encoded (percent-escaped) before * as internal encoding is skipped if url string contains '%'. * * @param url '%' char url encoded before * @throws MalformedURLException */ public MultiProtocolURL(String url) throws MalformedURLException { if (url == null) throw new MalformedURLException("url string is null"); this.hostAddress = null; this.contentDomain = null; // identify protocol url = url.trim(); if (url.startsWith("//")) { // patch for urls starting with "//" which can be found in the wild url = "http:" + url; } if (url.startsWith("\\\\")) { url = "smb://" + CommonPattern.BACKSLASH.matcher(url.substring(2)).replaceAll("/"); } if (url.length() > 1 && (url.charAt(1) == ':' && Character.isLetter(url.charAt(0)))) { // maybe a DOS drive path ( A: to z: ) url = "file://" + url; } if (url.length() > 0 && url.charAt(0) == '/') { // maybe a unix/linux absolute path url = "file://" + url; } int p = url.lastIndexOf("://", 5); // lastindexof to look only at the begin of url, up to "https://", if (p < 0) { if (url.length() > 7 && url.substring(0, 7).equalsIgnoreCase("mailto:")) { p = 6; } else { url = "http://" + url; p = 4; } } this.protocol = url.substring(0, p).toLowerCase(Locale.ROOT).trim().intern(); if (url.length() < p + 4) throw new MalformedURLException("URL not parseable: '" + url + "'"); if (!this.protocol.equals("file") && url.substring(p + 1, p + 3).equals("//")) { // identify host, userInfo and file for http and ftp protocol int q = url.indexOf('/', p + 3); if (q < 0) { // check for www.test.com?searchpart q = url.indexOf("?", p + 3); } else { // check that '/' was not in searchpart (example http://test.com?data=1/2/3) if (url.lastIndexOf("?", q) >= 0) { q = url.indexOf("?", p + 3); } } if (q < 0) { // check for www.test.com#fragment q = url.indexOf("#", p + 3); } int r; if (q < 0) { if ((r = url.indexOf('@', p + 3)) < 0) { this.host = url.substring(p + 3).intern(); this.userInfo = null; } else { this.host = url.substring(r + 1).intern(); this.userInfo = url.substring(p + 3, r); } this.path = "/"; } else { this.host = url.substring(p + 3, q).trim().intern(); if ((r = this.host.indexOf('@')) < 0) { this.userInfo = null; } else { this.userInfo = this.host.substring(0, r); this.host = this.host.substring(r + 1).intern(); } this.path = url.substring(q); // may result in "?searchpart" (resolveBackpath prepends a "/" ) } if (this.host.length() < 4 && !this.protocol.equals("file")) throw new MalformedURLException("host too short: '" + this.host + "', url = " + url); if (this.host.indexOf('&') >= 0) throw new MalformedURLException("invalid '&' in host"); this.path = resolveBackpath(this.path); // adds "/" if missing identPort(url, (isHTTP() ? 80 : (isHTTPS() ? 443 : (isFTP() ? 21 : (isSMB() ? 445 : -1))))); if (this.port < 0) { // none of known protocols (above) = unknown throw new MalformedURLException("unknown protocol: " + url); } identAnchor(); identSearchpart(); escape(); } else { url = UTF8.decodeURL(url); // normalization here // this is not a http or ftp url if (this.protocol.equals("mailto")) { // parse email url final int q = url.indexOf('@', p + 3); if (q < 0) { throw new MalformedURLException("wrong email address: " + url); } this.userInfo = url.substring(p + 1, q); this.host = url.substring(q + 1); this.path = ""; // TODO: quick fix, as not always checked for path != null this.port = -1; this.searchpart = null; this.anchor = null; } else if (this.protocol.equals("file")) { // parse file url (RFC 1738 file://host.domain/path file://localhost/path file:///path) // example unix file://localhost/etc/fstab // file:///etc/fstab // example windows file://localhost/c|/WINDOWS/clock.avi // file:///c|/WINDOWS/clock.avi // file://localhost/c:/WINDOWS/clock.avi // network file://hostname/path/to/the%20file.txt // local file:///c:/path/to/the%20file.txt String h = url.substring(p + 1); this.host = null; // host is ignored on file: protocol if (h.startsWith("///")) { //absolute local file path // no host given this.path = h.substring(2); // "/path" or "/c:/path" } else if (h.startsWith("//")) { // "//host/path" or "//host/c:/path" if (h.length() > 4 && h.charAt(3) == ':' && h.charAt(4) != '/' && h.charAt(4) != '\\') { // wrong windows path, after the doublepoint there should be a backslash. Let's add a slash, as it will be slash in the normal form h = h.substring(0, 4) + '/' + h.substring(4); } int q = h.indexOf('/', 2); if (q < 0 || h.length() > 3 && h.charAt(3) == ':') { // Missing root slash such as "path" or "c:/path" accepted, but the path attribute must by after all start with it this.path = "/" + h.substring(2); } else { this.host = h.substring(2, q); // TODO: handle "c:" ? if (this.host.equalsIgnoreCase(Domains.LOCALHOST)) this.host = null; this.path = h.substring(q); // "/path" } } else if (h.startsWith("/")) { // "/host/path" or "/host/c:/path" this.path = h; } this.userInfo = null; this.port = -1; this.searchpart = null; this.anchor = null; } else { throw new MalformedURLException("unknown protocol: " + url); } } // handle international domains if (!Punycode.isBasic(this.host)) try { this.host = toPunycode(this.host); } catch (final PunycodeException e) { } }
From source file:org.wso2.carbon.governance.generic.ui.utils.GenericUtil.java
private static String convertName(String[] nameParts) { String convertedName = null;// w w w. ja va 2 s . c o m // making widget name camel case for (String namePart : nameParts) { int i; for (i = 0; i < namePart.length(); i++) { char c = namePart.charAt(i); if (!Character.isLetter(c) || Character.isLowerCase(c)) { break; } } if (namePart.equals(nameParts[0])) { namePart = namePart.substring(0, i).toLowerCase() + namePart.substring(i); } if (convertedName == null) { convertedName = namePart; } else { convertedName += namePart; } } return convertedName; }
From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java
/** * The IRI-safe version of a string is obtained by applying the following * transformation in [RFC3987]./* w w w . j av a2 s.co m*/ * * @throws R2RMLDataError * @throws MalformedURLException */ public static String getIRISafeVersion(String value) { // Any character that is not in the iunreserved production // iunreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" / ucschar StringBuffer buff = new StringBuffer(value.length()); Set<Character> unreservedChars = new HashSet<Character>(); unreservedChars.add('-'); unreservedChars.add('.'); unreservedChars.add('_'); unreservedChars.add('~'); unreservedChars.add('*'); unreservedChars.add('\''); unreservedChars.add('('); unreservedChars.add(')'); unreservedChars.add('!'); unreservedChars.add('='); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (!(Character.isDigit(c) || Character.isLetter(c) || unreservedChars.contains(c))) { // Percent-encode each octet buff.append('%'); buff.append(Integer.toHexString(c).toUpperCase()); } else { buff.append(c); } } return buff.toString(); }
From source file:com.kyleszombathy.sms_scheduler.Home.java
/**Retreieves bitmap from database*/ // TODO: Move this off the UI thread private void setContactImages() { for (int msgIndex = 0; msgIndex < messages.size(); msgIndex++) { Message message = messages.get(msgIndex); ArrayList<Uri> uriList = message.getUriList(); Bitmap contactPhoto = null;/*from w ww. j a v a 2 s.c om*/ if (uriList != null && uriList.size() == 1 && uriList.get(0) != null && !uriList.get(0).toString().equals("null")) { contactPhoto = retrieveContactImage(uriList.get(0)); } else if (message.getNameList().size() == 1) { // Set custom contact image based off first letter of contact name String firstName = message.getNameList().get(0); // Ensure character is not a number if (Character.isLetter(firstName.charAt(0))) { contactPhoto = createCircleImageFromFirstLetterOfName(firstName); Log.i(TAG, "setContactImages: Created custom image based off first letter: " + firstName.charAt(0)); } } message.setContactPhoto(contactPhoto); messages.setPhotoDataset(msgIndex); } }
From source file:com.evanmclean.evlib.text.FuzzyCompare.java
/** * Returns true if the word meets the minimum length, is not an ignored word, * and contains at least one letter.//ww w . j av a 2 s . com * * @param word * @return */ private boolean goodWord(final String word) { final int len = word.length(); if (len < minimumWordLength) return false; if (ignoredWords.contains(word)) return false; for (int xi = 0; xi < len; ++xi) if (Character.isLetter(word.charAt(xi))) return true; return false; }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyTyped(KeyEvent e) { LOGGER.debug("key typed event caught " + e.getKeyCode()); char ch = e.getKeyChar(); if (ch == '\n') { // this case is handled at keyPressed(e) return;/*from w w w . ja v a2 s .c om*/ } if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { JTextComponent comp = (JTextComponent) e.getSource(); if (toSetIn == null) { LOGGER.debug("toSetIn is null"); } else { LOGGER.debug("toSetIn: >" + toSetIn + '<'); } // The case-insensitive system is a bit tricky here // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { // User continues on the word that was suggested. LOGGER.debug("cont"); toSetIn = toSetIn.substring(1); if (!toSetIn.isEmpty()) { int cp = comp.getCaretPosition(); //comp.setCaretPosition(cp+1-toSetIn.); //System.out.println(cp-toSetIn.length()+" - "+cp); comp.select((cp + 1) - toSetIn.length(), cp); lastBeginning = lastBeginning + ch; e.consume(); lastCaretPosition = comp.getCaretPosition(); //System.out.println("Added char: '"+toSetIn+"'"); //System.out.println("LastBeginning: '"+lastBeginning+"'"); lastCompletions = findCompletions(lastBeginning, comp); lastShownCompletion = 0; for (int i = 0; i < lastCompletions.length; i++) { String lastCompletion = lastCompletions[i]; //System.out.println("Completion["+i+"] = "+lastCompletion); if (lastCompletion.endsWith(toSetIn)) { lastShownCompletion = i; break; } } //System.out.println("Index now: "+lastShownCompletion); if (toSetIn.length() < 2) { // User typed the last character of the autocompleted word // We have to replace the automcompletion word by the typed word. // This helps if the user presses "space" after the completion // "space" indicates that the user does NOT want the autocompletion, // but the typed word String text = comp.getText(); comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning + text.substring(lastCaretPosition)); // there is no selected text, therefore we are not updating the selection toSetIn = null; } return; } } if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { // User discontinues the word that was suggested. lastBeginning = lastBeginning + ch; LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); String[] completed = findCompletions(lastBeginning, comp); if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[0]; // toSetIn = string used for autocompletion last time // this string has to be removed // lastCaretPosition is the position of the caret after toSetIn. int lastLen = toSetIn.length() - 1; toSetIn = sno.substring(lastBeginning.length() - 1); String text = comp.getText(); //Util.pr(""+lastLen); //we do not use toSetIn as we want to obey the casing of "sno" comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno + text.substring(lastCaretPosition)); int startSelect = (lastCaretPosition + 1) - lastLen; int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; comp.select(startSelect, endSelect); lastCaretPosition = comp.getCaretPosition(); e.consume(); return; } else { setUnmodifiedTypedLetters(comp, true, false); e.consume(); toSetIn = null; return; } } LOGGER.debug("case else"); comp.replaceSelection(""); StringBuffer currentword = getCurrentWord(comp); if (currentword == null) { currentword = new StringBuffer(); } // only "real characters" end up here assert (!Character.isISOControl(ch)); currentword.append(ch); startCompletion(currentword, e); return; } else { if (Character.isWhitespace(ch)) { assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); resetAutoCompletion(); return; } LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); resetAutoCompletion(); return; } } resetAutoCompletion(); }