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:fr.scc.elo.controller.manager.impl.EloManagerImpl.java
private Player showAndUpdatePlayer(String name, String elo, String eloType, Boolean save) throws EloException { boolean modified = false; Player player = eloService.getPlayer(name); if (player == null) { if (!save) { throw new PlayerNotFoundException(); }//from w w w . j a va 2 s . c o m player = new Player(name); modified = true; } if (elo != null && NumberUtils.isNumber(elo)) { Integer scoreElo = player.getElo(EloType.fromName(eloType)); Integer newElo = Integer.valueOf(elo); if (!scoreElo.equals(newElo)) { player.getElo().setEloValue(EloType.E5V5, newElo); modified = true; } } else if (eloType != null) { throw new MissingRequestArgumentException(); } if (save && modified) { eloService.savePlayer(player); } return player; }
From source file:com.netsteadfast.greenstep.bsc.util.PeriodTrendsCalUtils.java
private static void fillKpiPeriodTrendsDateRangeScore(PeriodTrendsData<KpiVO> periodData) throws Exception { for (int i = 0; i < periodData.getCurrent().getDateRangeScores().size(); i++) { DateRangeScoreVO currentRangeScore = periodData.getCurrent().getDateRangeScores().get(i); DateRangeScoreVO previousRangeScore = periodData.getPrevious().getDateRangeScores().get(i); periodData.getDateRangeLabels()/*from www .j av a 2 s.c o m*/ .add(currentRangeScore.getDate() + "(C) / " + previousRangeScore.getDate() + "(P)"); float score = 0.0f; Object ans = BscFormulaUtils.parseKPIPeroidScoreChangeValue(periodData.getCurrent().getTrendsFormula(), currentRangeScore.getScore(), previousRangeScore.getScore()); String change = String.valueOf(ans); if (NumberUtils.isNumber(String.valueOf(change))) { score = NumberUtils.toFloat(change); } periodData.getDateRangeScores().add(NumberUtils.toFloat(BscReportSupportUtils.parse2(score))); periodData.getCurrentDateRangeScores().add(currentRangeScore.getScore()); periodData.getPreviousDateRangeScores().add(previousRangeScore.getScore()); } if (periodData.getDateRangeLabels().size() > 1) { periodData.setCanChart(YesNo.YES); } }
From source file:com.epam.catgenome.manager.bed.parser.NggbBedCodec.java
private void parseAndSetScore(String[] tokens, int tokenCount, NggbSimpleBedFeature feature) { if (tokenCount > SCORE_OFFSET && NumberUtils.isNumber(tokens[SCORE_OFFSET])) { try {/*from w w w .jav a 2 s . c om*/ float score = Float.parseFloat(tokens[SCORE_OFFSET]); feature.setScore(score); } catch (NumberFormatException numberFormatException) { feature.setScore(Float.NaN); } } }
From source file:gov.nih.nci.caintegrator.web.action.query.form.FoldChangeCriterionWrapper.java
private TextFieldParameter createFoldsDownParameter() { final String label = RegulationTypeEnum.UNCHANGED.equals(criterion.getRegulationType()) ? "Folds between" : "Down-regulation folds"; TextFieldParameter foldsParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(), criterion.getFoldsDown().toString()); foldsParameter.setLabel(label);//from w w w . j av a2s. c om ValueHandler foldsChangeHandler = new ValueHandlerAdapter() { @Override public boolean isValid(String value) { return 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) { criterion.setFoldsDown(Float.valueOf(value)); } }; foldsParameter.setValueHandler(foldsChangeHandler); return foldsParameter; }
From source file:de.pksoftware.springstrap.cms.util.CmsUtils.java
/** * //from w w w . j av a 2s. c om * @param model * @param path * @param value * @throws InvalidPathException */ public static String setModelProperty(CmsModel model, String path, String value) throws InvalidPathException { Assert.notNull(model); 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."); } logger.info("Trying to set " + model.getModelName() + ">" + path); String data = model.getData(); String[] pathParts = path.split("\\/"); int partsLength = pathParts.length; JSONObject jsonObject = new JSONObject(data); boolean pointerIsArray = false; Object pointer = jsonObject; for (int i = 1; i < partsLength; i++) { Assert.notNull(pointer); String pathPart = pathParts[i]; logger.info("Testing property: " + pathPart); Object jsonValue = null; if (pointerIsArray) { if (!NumberUtils.isNumber(pathPart)) { throw new InvalidPathException("Path element '" + pathPart + "' should be numeric."); } JSONArray arrayPointer = ((JSONArray) pointer); int arrayIndex = Integer.parseInt(pathPart); jsonValue = arrayPointer.opt(arrayIndex); if (null == jsonValue && i < partsLength - 1) { //Decide whether we want to create a new array or object String nextPathPart = pathParts[i + 1]; if (NumberUtils.isNumber(nextPathPart)) { jsonValue = new JSONArray(); } else { jsonValue = new JSONObject(); } arrayPointer.put(arrayIndex, jsonValue); } } else { JSONObject objectPointer = ((JSONObject) pointer); jsonValue = objectPointer.opt(pathPart); if (null == jsonValue && i < partsLength - 1) { //Decide whether we want to create a new array or object String nextPathPart = pathParts[i + 1]; if (NumberUtils.isNumber(nextPathPart)) { jsonValue = new JSONArray(); } else { jsonValue = new JSONObject(); } objectPointer.put(pathPart, jsonValue); } } if (i < partsLength - 1) { //Must be Object or Array if (jsonValue instanceof JSONArray) { logger.info(pathPart + " is an array."); pointer = (JSONArray) jsonValue; pointerIsArray = true; } else if (jsonValue instanceof JSONObject) { 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 " + jsonValue.getClass().toString() + " found."); } } else { if (null != jsonValue && !(jsonValue instanceof String)) { throw new InvalidPathException("Path element '" + pathPart + "' should be a be a string, but " + jsonValue.getClass().toString() + " found."); } if (pointerIsArray) { if (!NumberUtils.isNumber(pathPart)) { throw new InvalidPathException("Path element '" + pathPart + "' should be numeric."); } ((JSONArray) pointer).put(Integer.parseInt(pathPart), value); } else { ((JSONObject) pointer).put(pathPart, value); } break; } } return jsonObject.toString(); }
From source file:com.tekstosense.segmenter.Rule.SectionRules.java
private boolean hasSpecialCharacters(Node<LineNode> lineNodeNode) { if (lineNodeNode.getData().getFamily().equalsIgnoreCase("symbol") || lineNodeNode.getData().getFamily().equalsIgnoreCase("CMMI9") || lineNodeNode.getData().getFamily().equalsIgnoreCase("CMMI6") || NumberUtils.isNumber(lineNodeNode.getData().getText())) { return true; }//from w ww . j a v a 2 s . c o m return false; }
From source file:com.money.manager.ex.settings.PerDatabaseFragment.java
private void initializeControls() { final InfoService infoService = new InfoService(getActivity()); // Username//from ww w .java2 s. co m final Preference pUserName = findPreference(getString(R.string.pref_user_name)); if (pUserName != null) { pUserName.setSummary(MoneyManagerApplication.getApp().getUserName()); pUserName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { MoneyManagerApplication.getApp().setUserName((String) newValue, true); pUserName.setSummary(MoneyManagerApplication.getApp().getUserName()); return false; } }); } // Date format final ListPreference lstDateFormat = (ListPreference) findPreference(getString(R.string.pref_date_format)); if (lstDateFormat != null) { lstDateFormat.setEntries(getResources().getStringArray(R.array.date_format)); lstDateFormat.setEntryValues(getResources().getStringArray(R.array.date_format_mask)); //set summary String value = infoService.getInfoValue(InfoKeys.DATEFORMAT); lstDateFormat.setSummary(getDateFormatFromMask(value)); lstDateFormat.setValue(value); //on change lstDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (infoService.setInfoValue(InfoKeys.DATEFORMAT, (String) newValue)) { lstDateFormat.setSummary(getDateFormatFromMask((String) newValue)); } // Do not update to preferences file. return false; } }); } // Base Currency initBaseCurrency(); // financial year, day and month final Preference pFinancialDay = findPreference( getString(PreferenceConstants.PREF_FINANCIAL_YEAR_STARTDATE)); if (pFinancialDay != null) { pFinancialDay.setSummary(infoService.getInfoValue(InfoKeys.FINANCIAL_YEAR_START_DAY)); if (pFinancialDay.getSummary() != null) { pFinancialDay.setDefaultValue(pFinancialDay.getSummary().toString()); } pFinancialDay.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int day; try { day = Integer.parseInt((String) newValue); } catch (NumberFormatException e) { new UIHelper(getActivity()).showToast(R.string.error_parsing_value); return false; } try { if (day < 1 || day > 31) { return false; } if (infoService.setInfoValue(InfoKeys.FINANCIAL_YEAR_START_DAY, Integer.toString(day))) { pFinancialDay.setSummary(Integer.toString(day)); } // return true; } catch (Exception e) { Timber.e(e, "changing the start day of the financial year"); } return false; } }); } final Core core = new Core(getActivity().getApplicationContext()); // Financial year/month final ListPreference lstFinancialMonth = (ListPreference) findPreference( getString(PreferenceConstants.PREF_FINANCIAL_YEAR_STARTMONTH)); if (lstFinancialMonth != null) { lstFinancialMonth.setEntries(core.getListMonths()); lstFinancialMonth .setEntryValues(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" }); lstFinancialMonth.setDefaultValue("0"); // get current month try { String currentMonth = infoService.getInfoValue(InfoKeys.FINANCIAL_YEAR_START_MONTH); if ((!TextUtils.isEmpty(currentMonth)) && NumberUtils.isNumber(currentMonth)) { int month = Integer.parseInt(currentMonth) - 1; if (month > -1 && month < lstFinancialMonth.getEntries().length) { lstFinancialMonth.setSummary(lstFinancialMonth.getEntries()[month]); lstFinancialMonth.setValue(Integer.toString(month)); } } } catch (Exception e) { Timber.e(e, "showing the month of the financial year"); } lstFinancialMonth.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { try { int value = Integer.parseInt(newValue.toString()); if (value > -1 && value < lstFinancialMonth.getEntries().length) { if (infoService.setInfoValue(InfoKeys.FINANCIAL_YEAR_START_MONTH, Integer.toString(value + 1))) { lstFinancialMonth.setSummary(lstFinancialMonth.getEntries()[value]); // return true; } } } catch (Exception e) { Timber.e(e, "changing the month of the financial year"); // return false; } return false; } }); } initDefaultAccount(); }
From source file:gov.nih.nci.caintegrator.security.SecurityManagerImpl.java
@SuppressWarnings(UNCHECKED) // CSM API is untyped private Set<Long> retrieveStudyIds(Set<ProtectionGroup> protectionGroups) throws CSException { Set<Long> managedStudyIds = new HashSet<Long>(); for (ProtectionGroup group : protectionGroups) { Set<ProtectionElement> elements = getAuthorizationManager() .getProtectionElements(String.valueOf(group.getProtectionGroupId())); for (ProtectionElement element : elements) { if (STUDY_OBJECT.equals(element.getObjectId()) && NumberUtils.isNumber(element.getValue())) { managedStudyIds.add(Long.valueOf(element.getValue())); }// w w w . j ava2s . co m } } return managedStudyIds; }
From source file:ching.icecreaming.action.ViewAction.java
public void validate() { int int1 = 0, int2 = 0; DataModel2 dataObject2 = null;/* w w w . j av a2 s . c om*/ if (StringUtils.equals(wsType, "reportUnit") && StringUtils.equals(button1, getText("Print"))) { if (listObject2 != null) { int2 = listObject2.size(); for (int1 = 0; int1 < int2; int1++) { dataObject2 = (DataModel2) listObject2.get(int1); switch (dataObject2.getType1()) { case "singleValueDateTime": if (!GenericValidator.isDate(dataObject2.getValue1(), "yyyy-MM-dd HH:mm", false)) { addFieldError(String.format("listObject2[%d].value1", int1), getText("Error")); } break; case "singleValueDate": if (!GenericValidator.isDate(dataObject2.getValue1(), "yyyy-MM-dd", false)) { addFieldError(String.format("listObject2[%d].value1", int1), getText("Error")); } break; case "singleValueNumber": if (!NumberUtils.isNumber(dataObject2.getValue1())) { addFieldError(String.format("listObject2[%d].value1", int1), getText("Error")); } break; default: break; } } } } }
From source file:com.epam.catgenome.manager.bed.parser.NggbBedCodec.java
private void parseAndSetColour(String[] tokens, int tokenCount, NggbSimpleBedFeature feature) { if (tokenCount > COLOUR_OFFSET) { String colorString = tokens[COLOUR_OFFSET]; feature.setColor(ParsingUtils.parseColor(colorString)); // ThickStart and ThickEnd if (NumberUtils.isNumber(tokens[THICK_START_OFFSET]) && NumberUtils.isNumber(tokens[THICK_END_OFFSET])) { feature.setThickStart(Integer.parseInt(tokens[THICK_START_OFFSET])); feature.setThickEnd(Integer.parseInt(tokens[THICK_END_OFFSET])); }// w w w.j av a2 s. c o m } }