List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:edu.illinois.cs.cogcomp.ner.StringStatisticsUtils.MyString.java
public static String normalizeDigits(String s) { StringBuilder res = new StringBuilder(s.length() * 2); for (int i = 0; i < s.length(); i++) { if (Character.isDigit(s.charAt(i))) { res.append("*D*"); } else {//w ww . j a va 2s. c o m res.append(s.charAt(i)); } } return res.toString(); }
From source file:com.autentia.common.util.ejb.JBossUtils.java
/** * Devuelve el nombre del ear en el que se encuentra la clase <code>clazz</code>. "" si no est en un ear. * <p>// www .ja v a 2 s .co m * Este mtodo esta probado para JBoss 4.2.2GA. * * @param clazz clase que se est buscando. * @return el nombre del ear en el que se encuentra la clase <code>clazz</code>. "" si no est en un ear. */ public static String getEarName(Class<?> clazz) { String cn = File.separator + clazz.getCanonicalName(); cn = cn.replace('.', File.separatorChar); cn += ".class"; final URL url = Thread.currentThread().getContextClassLoader().getResource(cn); final String path = url.getPath(); if (log.isDebugEnabled()) { log.debug(clazz.getCanonicalName() + " is in path: " + path); } final int indexOfEar = path.indexOf(".ear"); final int indexOfExclamationChar = path.indexOf("!"); if (indexOfEar > -1 && indexOfExclamationChar > -1 && indexOfEar < indexOfExclamationChar) { // JBoss despliega los ear en un directorio temporal del estilo: .../tmp34545nombreDelEar.ear-contents/... int beginTempDir = path.lastIndexOf(File.separatorChar, indexOfEar); int i = beginTempDir; boolean reachedDigit = false; while (i < indexOfEar) { if (Character.isDigit(path.charAt(i))) { reachedDigit = true; } else if (reachedDigit) { break; } i++; } final String prefix = path.substring(i, indexOfEar) + File.separator; log.debug(clazz.getCanonicalName() + " is inside ear: " + prefix); return prefix; } log.debug(clazz.getCanonicalName() + " is not inside an ear."); return ""; }
From source file:ca.uhn.fhir.rest.param.BaseParamWithPrefix.java
/** * Eg. if this is invoked with "gt2012-11-02", sets the prefix to GREATER_THAN and returns "2012-11-02" *///from www .j av a2s .c o m String extractPrefixAndReturnRest(String theString) { int offset = 0; while (true) { if (theString.length() == offset || Character.isDigit(theString.charAt(offset))) { break; } offset++; } String prefix = theString.substring(0, offset); myPrefix = ParamPrefixEnum.forValue(prefix); if (myPrefix == null) { myPrefix = ParamPrefixEnum.forDstu1Value(prefix); } return theString.substring(offset); }
From source file:Main.java
/** * Escapes all necessary characters in the String so that it can be used * in an XML doc./*from w w w.ja v a2 s. co m*/ * * @param string the string to escape. * @return the string with appropriate characters escaped. */ public static String escapeForXML(String string) { if (string == null) { return null; } char ch; int i = 0; int last = 0; char[] input = string.toCharArray(); int len = input.length; StringBuilder out = new StringBuilder((int) (len * 1.3)); for (; i < len; i++) { ch = input[i]; if (ch > '>') { } else if (ch == '<') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(LT_ENCODE); } else if (ch == '>') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(GT_ENCODE); } else if (ch == '&') { if (i > last) { out.append(input, last, i - last); } // Do nothing if the string is of the form ë (unicode value) if (!(len > i + 5 && input[i + 1] == '#' && Character.isDigit(input[i + 2]) && Character.isDigit(input[i + 3]) && Character.isDigit(input[i + 4]) && input[i + 5] == ';')) { last = i + 1; out.append(AMP_ENCODE); } } else if (ch == '"') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(QUOTE_ENCODE); } else if (ch == '\'') { if (i > last) { out.append(input, last, i - last); } last = i + 1; out.append(APOS_ENCODE); } } if (last == 0) { return string; } if (i > last) { out.append(input, last, i - last); } return out.toString(); }
From source file:net.prasenjit.auth.validation.StrongPasswordValidator.java
/** {@inheritDoc} */ @Override// w w w . j a va2 s . co m public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.hasText(value)) return true; int upperCount = 0; int specialCount = 0; int lowerCount = 0; int numericCount = 0; for (int i = 0; i < value.length(); i++) { char current = value.charAt(i); if (Character.isDigit(current)) numericCount = 1; if (Character.isUpperCase(current)) upperCount = 1; if (Character.isLowerCase(current)) lowerCount = 1; if (!Character.isLetterOrDigit(current)) specialCount = 1; } return upperCount + lowerCount + numericCount + specialCount >= 2; }
From source file:edu.stanford.muse.util.SloppyDates.java
private static Triple<Integer, Integer, Integer> parseDate(String s) { // separate into month and date // "jan10", "10jan", "jan 10" "10 jan" should all work s = s.toLowerCase();/* w w w . j a v a2 s . c o m*/ s = s.trim(); StringBuilder sb = new StringBuilder(); // detect when string changes from alpha to num or vice versa and ensure a whitespace there boolean prevCharDigit = false, prevCharLetter = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { sb.append(c); prevCharDigit = prevCharLetter = false; continue; } // treat apostrophe like a space if (c == '\'') { sb.append(' '); prevCharDigit = prevCharLetter = false; continue; } if (Character.isLetter(c)) { if (prevCharDigit) sb.append(' '); sb.append(c); prevCharLetter = true; prevCharDigit = false; } else if (Character.isDigit(c)) { if (prevCharLetter) sb.append(' '); sb.append(c); prevCharDigit = true; prevCharLetter = false; } else throw new RuntimeException(); } String newS = sb.toString(); log.info("string " + s + " parsed to " + newS); StringTokenizer st = new StringTokenizer(newS); int nTokens = st.countTokens(); if (nTokens == 0 || nTokens > 3) return new Triple<Integer, Integer, Integer>(-1, -1, -1); int mm = -1, dd = -1, yy = -1; while (st.hasMoreTokens()) { String token = st.nextToken(); boolean isNumber = true; int num = -1; try { num = Integer.parseInt(token); } catch (NumberFormatException nfe) { isNumber = false; } if (isNumber && num < 0) return new Triple<Integer, Integer, Integer>(-1, -1, -1); if (isNumber) { if (dd == -1 && num > 0 && num <= 31) dd = num; else if (yy == -1) { yy = num; if (yy < 100) { yy = (yy > 12) ? (1900 + yy) : (2000 + yy); } if (yy < 1900 || yy > 2015) return new Triple<Integer, Integer, Integer>(-1, -1, -1); } else return new Triple<Integer, Integer, Integer>(-1, -1, -1); } else { int x = SloppyDates.uniquePrefixIdx(token, monthNames); if (x >= 0 && mm == -1) mm = x; else return new Triple<Integer, Integer, Integer>(-1, -1, -1); } } return new Triple<Integer, Integer, Integer>(dd, mm, yy); }
From source file:Main.java
private static String tzid(String s) { int length = s.length(); if (length > 4) { char[] tzid = { 'G', 'M', 'T', 0, 0, 0, ':', 0, 0 }; s.getChars(length - 5, length - 2, tzid, 3); s.getChars(length - 2, length, tzid, 7); if ((tzid[3] == '+' || tzid[3] == '-') && Character.isDigit(tzid[4]) && Character.isDigit(tzid[5]) && Character.isDigit(tzid[7]) && Character.isDigit(tzid[8])) { return new String(tzid); }//w w w .j a v a2 s.c om } return null; }
From source file:Main.java
@Override public void replace(DocumentFilter.FilterBypass fp, int offset, int length, String string, AttributeSet aset) throws BadLocationException { int len = string.length(); boolean isValidInteger = true; for (int i = 0; i < len; i++) { if (!Character.isDigit(string.charAt(i))) { isValidInteger = false;//from ww w . j av a2s . c om break; } } if (isValidInteger) { super.replace(fp, offset, length, string, aset); } else { System.out.println("not valid integer"); } }
From source file:Main.java
/** * Checking whether a peer ID is Shadow style or not is a bit tricky. * //w ww. ja v a 2s . c o m * The BitTornado peer ID convention code is explained here: * http://forums.degreez.net/viewtopic.php?t=7070 * * The main thing we are interested in is the first six characters. * Although the other characters are base64 characters, there's no * guarantee that other clients which follow that style will follow * that convention (though the fact that some of these clients use * BitTornado in the core does blur the lines a bit between what is * "style" and what is just common across clients). * * So if we base it on the version number information, there's another * problem - there isn't the use of absolute delimiters (no fixed dash * character, for example). * * There are various things we can do to determine how likely the peer * ID is to be of that style, but for now, I'll keep it to a relatively * simple check. * * We'll assume that no client uses the fifth version digit, so we'll * expect a dash. We'll also assume that no client has reached version 10 * yet, so we expect the first two characters to be "letter,digit". * * We've seen some clients which don't appear to contain any version * information, so we need to allow for that. */ public static boolean isShadowStyle(String peer_id) { if (peer_id.charAt(5) != '-') { return false; } if (!Character.isLetter(peer_id.charAt(0))) { return false; } if (!(Character.isDigit(peer_id.charAt(1)) || peer_id.charAt(1) == '-')) { return false; } // Find where the version number string ends. int last_ver_num_index = 4; for (; last_ver_num_index > 0; last_ver_num_index--) { if (peer_id.charAt(last_ver_num_index) != '-') { break; } } // For each digit in the version string, check it is a valid version identifier. char c; for (int i = 1; i <= last_ver_num_index; i++) { c = peer_id.charAt(i); if (c == '-') { return false; } if (decodeAlphaNumericChar(c) == null) { return false; } } return true; }
From source file:com.google.dart.engine.services.refactoring.NamingConventions.java
/** * @return the {@link RefactoringStatus} with {@link RefactoringStatusSeverity#OK} if the name is * valid, {@link RefactoringStatusSeverity#WARNING} if the name is discouraged, or * {@link RefactoringStatusSeverity#ERROR} if the name is illegal. *///from w ww.java2s .c o m public static RefactoringStatus validateConstantName(String name) { // null if (name == null) { return RefactoringStatus.createErrorStatus("Constant name must not be null."); } // is not identifier RefactoringStatus status = validateIdentifier(name, "Constant"); if (!status.isOK()) { return status; } // is private, OK int startIndex = 0; if (name.charAt(0) == '_') { startIndex++; } // does not start with lower case for (int i = startIndex; i < name.length(); i++) { char c = name.charAt(i); if (!Character.isUpperCase(c) && !Character.isDigit(c) && c != '_') { return RefactoringStatus .createWarningStatus("Constant name should be all uppercase with underscores."); } } // OK return new RefactoringStatus(); }