List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:com.apress.prospringintegration.batch.UserRegistrationValidationItemProcessor.java
private String stripNonNumbers(String input) { String output = StringUtils.defaultString(input); StringBuffer numbersOnly = new StringBuffer(); for (char potentialDigit : output.toCharArray()) { if (Character.isDigit(potentialDigit)) { numbersOnly.append(potentialDigit); }/*from ww w . j a v a 2 s. com*/ } return numbersOnly.toString(); }
From source file:edu.illinois.cs.cogcomp.ner.StringStatisticsUtils.MyString.java
public static boolean hasDigits(String s) { for (int i = 0; i < s.length(); i++) if (Character.isDigit(s.charAt(i))) return true; return false; }
From source file:com.att.aro.console.util.ThrottleUtil.java
public int parseNumCvtUnit(String number) { int temp = -1; if (StringUtils.isNumericSpace(number)) { temp = Integer.parseInt(number); return temp; } else {//from www . j a v a2 s .c o m char unit = number.charAt(number.length() - 1); if ('m' == unit || 'M' == unit) { String subSt = number.substring(0, number.length() - 1); temp = Integer.parseInt(subSt); return temp * 1024; } else if ('k' == unit || 'K' == unit) { String subSt = number.substring(0, number.length() - 1); temp = Integer.parseInt(subSt); return temp; } else if (Character.isDigit(unit)) { temp = Integer.parseInt(number); return temp; } } return temp; }
From source file:NaturalOrderComparator.java
int compareRight(String a, String b) { int bias = 0; int ia = 0;/*w ww .j a va2 s. co m*/ int ib = 0; // The longest run of digits wins. That aside, the greatest // value wins, but we can't know that it will until we've scanned // both numbers to know that they have the same magnitude, so we // remember it in BIAS. for (;; ia++, ib++) { char ca = charAt(a, ia); char cb = charAt(b, ib); if (!Character.isDigit(ca) && !Character.isDigit(cb)) { return bias; } else if (!Character.isDigit(ca)) { return -1; } else if (!Character.isDigit(cb)) { return +1; } else if (ca < cb) { if (bias == 0) { bias = -1; } } else if (ca > cb) { if (bias == 0) bias = +1; } else if (ca == 0 && cb == 0) { return bias; } } }
From source file:com.daveayan.rjson.utils.RjsonUtil.java
public static Object getJsonObject(String json) throws JSONException { log.debug("getJsonObject for " + json); if (StringUtils.isEmpty(json)) { return ""; }// w w w .java 2s. c o m JSONTokener tokener = new JSONTokener(json); char firstChar = tokener.nextClean(); if (firstChar == '\"') { return tokener.nextString('\"'); } if (firstChar == '{') { tokener.back(); return new JSONObject(tokener); } if (firstChar == '[') { tokener.back(); return new JSONArray(tokener); } if (Character.isDigit(firstChar)) { tokener.back(); return tokener.nextValue(); } tokener.back(); return tokener.nextValue(); }
From source file:Main.java
/** * @param base// w w w . j a va2 s . com * @param set * @param title */ private static void compareTitleWithBase(String base, boolean bracketed, HashSet<Integer> set, String title) { // Check to see it the name starts with the prefix if (title.toLowerCase().startsWith(base.toLowerCase())) { // with brackets add on is: space, (, #, ) int minSizeNumAddOn = 4; if (!bracketed) // without brackets and space add on is just number minSizeNumAddOn = 1; // We found a possible auto-generated name // Determine number if (title.length() >= (base.length() + minSizeNumAddOn)) { String numPart; if (bracketed && title.charAt(base.length()) == ' ') { // We skipped the space since we already checked numPart = title.substring(base.length() + 1); } else if (!bracketed) { // without brackets, the numPart is everything after the prefix numPart = title.substring(base.length()); } else { // We are using brackets and there was no space return; } if (bracketed) { if (numPart.charAt(0) == '(') { // We are using brackets and confirmed that the open bracket exists // move on to just the number part numPart = numPart.substring(1); } else { // We are using brackets and there is no opening bracket return; } } // We found an auto-generated name StringBuffer buffer = new StringBuffer(); // Parse the number between the brackets for (int j = 0; j < numPart.length(); j++) { char current = numPart.charAt(j); // Make sure its a digit if (Character.isDigit(current)) { buffer.append(current); } else { if (!bracketed || numPart.charAt(j) != ')' || j != numPart.length() - 1) { // without brackets, a non digits means this will not conflict // with brackets, anything other than a ')' means this will not conflict // with brackets, if this is not the last character it will not conflict return; } // if all conditions passed, this is the last loop, no need to break } } // Convert the number we found into an actual number if (buffer.length() > 0) { set.add(new Integer(buffer.toString())); } } else { // No number to parse // Assume it is just base set.add(new Integer(0)); } } }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.CalculateUtil.java
/** * ? List// w w w . j a v a2 s. co m * * @param expression * @return list */ private static List<String> getStringList(String expression) { List<String> result = new ArrayList<>(); String num = ""; for (int i = 0; i < expression.length(); i++) { if (Character.isDigit(expression.charAt(i))) { num = num + expression.charAt(i); } else { if (!num.isEmpty()) { result.add(num); } result.add(expression.charAt(i) + ""); num = ""; } } if (!num.isEmpty()) { result.add(num); } return result; }
From source file:bhl.pages.handler.PagesDocumentsHandler.java
String concoctTitle(String docid) { StringBuilder className = new StringBuilder(); StringBuilder yearName = new StringBuilder(); StringBuilder author = new StringBuilder(); int state = 0; for (int i = 0; i < docid.length(); i++) { char token = docid.charAt(i); switch (state) { case 0: // looking for document classname if (Character.isDigit(token)) { yearName.append(token);/* w w w .j a va 2 s. c o m*/ state = 1; } else className.append(token); break; case 1: // looking for year if (Character.isDigit(token) && yearName.length() < 4) yearName.append(token); else state = 2; break; case 2: // looking for author if (Character.isLetter(token)) author.append(token); break; } } StringBuilder total = new StringBuilder(); total.append(author); total.append(" "); if (className.length() > 0 && className.charAt(className.length() - 1) == 's') className.setLength(className.length() - 1); total.append(className); total.append(" "); total.append(yearName); return total.toString(); }
From source file:example.app.core.convert.converter.StringToPhoneNumberConverter.java
protected String getDigits(String value) { StringBuilder buffer = new StringBuilder(); for (char character : nullSafeCharArray(value)) { if (Character.isDigit(character)) { buffer.append(character);/* www . ja v a2 s . c om*/ } } return buffer.toString(); }
From source file:biblivre3.marcutils.Indexer.java
public static String listIssn(Record record) { String retorno = ""; DataField dataField = MarcUtils.getDataField(record, MarcConstants.ISSN); if (dataField != null) { Subfield subField = dataField.getSubfield('a'); String isbn = subField != null ? subField.getData() : null; if (StringUtils.isNotBlank(isbn)) { if (Character.isDigit(isbn.charAt(0)) && (isbn.length() >= 10)) { retorno = isbn;// ww w. j a v a2 s . co m } } } return retorno; }