List of usage examples for org.apache.commons.lang StringUtils isNumericSpace
public static boolean isNumericSpace(String str)
Checks if the String contains only unicode digits or space ( ' '
).
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 w w w .j a va2 s . co 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:com.fengduo.spark.commons.test.BaseTestCase.java
/** * Assert string contains only unicode digits or space(' '). */ protected void assertNumericSpace(String str) { Assert.assertTrue(StringUtils.isNumericSpace(str)); }
From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java
/** * /*from w w w .j a v a2 s . c om*/ */ private void writeRow() { try { int i = 0; int col = 1; for (FieldDef fd : fields) { if (fd.getMaxSize() > 0) { String val = values.get(i); if (StringUtils.isNotEmpty(val)) { switch (fd.getType()) { case eText: pStmt.setString(col, val); break; case eNumber: { if (StringUtils.isNumericSpace(val)) { if (fd.isDouble()) { pStmt.setDouble(col, Double.parseDouble(val)); } else { pStmt.setInt(col, Integer.parseInt(val)); } } else { pStmt.setObject(col, null); } break; } case eDate: { Date date = null; try { date = sdf.parse(val); pStmt.setDate(col, new java.sql.Date(date.getTime())); } catch (Exception ex) { pStmt.setObject(col, null); } break; } case eTime: { Time time = null; try { time = Time.valueOf(val); } catch (Exception ex) { } pStmt.setTime(col, time); break; } } } else { pStmt.setObject(col, null); } col++; } i++; } } catch (SQLException ex) { ex.printStackTrace(); } try { pStmt.execute(); } catch (SQLException ex) { ex.printStackTrace(); } values.clear(); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatter.java
/** * @param formatter/*w ww . j av a2 s. co m*/ * @param text * @return */ private static boolean isDateValid(final UIFieldFormatterIFace formatter, final String text) { UIFieldFormatterField month = null; UIFieldFormatterField day = null; UIFieldFormatterField year = null; int monthInx = 0; int dayInx = 0; int yearInx = 0; int inx = 0; for (UIFieldFormatterField field : formatter.getFields()) { if (month == null && field.getValue().equals("MM")) { month = field; monthInx = inx; } else if (day == null && field.getValue().equals("DD")) { day = field; dayInx = inx; } else if (year == null && field.getValue().equals("YYYY")) { year = field; yearInx = inx; } inx += field.getSize(); } int yearVal = -1; if (year != null) { String val = text.substring(yearInx, yearInx + year.getSize()); if (StringUtils.isNumericSpace(val)) { yearVal = Integer.parseInt(val); if (yearVal == 0 || yearVal > 2500) { return false; } } else { return false; } } if (month != null) { int monVal = 0; String val = text.substring(monthInx, monthInx + month.getSize()).trim(); if (StringUtils.isNumericSpace(val)) { monVal = Integer.parseInt(val); if (monVal < 1 || monVal > 12) { return false; } } else { return false; } if (day != null) { daysInMon[1] = isLeapYear(yearVal) ? 29 : 28; val = text.substring(dayInx, dayInx + day.getSize()); if (StringUtils.isNumericSpace(val)) { int dayVal = Integer.parseInt(val); if (dayVal < 1 || dayVal > daysInMon[monVal - 1]) { return false; } } else { return false; } } } return true; }
From source file:com.ms.commons.test.BaseTestCase.java
/** * Assert string contains only unicode digits or space(' '). */ protected void assertNumericSpace(String str) { assertTrue(StringUtils.isNumericSpace(str)); }
From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQL.java
/** * //from ww w .j a v a 2 s .c o m */ public void convert(final String databaseName, final String tableName, final String srcFileName, final String xmlFileName) { String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; HashMap<String, Integer> monthHash = new HashMap<String, Integer>(); for (String mn : months) { monthHash.put(mn, monthHash.size() + 1); } Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection( "jdbc:mysql://localhost/" + databaseName + "?characterEncoding=UTF-8&autoReconnect=true", "root", "root"); stmt = conn.createStatement(); FMPCreateTable fmpInfo = new FMPCreateTable(tableName, null, true); fmpInfo.process(xmlFileName); boolean doCreateTable = true; if (doCreateTable) { processFieldSizes(fmpInfo, srcFileName); PrintWriter pw = new PrintWriter(new File("fields.txt")); int i = 0; for (FieldDef fd : fmpInfo.getFields()) { pw.println(i + " " + fd.getName() + "\t" + fd.getType() + "\t" + fd.isDouble()); i++; } pw.close(); BasicSQLUtils.update(conn, fmpInfo.dropTableStr()); String sqlCreateTable = fmpInfo.createTableStr(); BasicSQLUtils.update(conn, sqlCreateTable); System.out.println(sqlCreateTable); } String prepSQL = fmpInfo.getPrepareStmtStr(true, true); System.out.println(prepSQL); pStmt = conn.prepareStatement(prepSQL); Vector<FieldDef> fieldDefs = fmpInfo.getFields(); int rowCnt = 0; BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(srcFileName))); String str = in.readLine(); str = in.readLine(); while (str != null) { String line = str; char sep = '`'; String sepStr = ""; for (char c : seps) { if (line.indexOf(c) == -1) { sepStr += c; sep = c; break; } } str = StringUtils.replace(str.substring(1, str.length() - 1), "\",\"", sepStr); Vector<String> fields = split(str, sep); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); int col = 1; int inx = 0; for (String fld : fields) { String value = fld.trim(); FieldDef fd = fieldDefs.get(inx); switch (fd.getType()) { case eText: case eMemo: { if (value.length() > 0) { //value = FMPCreateTable.convertFromUTF8(value); if (value.length() <= fd.getMaxSize()) { pStmt.setString(col, value); } else { System.err.println(String.format("The data for `%s` max(%d) is too big %d", fd.getName(), fd.getMaxSize(), value.length())); pStmt.setString(col, null); } } else { pStmt.setString(col, null); } } break; case eNumber: { if (StringUtils.isNotEmpty(value)) { String origValue = value; String val = value.charAt(0) == '' ? value.substring(1) : value; val = val.charAt(0) == '-' ? val.substring(1) : val; val = val.indexOf('.') > -1 ? StringUtils.replace(val, ".", "") : val; val = val.indexOf('') > -1 ? StringUtils.replace(val, "", "") : val; if (StringUtils.isNumericSpace(val)) { if (fd.isDouble()) { pStmt.setDouble(col, Double.parseDouble(val)); } else { pStmt.setInt(col, Integer.parseInt(val)); } } else if (val.startsWith("ca. ")) { pStmt.setInt(col, Integer.parseInt(val.substring(4))); } else if (val.startsWith("ca ")) { pStmt.setInt(col, Integer.parseInt(val.substring(3))); } else { System.err.println(col + " Bad Number val[" + val + "] origValue[" + origValue + "] " + fieldDefs.get(col - 1).getName()); pStmt.setObject(col, null); } } else { pStmt.setDate(col, null); } } break; case eTime: { Time time = null; try { time = Time.valueOf(value); } catch (Exception ex) { } pStmt.setTime(col, time); } break; case eDate: { String origValue = value; try { if (StringUtils.isNotEmpty(value) && !value.equals("?") && !value.equals("-")) { int len = value.length(); if (len == 8 && value.charAt(1) == '-' && value.charAt(3) == '-') // 0-9-1886 { String dayStr = value.substring(0, 1); String monStr = value.substring(2, 3); if (StringUtils.isNumeric(dayStr) && StringUtils.isNumeric(monStr)) { String year = value.substring(4); int day = Integer.parseInt(dayStr); int mon = Integer.parseInt(monStr); if (day == 0) day = 1; if (mon == 0) mon = 1; value = String.format("%02d-%02d-%s", day, mon, year); } else { value = StringUtils.replaceChars(value, '.', ' '); String[] toks = StringUtils.split(value, ' '); if (toks.length == 3) { String dyStr = toks[0]; String mnStr = toks[1]; String yrStr = toks[2]; if (StringUtils.isNumeric(mnStr) && StringUtils.isNumeric(dyStr) && StringUtils.isNumeric(yrStr)) { int day = Integer.parseInt(dyStr); int mon = Integer.parseInt(mnStr); int year = Integer.parseInt(yrStr); if (day == 0) day = 1; if (mon == 0) mon = 1; value = String.format("%02d-%02d-%04d", day, mon, year); } else { System.err.println( col + " Bad Date#[" + value + "] [" + origValue + "]\n"); } } else { System.err.println( col + " Bad Date#[" + value + "] [" + origValue + "]\n"); } } } else if (len == 8 && (value.charAt(3) == '-' || value.charAt(3) == ' ')) // Apr-1886 { String monStr = value.substring(0, 3); Integer month = monthHash.get(monStr); String year = value.substring(4); if (month != null && StringUtils.isNumeric(year)) { value = String.format("01-%02d-%s", month, year); } else { value = StringUtils.replaceChars(value, '.', ' '); String[] toks = StringUtils.split(value, ' '); if (toks.length == 3) { String dyStr = toks[0]; String mnStr = toks[1]; String yrStr = toks[2]; if (StringUtils.isNumeric(mnStr) && StringUtils.isNumeric(dyStr) && StringUtils.isNumeric(yrStr)) { int day = Integer.parseInt(dyStr); int mon = Integer.parseInt(mnStr); int yr = Integer.parseInt(yrStr); if (day == 0) day = 1; if (mon == 0) mon = 1; value = String.format("%02d-%02d-%04d", day, mon, yr); } else { System.err.println( col + " Bad Date#[" + value + "] [" + origValue + "]\n"); } } else { System.err.println( col + " Bad Date#[" + value + "] [" + origValue + "]\n"); } } } else if ((len == 11 && value.charAt(2) == '-' && value.charAt(6) == '-') || // 10-May-1898 (len == 10 && value.charAt(1) == '-' && value.charAt(5) == '-')) // 7-May-1898 { boolean do11 = len == 11; String dayStr = value.substring(0, do11 ? 2 : 1); String monStr = value.substring(do11 ? 3 : 2, do11 ? 6 : 5); Integer month = monthHash.get(monStr); String year = value.substring(do11 ? 7 : 6); if (month != null && StringUtils.isNumeric(dayStr) && StringUtils.isNumeric(year)) { int day = Integer.parseInt(dayStr); if (day == 0) day = 1; value = String.format("%02d-%02d-%s", day, month, year); } else { System.err .println(col + " Bad Date^[" + value + "] [" + origValue + "]\n"); } } else if (len == 4) { if (StringUtils.isNumeric(value)) { value = "01-01-" + value; } else if (value.equalsIgnoreCase("s.d.") || value.equalsIgnoreCase("n.d.") || value.equalsIgnoreCase("s.n.")) { value = null; } } else if (StringUtils.contains(value, "/")) { value = StringUtils.replace(value, "/", "-"); } else if (StringUtils.contains(value, " ")) { value = StringUtils.replace(value, " ", "-"); } pStmt.setDate(col, StringUtils.isNotEmpty(value) ? new java.sql.Date(sdf.parse(value).getTime()) : null); } else { pStmt.setDate(col, null); } } catch (Exception ex) { System.err.println(col + " Bad Date[" + value + "] [" + origValue + "]\n" + str); pStmt.setDate(col, null); } } break; default: { System.err.println("Col: " + col + " Error - " + fd.getType()); } } inx++; col++; } pStmt.execute(); str = in.readLine(); rowCnt++; if (rowCnt % 1000 == 0) { System.out.println(rowCnt); } } in.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { stmt.close(); conn.close(); pStmt.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:org.goobi.production.flow.statistics.StatisticsManager.java
/** * Set source number if time units as String. * /*from ww w . ja v a 2 s .c o m*/ * @param inUnits * the sourceNumberOfTimeUnits to set given as String to show an * empty text field in gui */ public void setSourceNumberOfTimeUnitsAsString(String inUnits) { if (StringUtils.isNotBlank(inUnits) && StringUtils.isNumericSpace(inUnits)) { sourceNumberOfTimeUnits = Integer.parseInt(inUnits); } else { sourceNumberOfTimeUnits = 0; } }