List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java
private boolean isUnicode(String control) { return control.length() > 1 && control.charAt(0) == UNICODE && Character.isDigit(control.charAt(1)); }
From source file:BayesianAnalyzer.java
private String nextToken(Reader reader) throws java.io.IOException { StringBuffer token = new StringBuffer(); int i;/*from w ww . j a v a2s . com*/ 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:com.florian.chess.pgn.SimplePgnParser.java
/** * Move numbers are in the format 1. or 1... If wordToken isn't a move * number or doesn't start with a move number then null is returned. * Otherwise if it contains a move number and nothing else then a String[1] * is returned with the move number stripped of all '.'s. Otherwise a * String[2] is returned where index 0 is the move number with '.' stripped * and index 1 is the rest of the word token. *///www. j av a 2 s.c o m private String[] splitOutGameMoveNumber(String wordToken) { if (Character.isDigit(wordToken.charAt(0))) { // Remove the . or ... int firstDotIndex = wordToken.indexOf('.'); if (firstDotIndex != -1) { int firstThreeDotIndex = wordToken.indexOf("..."); if (firstThreeDotIndex != -1) { if (wordToken.length() > firstThreeDotIndex + 3) { return new String[] { wordToken.substring(0, firstThreeDotIndex), wordToken.substring(firstThreeDotIndex + 3) }; } else { return new String[] { wordToken.substring(0, firstThreeDotIndex) }; } } else { if (wordToken.length() > firstDotIndex + 1) { return new String[] { wordToken.substring(0, firstDotIndex), wordToken.substring(firstDotIndex + 1) }; } else { return new String[] { wordToken.substring(0, firstDotIndex) }; } } } } return null; }
From source file:com.mirth.connect.plugins.datatypes.delimited.DelimitedBatchAdaptor.java
private void updateGroupingColumnIndex(String batchGroupingColumn, String[] columnNames) { if (groupingColumnIndex == null) { // Default groupingColumnIndex = -1;//from w w w . j av a2s .co m // If there is a batch grouping column name if (StringUtils.isNotEmpty(batchGroupingColumn)) { // If we can't resolve the grouping column name, it'll default to the first column (index=0) groupingColumnIndex = 0; // If there are no user specified column names if (columnNames == null) { // Try to parse the index from the end of a default column name // e.g. "column24" => index = 23 int index = batchGroupingColumn.length() - 1; int len = 0; while (index >= 0 && Character.isDigit(batchGroupingColumn.charAt(index))) { index--; len++; } if (len > 0) { try { groupingColumnIndex = Integer.valueOf(batchGroupingColumn .substring(batchGroupingColumn.length() - len, batchGroupingColumn.length())) - 1; } catch (NumberFormatException e) { logger.warn( "Invalid number format in Split Batch by Grouping Column (defaulting to first column): " + batchGroupingColumn.substring(batchGroupingColumn.length() - len, batchGroupingColumn.length())); } } else { logger.warn("Unknown batch grouping column (defaulting to first column): " + batchGroupingColumn); } } else { // Try to find the grouping column name in the user specified column names int i; for (i = 0; i < columnNames.length; i++) { if (columnNames[i].equals(batchGroupingColumn)) { groupingColumnIndex = i; break; } } if (i == columnNames.length) { logger.warn("Unknown batch grouping column (defaulting to first column): " + batchGroupingColumn); } } } } }
From source file:com.prowidesoftware.swift.model.Tag.java
/** * Iterate the current tagname and return only number as told by {@link Character#isDigit(char)} * /*from ww w .j a v a2 s . co m*/ * @return an integer containing the numeric of the tagname or <code>null</code> if no digits are found * @since 6.2 */ public Integer getNumber() { if (this.name != null) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.name.length(); i++) { char c = this.name.charAt(i); if (Character.isDigit(c)) { sb.append(c); } } if (sb.length() > 0) { return Integer.parseInt(sb.toString()); } } return null; }
From source file:RankingMIDlet.java
public String gatherNumber() throws IOException { StringBuffer sb = new StringBuffer(); boolean gotNumeric = false; for (;;) {//from w w w. j a v a 2 s .c o m char c = getNext(); // Skip until we find a digit. boolean isDigit = Character.isDigit(c); if (!gotNumeric && !isDigit) { continue; } gotNumeric = true; if (!isDigit) { if (c == '.' || c == ',') { continue; } break; } sb.append(c); } return sb.toString(); }
From source file:com.aw.swing.mvp.binding.component.support.ColumnInfo.java
private int getIndexFromFieldName(int index) { if (fieldName != null && fieldName.length() > 0 && Character.isDigit(fieldName.charAt(0))) { index = Integer.parseInt(fieldName); }/*from ww w . ja v a2 s.c o m*/ return index; }
From source file:com.dgtlrepublic.anitomyj.ParserNumber.java
/** * Match partial episodes episodes. "4a", "111C". * * @param word the word/*from w ww. j a v a2 s . co m*/ * @param token the token * @return true if the token matched */ public boolean matchPartialEpisodePattern(String word, Token token) { if (StringUtils.isEmpty(word)) return false; int foundIdx = IntStream.rangeClosed(0, word.length()) .filter(value -> !Character.isDigit(word.charAt(value))).findFirst().orElse(word.length()); int suffixLength = word.length() - foundIdx; Function<Integer, Boolean> isValidSuffix = c -> (c >= 'A' && c <= 'C') || (c >= 'a' && c <= 'c'); if (suffixLength == 1 && isValidSuffix.apply((int) word.charAt(foundIdx))) if (setEpisodeNumber(word, token, true)) return true; return false; }
From source file:DateUtils.java
/** * Parse date time value from given string resolving any functions or formulas * the string can contain. This method can be therefore used if the passed * string contains string representation date, time or timestamp or a formula * such as now + 3h - 1m + 4d. // ww w. java2 s. c o m * * @param strValue - string representation of date or date function * @param iDateType - date type code, one of the DATE_TYPE_XXX constants * @param stored - flag if Date should be parsed using format used for * storage or for display * @return Timestamp - parsed date or null if date was null * @throws OSSInvalidDataException - error during parsing */ public static Timestamp parseDateTime(String strValue, int iDateType, boolean stored) { Timestamp tsReturn = null; Calendar workCal = GregorianCalendar.getInstance(); if (strValue != null && strValue.length() > 0) { strValue = strValue.trim(); if (strValue.startsWith(CURRENT_DATE_CODE)) { strValue = strValue.replaceAll("[ ]", ""); // If the user specified "UseCurrent", then substitute the // current date/time in the value workCal.setTime(new Date()); // Log.getInstance().debug("Parsing current date " + strValue); // Parse the date math int iBeginIndex = CURRENT_DATE_CODE.length(); int iMaxLength = strValue.length(); int iSign = 1; int iNumberIndex; int iValue; char cChar = ' '; while (iBeginIndex < iMaxLength) { // This has to be sign if (strValue.charAt(iBeginIndex) == '+') { iSign = 1; } else if (strValue.charAt(iBeginIndex) == '-') { iSign = -1; } else { // Incorrect String throw new RuntimeException("Date function is in incorrect format: " + strValue + " at " + strValue.substring(iBeginIndex)); } iBeginIndex++; // Now we have to have number iNumberIndex = iBeginIndex; while (((iBeginIndex == iNumberIndex) || Character.isDigit(cChar)) && (iBeginIndex < iMaxLength)) { cChar = strValue.charAt(iBeginIndex++); } // We have to go one back because we should stop on modifier (e.g 1m) iBeginIndex--; try { iValue = Integer.parseInt(strValue.substring(iNumberIndex, iBeginIndex)); } catch (NumberFormatException nmeExc) { // Incorrect String throw new RuntimeException("Date function is in incorrect format: " + strValue + " at " + strValue.substring(iNumberIndex)); } // This has to be modifier: y - year, M - month, w - week, // d - day, h - hour, m - minute, s - second cChar = strValue.charAt(iBeginIndex); switch (cChar) { case (YEAR_CODE): { if (iDateType == DATE_TYPE_TIME) { throw new RuntimeException( "Date function is in incorrect format: " + "used YEAR modifier for TIME type"); } workCal.add(Calendar.YEAR, iSign * iValue); break; } case (MONTH_CODE): { if (iDateType == DATE_TYPE_TIME) { throw new RuntimeException( "Date function is in incorrect format: " + "used MONTH modifier for TIME type"); } workCal.add(Calendar.MONTH, iSign * iValue); break; } case (WEEK_CODE): { if (iDateType == DATE_TYPE_TIME) { throw new RuntimeException( "Date function is in incorrect format: " + "used WEEK modifier for TIME type"); } workCal.add(Calendar.WEEK_OF_YEAR, iSign * iValue); break; } case (DAY_CODE): { if (iDateType == DATE_TYPE_TIME) { throw new RuntimeException( "Date function is in incorrect format: " + "used DAY modifier for TIME type"); } workCal.add(Calendar.DATE, iSign * iValue); break; } case (HOUR_CODE): { if (iDateType == DATE_TYPE_DATE) { throw new RuntimeException( "Date function is in incorrect format: " + "used HOUR modifier for DATE type"); } workCal.add(Calendar.HOUR, iSign * iValue); break; } case (MINUTE_CODE): { if (iDateType == DATE_TYPE_DATE) { throw new RuntimeException("Date function is in incorrect format: " + "used MINUTE modifier for DATE type"); } workCal.add(Calendar.MINUTE, iSign * iValue); break; } case (SECOND_CODE): { if (iDateType == DATE_TYPE_DATE) { throw new RuntimeException("Date function is in incorrect format: " + "used SECOND modifier for DATE type"); } workCal.add(Calendar.SECOND, iSign * iValue); break; } default: { // Incorrect String throw new RuntimeException("Date function is in incorrect format: " + strValue + " at " + strValue.substring(iBeginIndex)); } } iBeginIndex++; } tsReturn = new Timestamp(workCal.getTimeInMillis()); } else { try { if (stored) { switch (iDateType) { case (DATE_TYPE_DATE): { tsReturn = new Timestamp(DATE_STORE_FORMAT.parse(strValue).getTime()); break; } case (DATE_TYPE_TIME): { tsReturn = new Timestamp(TIME_STORE_FORMAT.parse(strValue).getTime()); break; } case (DATE_TYPE_DATETIME): { tsReturn = new Timestamp(DATETIME_STORE_FORMAT.parse(strValue).getTime()); break; } default: { assert false : "Unknown date type " + iDateType; } } } else { switch (iDateType) { case (DATE_TYPE_DATE): { tsReturn = new Timestamp(DATE_FORMAT.parse(strValue).getTime()); break; } case (DATE_TYPE_TIME): { tsReturn = new Timestamp(TIME_FORMAT.parse(strValue).getTime()); break; } case (DATE_TYPE_DATETIME): { tsReturn = new Timestamp(DATETIME_FORMAT.parse(strValue).getTime()); break; } default: { assert false : "Unknown date type " + iDateType; } } } } catch (ParseException peExc) { throw new RuntimeException("Date is in incorrect format. Problems with parsing.", peExc); } } } return tsReturn; }
From source file:edu.cornell.mannlib.vedit.util.Stemmer.java
public static String StemString(String inputStr, int maxLength) { String outputStr = ""; int previousCh = 0; char[] w = new char[maxLength]; char[] inputArray = inputStr.toCharArray(); Stemmer s = new Stemmer(); int inputArrayIndex = 0, stemmerInputBufferIndex = 0, ch = 0; for (inputArrayIndex = 0; inputArrayIndex < inputArray.length; inputArrayIndex++) { ch = inputArray[inputArrayIndex]; if (Character.isLetter((char) ch)) { stemmerInputBufferIndex = 0; // start collecting letters for a new word while (inputArrayIndex < inputArray.length) { // keep reading until hit character other than a letter ch = Character.toLowerCase((char) ch); w[stemmerInputBufferIndex] = (char) ch; if (stemmerInputBufferIndex < maxLength - 1) { stemmerInputBufferIndex++; }/* ww w. jav a2 s .c o m*/ if (inputArrayIndex < inputArray.length - 1) { previousCh = ch; ch = inputArray[++inputArrayIndex]; if (!Character.isLetter((char) ch)) { // parse the word in preparation for starting a new one for (int c = 0; c < stemmerInputBufferIndex; c++) { // copy to stemmer internal buffer s.add(w[c]); } s.stem(); { String u; u = s.toString(); outputStr += u; if (ch == '-') { // replace - with space outputStr += " "; } else if (ch == '.') { if (Character.isDigit((char) previousCh)) { outputStr += "."; } else { outputStr += " "; //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass } } else { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } stemmerInputBufferIndex = 0; // to avoid repeats after ) } break; } } else { break; } } } else if (Character.isWhitespace((char) ch)) { if (!Character.isWhitespace((char) previousCh)) { if (previousCh != '.') { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } } } else if (ch == '(') { // open paren; copy all characters until close paren while (ch != ')') { if (inputArrayIndex < inputArray.length) { ch = inputArray[inputArrayIndex++]; } else { log.trace(""); log.trace("1 short of EOS in paren at pos: " + inputArrayIndex + " of " + inputStr); break; } Character Ch = new Character((char) ch); //outputStr += Ch.toString(); //System.out.print( Ch.toString() ); } //log.trace(""); /* not needed -- just duplicates close paren if ( ch == ')') { Character Ch = new Character((char) ch); outputStr += Ch.toString(); log.trace( Ch.toString() ); } */ stemmerInputBufferIndex = 0; } else if (ch == ')') { // when is last character of input string Character Ch = new Character((char) ch); outputStr += Ch.toString(); log.trace(Ch.toString()); log.trace("found close paren at position: " + inputArrayIndex + " of input term " + inputStr); } else if (ch == '-') { // replace - with space outputStr += " "; } else if (ch == '.') { if (Character.isDigit((char) previousCh)) { outputStr += "."; } else { outputStr += " "; //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass } } else { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } previousCh = ch; if (ch < 0) break; } if (stemmerInputBufferIndex > 0) { for (int c = 0; c < stemmerInputBufferIndex; c++) { s.add(w[c]); } s.stem(); String u; u = s.toString(); outputStr += u; } return outputStr == null ? (outputStr.equals("") ? null : outputStr.trim()) : outputStr.trim(); }