List of usage examples for org.apache.commons.lang.math NumberUtils isNumber
public static boolean isNumber(String str)
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g.
From source file:MainClass.java
public static void main(String[] args) { //Check if a String is a valid number System.out.println("Is Number >>> " + NumberUtils.isNumber("123.123")); }
From source file:MathUtilsTrial.java
public static void main(String[] args) { // Check if a String contains only digits System.out.println("Is Digits >>> " + NumberUtils.isDigits("123.123")); // Check if a String is a valid number System.out.println("Is Number >>> " + NumberUtils.isNumber("123.123")); // Get MAX value from an array System.out.println("MAX >>> " + NumberUtils.max(new double[] { 3.33, 8.88, 1.11 })); }
From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalWriter.java
public static void main(String[] args) throws SOMToolboxException, IOException { // register and parse all options JSAPResult config = OptionFactory.parseResults(args, OPTIONS); File inputVectorFile = config.getFile("inputVectorFile"); String outputDirStr = AbstractOptionFactory.getFilePath(config, "outputDirectory"); File outputDirBase = new File(outputDirStr); outputDirBase.mkdirs();/* w w w . j a va 2 s. c o m*/ String metricName = config.getString("metric"); DistanceMetric metric = AbstractMetric.instantiateNice(metricName); int neighbours = config.getInt("numberNeighbours"); int startIndex = config.getInt("startIndex"); int numberItems = config.getInt("numberItems", -1); try { SOMLibSparseInputData data = new SOMLibSparseInputData(inputVectorFile.getAbsolutePath()); int endIndex = data.numVectors(); if (numberItems != -1) { if (startIndex + numberItems > endIndex) { System.out.println("Specified number of items (" + numberItems + ") exceeds maximum (" + data.numVectors() + "), limiting to " + (endIndex - startIndex) + "."); } else { endIndex = startIndex + numberItems; } } StdErrProgressWriter progress = new StdErrProgressWriter(endIndex - startIndex, "processing vector "); // SortedSet<InputDistance> distances; for (int inputDatumIndex = startIndex; inputDatumIndex < endIndex; inputDatumIndex++) { InputDatum inputDatum = data.getInputDatum(inputDatumIndex); String inputLabel = inputDatum.getLabel(); if (inputDatumIndex == -1) { throw new IllegalArgumentException( "Input with label '" + inputLabel + "' not found in vector file '" + inputVectorFile + "'; possible labels are: " + StringUtils.toString(data.getLabels(), 15)); } File outputDir = new File(outputDirBase, inputLabel.charAt(2) + "/" + inputLabel.charAt(3) + "/" + inputLabel.charAt(4)); outputDir.mkdirs(); File outputFile = new File(outputDir, inputLabel + ".txt"); boolean fileExistsAndValid = false; if (outputFile.exists()) { // check if it the valid data String linesInvalid = ""; int validLineCount = 0; ArrayList<String> lines = FileUtils.readLinesAsList(outputFile.getAbsolutePath()); for (String string : lines) { if (string.trim().length() == 0) { continue; } String[] parts = string.split("\t"); if (parts.length != 2) { linesInvalid += "Line '" + string + "' invalid - contains " + parts.length + " elements.\n"; } else if (!NumberUtils.isNumber(parts[1])) { linesInvalid = "Line '" + string + "' invalid - 2nd part is not a number.\n"; } else { validLineCount++; } } if (validLineCount != neighbours) { linesInvalid = "Not enough valid lines; expected " + neighbours + ", found " + validLineCount + ".\n"; } fileExistsAndValid = true; if (org.apache.commons.lang.StringUtils.isNotBlank(linesInvalid)) { System.out.println("File " + outputFile.getAbsolutePath() + " exists, but is not valid:\n" + linesInvalid); } } if (fileExistsAndValid) { Logger.getLogger("at.tuwien.ifs.feature.evaluation").finer( "File " + outputFile.getAbsolutePath() + " exists and is valid; not recomputing"); } else { PrintWriter p = new PrintWriter(outputFile); SmallestElementSet<InputDistance> distances = data.getNearestDistances(inputDatumIndex, neighbours, metric); for (InputDistance inputDistance : distances) { p.println(inputDistance.getInput().getLabel() + "\t" + inputDistance.getDistance()); } p.close(); } progress.progress(); } } catch (IllegalArgumentException e) { System.out.println(e.getMessage() + ". Aborting."); System.exit(-1); } }
From source file:com.pureinfo.srm.config.affirm.AffirmHelper.java
public static int getActualHonorMaxDay() throws PureException { IAffirmMgr mgr = (IAffirmMgr) PureFactory.getBean("IAffirmMgr"); String sDay = mgr.getMaxDayString("honor", "all"); return NumberUtils.isNumber(sDay) ? Integer.parseInt(sDay) : 0; }
From source file:com.qualogy.qafe.business.integration.filter.page.PageCreator.java
/** * Method to create a page object based page data in the datastore. * If no data supplied for the page, null is returned * @param id/*ww w . j a va2s.c o m*/ * @return */ public static Page create(DataIdentifier id) { Page page = null; Object objPageNr = DataStore.findValue(id, DataStore.KEY_WORD_PAGE_NUMBER); Object objPageSize = DataStore.findValue(id, DataStore.KEY_WORD_PAGESIZE); if (objPageSize != null) { int pagesize = 0; if (objPageSize instanceof Number) pagesize = ((Number) objPageSize).intValue(); else if (objPageSize instanceof String && NumberUtils.isNumber((String) objPageSize)) pagesize = Integer.parseInt((String) objPageSize); if (pagesize > -1) { int pagenumber = 0; if (objPageNr instanceof Number) pagenumber = ((Number) objPageNr).intValue(); else if (objPageNr instanceof String && NumberUtils.isNumber((String) objPageNr)) pagenumber = Integer.parseInt((String) objPageNr); else if (objPageNr instanceof String && ((String) objPageNr).toUpperCase().equals(DataStore.KEY_WORD_PAGE_NUMBER_LAST)) pagenumber = Integer.MAX_VALUE; boolean countPages = false; Object objCountPages = DataStore.findValue(id, DataStore.KEY_WORD_CALCULATEPAGESAVAILABLE); if (objCountPages instanceof String) countPages = Boolean.valueOf((String) objCountPages).booleanValue(); else if (objCountPages instanceof Boolean) countPages = ((Boolean) objCountPages).booleanValue(); page = Page.create(pagenumber, pagesize, countPages, id); } } return page; }
From source file:com.pureinfo.srm.config.affirm.AffirmHelper.java
public static int getActualProductMaxDay(String _sProductForm, String _sPubLevel) throws PureException { IAffirmMgr mgr = (IAffirmMgr) PureFactory.getBean("IAffirmMgr"); String sDay = mgr.getMaxDayString(_sProductForm, _sPubLevel); if (sDay == null && !"all".equals(_sProductForm)) sDay = mgr.getMaxDayString("all", _sPubLevel); if (sDay == null && !"all".equals(_sPubLevel)) sDay = mgr.getMaxDayString(_sProductForm, "all"); if (sDay == null && !"all".equals(_sProductForm) && !"all".equals(_sPubLevel)) sDay = mgr.getMaxDayString("all", "all"); return NumberUtils.isNumber(sDay) ? Integer.parseInt(sDay) : 0; }
From source file:com.intuit.tank.harness.functions.NumericFunctions.java
/** * Is this a valid Numeric function request * //w w w .ja va2s.c o m * @param values * The command * @return TRUE if valid format; FALSE otherwise */ static public boolean isValid(String[] values) { try { if (values[2].equalsIgnoreCase("randompositivewhole") || values[2].equalsIgnoreCase("randomnegativewhole")) { if (NumberUtils.isDigits(values[3])) { return true; } } if (values[2].equalsIgnoreCase("randompositivefloat") || values[2].equalsIgnoreCase("randomnegativefloat") || values[2].equalsIgnoreCase("mod")) { if (NumberUtils.isDigits(values[3]) && NumberUtils.isDigits(values[4])) { return true; } } if (values[2].equalsIgnoreCase("add") || values[2].equalsIgnoreCase("subtract")) { if (NumberUtils.isNumber(values[3]) && NumberUtils.isNumber(values[4])) { for (int i = 5; i < values.length; i++) { if (values[i] != null) { if (!NumberUtils.isNumber(values[i])) { return false; } } else { return true; } } } } return false; } catch (Exception ex) { return false; } }
From source file:gov.nih.nci.cabig.caaers.validation.fields.validators.NumberValidator.java
@Override public boolean isValid(Object fieldValue) { if (fieldValue != null) return NumberUtils.isNumber(fieldValue.toString()); return true;//from ww w . j av a2 s .com }
From source file:com.us.action.account.ViewMyPic.java
@Override public String execute() throws Exception { if (!StringUtil.hasText(catalog) || !NumberUtils.isNumber(catalog) || NumberUtils.toLong(catalog) == -1) { albums = albumBo.find(Album.class, "creator", getLogonUserId()); } else {//from w w w . j av a 2s . c o m String pro[] = ArrayHelper.make("creator", "catalog.uuid"); Object val[] = ArrayHelper.make(getLogonUserId(), NumberUtils.toLong(catalog)); albums = albumBo.find(Album.class, pro, val); } for (Album album : albums) { List<Object> o = albumBo.findByHql("select count(uuid) from com.us.vo.Image i where i.album=?", album.getUuid()); final long imageCount = Long.parseLong(o.get(0).toString()); album.setImgaeConunt(imageCount); totolImg += imageCount; } return view("viewMyAlbums.jsp"); }
From source file:gov.nih.nci.cabig.caaers.tools.CodedEnumType.java
@Override protected Object getKeyObject(ResultSet rs, String colname) throws SQLException { String s = rs.getString(colname); if (s == null) return null; else {//ww w . j a v a2 s . c o m if (NumberUtils.isNumber(s)) return Integer.parseInt(s); return s; } }