List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber
public static boolean isNumber(final String str)
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x
or 0X
qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.
From source file:gov.nih.nci.caintegrator.web.action.query.form.SegmentCriterionWrapper.java
private TextFieldParameter createLowerLimitParameter() { final String label = "Segment Mean Value >="; TextFieldParameter textParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(), getCopyNumberAlterationCriterion().getDisplayLowerLimit()); textParameter.setLabel(label);/*from w w w . j a v a2 s.com*/ ValueHandler valueChangeHandler = new ValueHandlerAdapter() { @Override public boolean isValid(String value) { return StringUtils.isBlank(value) || NumberUtils.isNumber(value); } @Override public void validate(String formFieldName, String value, ValidationAware action) { if (!isValid(value)) { action.addActionError("Numeric value required or blank for " + label); } } @Override public void valueChanged(String value) { if (StringUtils.isBlank(value)) { getCopyNumberAlterationCriterion().setLowerLimit(null); } else { getCopyNumberAlterationCriterion().setLowerLimit(Float.valueOf(value)); } } }; textParameter.setValueHandler(valueChangeHandler); return textParameter; }
From source file:com.utdallas.s3lab.smvhunter.monkey.DeviceOfflineMonitor.java
@Override public void run() { int count = 0; while (true) { try {/*from ww w . ja v a 2 s. c o m*/ if (stop) { //free all the threads UIEnumerator.execCommand("killall emulator-arm"); return; } try { //run every 30 secs Thread.sleep(1000 * 30); } catch (InterruptedException ex) { logger.error("sleep interrupted", ex); if (stop) { //free all the threads UIEnumerator.execCommand("killall emulator-arm"); return; } } ////////////////////// adb status check //check adb status count++; if (count % 5 == 0) { String out = UIEnumerator.execSpecial(MonkeyMe.adbLocation + " devices"); //restart the adb daemon when it does not respond //don't know why it happens but after 5-6 hours adb //daemon stops responding if (!StringUtils.contains(out, "emulator-")) { UIEnumerator.execSpecial("killall adb"); UIEnumerator.execSpecial(MonkeyMe.adbLocation + " start-server"); } } //kill adb process if the count increases above 100 String adbCount = UIEnumerator.execSpecial("ps aux | grep adb"); if (adbCount.split("\\n").length > 100) { logger.info("number of adb process exceeded 100. Restarting adb"); UIEnumerator.execSpecial("killall adb"); UIEnumerator.execCommand(MonkeyMe.adbLocation + " start-server"); } ///////////////// adb status check end //check for offline devices String offlineDevices = UIEnumerator.execSpecial(LIST_OFFLINE); //for each device find the pid and process for (String device : offlineDevices.split("\\n")) { if (StringUtils.isEmpty(device)) { continue; } logger.error(String.format("%s found offline. processing ", device)); if (NumberUtils.isNumber(device)) { //find the pid of the emulator String cmd = String.format(PID_OF_OFFLINE_DEVICE, device); String offlinePid = UIEnumerator.execSpecial(cmd); //now find the emulator name final String emulatorName = UIEnumerator .execSpecial(String.format(EMULATOR_NAME, offlinePid)); //kill the emulator and start another one UIEnumerator.execSpecial(String.format(KILL_EMULATOR, offlinePid)); //wait for a sec Thread.sleep(2000); logger.info(String.format("killed %s. now starting again", emulatorName)); //start the emulator in a new thread exec.execute(new Runnable() { @Override public void run() { try { //start it again String out = UIEnumerator .execSpecial(String.format(START_EMULATOR, emulatorName)); logger.info(String.format("%s started with message ", out)); } catch (Exception e) { logger.error(e); } } }); } } } catch (Exception e) { logger.error(e); } } }
From source file:com.efficio.fieldbook.web.nursery.service.impl.AbstractNamingConventionServiceImpl.java
private void updatePlantsSelectedIfNecessary(AdvancingSourceList list, AdvancingNursery info) { boolean lineChoiceSame = info.getLineChoice() != null && "1".equals(info.getLineChoice()); int plantsSelected = 0; if (info.getLineSelected() != null && NumberUtils.isNumber(info.getLineSelected())) { plantsSelected = Integer.valueOf(info.getLineSelected()); } else {/*w w w .j a v a 2 s. com*/ lineChoiceSame = false; } if (list != null && list.getRows() != null && !list.getRows().isEmpty() && lineChoiceSame && plantsSelected > 0) { for (AdvancingSource row : list.getRows()) { row.setPlantsSelected(plantsSelected); } } }
From source file:com.embedler.moon.jtxt2img.ImgTextPropertiesAccessor.java
public Color getBackgroundColor() { Color bgColor = getDefaultBackgroundColor(); if (isValidForegroundColor()) { Matcher m = CoreHelper.COLOR_REGEXP.matcher(imgTextProperties.getBgColor()); if (m.matches()) { String temp = m.group(1); if (NumberUtils.isNumber("0x" + temp)) { bgColor = CoreHelper.hex2Rgb(temp); }// ww w .j av a 2 s . c o m } } return bgColor; }
From source file:gov.nih.nci.caintegrator.web.action.query.form.AbstractCopyNumberCoordinateWrapper.java
/** * @return//from www . jav a 2 s . com */ private AbstractCriterionParameter createToCoordinateParameter() { final String label = "To"; TextFieldParameter textParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(), criterion.getDisplayChromosomeCoordinateHigh()); textParameter.setLabel(label); ValueHandler valueChangeHandler = new ValueHandlerAdapter() { @Override public boolean isValid(String value) { return StringUtils.isBlank(value) || NumberUtils.isNumber(value); } @Override public void validate(String formFieldName, String value, ValidationAware action) { if (!isValid(value)) { action.addActionError("Numeric value required for " + label); } } @Override public void valueChanged(String value) { if (StringUtils.isBlank(value)) { criterion.setChromosomeCoordinateHigh(null); } else { criterion.setChromosomeCoordinateHigh(Integer.valueOf(value)); } } }; textParameter.setValueHandler(valueChangeHandler); return textParameter; }
From source file:com.netsteadfast.greenstep.bsc.util.AggregationMethod.java
public float average(KpiVO kpi) throws Exception { List<BbMeasureData> measureDatas = kpi.getMeasureDatas(); float score = 0.0f; // init zero int size = 0; for (BbMeasureData measureData : measureDatas) { BscMeasureData data = new BscMeasureData(); data.setActual(measureData.getActual()); data.setTarget(measureData.getTarget()); try {/* w w w. j a va 2 s. co m*/ Object value = BscFormulaUtils.parse(kpi.getFormula(), data); if (value == null) { continue; } if (!NumberUtils.isNumber(String.valueOf(value))) { continue; } score += NumberUtils.toFloat(String.valueOf(value), 0.0f); size++; } catch (Exception e) { e.printStackTrace(); } } if (score != 0.0f && size > 0) { score = score / size; } return score; }
From source file:com.baasbox.Global.java
@Override public Configuration onLoadConfig(Configuration config, java.io.File path, java.lang.ClassLoader classloader) { debug("Global.onLoadConfig() called"); info("BaasBox is preparing OrientDB Embedded Server..."); try {// w ww . j a va2s . c o m OGlobalConfiguration.TX_LOG_SYNCH.setValue(Boolean.TRUE); OGlobalConfiguration.TX_COMMIT_SYNCH.setValue(Boolean.TRUE); OGlobalConfiguration.NON_TX_RECORD_UPDATE_SYNCH.setValue(Boolean.TRUE); //Deprecated due to OrientDB 1.6 //OGlobalConfiguration.NON_TX_CLUSTERS_SYNC_IMMEDIATELY.setValue(OMetadata.CLUSTER_MANUAL_INDEX_NAME); OGlobalConfiguration.CACHE_LEVEL1_ENABLED.setValue(Boolean.FALSE); OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(Boolean.FALSE); OGlobalConfiguration.INDEX_MANUAL_LAZY_UPDATES.setValue(-1); OGlobalConfiguration.FILE_LOCK.setValue(false); OGlobalConfiguration.FILE_DEFRAG_STRATEGY.setValue(1); OGlobalConfiguration.MEMORY_USE_UNSAFE.setValue(false); if (!NumberUtils.isNumber(System.getProperty("storage.wal.maxSize"))) OGlobalConfiguration.WAL_MAX_SIZE.setValue(300); Orient.instance().startup(); ODatabaseDocumentTx db = null; try { db = Orient.instance().getDatabaseFactory().createDatabase("graph", "plocal:" + config.getString(BBConfiguration.DB_PATH)); if (!db.exists()) { info("DB does not exist, BaasBox will create a new one"); db.create(); justCreated = true; } } catch (Throwable e) { error("!! Error initializing BaasBox!", e); error(ExceptionUtils.getFullStackTrace(e)); throw e; } finally { if (db != null && !db.isClosed()) db.close(); } info("DB has been create successfully"); } catch (Throwable e) { error("!! Error initializing BaasBox!", e); error("Abnormal BaasBox termination."); System.exit(-1); } debug("Global.onLoadConfig() ended"); return config; }
From source file:gov.nih.nci.caintegrator.application.study.FileColumn.java
private Object handleNumericType(String stringValue) throws ValidationException { if (!NumberUtils.isNumber(stringValue)) { throw new ValidationException( "Cannot cast column '" + name + "' as a number, because of value: " + stringValue); }/*from ww w .j a va 2 s.co m*/ return Double.valueOf(stringValue); }
From source file:gov.nih.nci.caintegrator.application.arraydata.AffymetrixCnPlatformLoader.java
private int getIntegerValue(String[] fields, String header) { String value = getAnnotationValue(fields, header); if (!NumberUtils.isNumber(value)) { return -1; }/* w w w . java 2 s. c om*/ return Integer.parseInt(value); }
From source file:de.pksoftware.springstrap.cms.util.CmsUtils.java
public static String getModelProperty(CmsModel model, String path, String defaultValue) throws InvalidPathException { if (null == model) { return defaultValue; }//from w w w . j av a 2 s . c om Pattern pattern = Pattern.compile("^(\\/\\w+)+$"); Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { throw new RuntimeException( "Path must start with /, must not end with / and must only contain letters and numbers."); } String value = defaultValue; logger.info("Trying to get " + model.getModelName() + ">" + path); String data = model.getData(); String[] pathParts = path.split("\\/"); int partsLength = pathParts.length; JsonReader jsonReader = Json.createReader(new StringReader(data)); JsonObject jsonObject = jsonReader.readObject(); boolean pointerIsArray = false; Object pointer = jsonObject; for (int i = 1; i < partsLength; i++) { String pathPart = pathParts[i]; logger.info("Testing property: " + pathPart); JsonValue jsonValue = null; Assert.notNull(pointer); if (pointerIsArray) { if (!NumberUtils.isNumber(pathPart)) { throw new InvalidPathException("Path element '" + pathPart + "' should be numeric."); } jsonValue = ((JsonArray) pointer).get(Integer.parseInt(pathPart)); } else { jsonValue = ((JsonObject) pointer).get(pathPart); } if (null == jsonValue) { logger.info(model.getModelName() + " has no property: " + path); break; } JsonValue.ValueType valueType = jsonValue.getValueType(); if (i < partsLength - 1) { //Must be Object or Array if (valueType == JsonValue.ValueType.ARRAY) { logger.info(pathPart + " is an array."); pointer = (JsonArray) jsonValue; pointerIsArray = true; } else if (valueType == JsonValue.ValueType.OBJECT) { logger.info(pathPart + " is an object."); pointer = (JsonObject) jsonValue; pointerIsArray = false; } else { throw new InvalidPathException("Path element '" + pathPart + "' should be a be an object or array, but " + valueType.toString() + " found."); } } else { if (valueType == JsonValue.ValueType.STRING) { logger.info(pathPart + " is an string."); value = ((JsonString) jsonValue).getString(); break; } else { throw new InvalidPathException("Path element '" + pathPart + "' should be a string, but " + valueType.toString() + " found."); } } } jsonReader.close(); return value; }