List of usage examples for org.apache.commons.lang3.math NumberUtils isDigits
public static boolean isDigits(final String str)
Checks whether the String
contains only digit characters.
Null
and empty String will return false
.
From source file:com.xpn.xwiki.api.XWiki.java
/** * @return specified documents in recycle bin * @param fullname - {@link XWikiDocument#getFullName()} * @param lang - {@link XWikiDocument#getLanguage()} * @throws XWikiException if any error/*from www . ja v a 2s .c o m*/ */ public DeletedDocument getDeletedDocument(String fullname, String lang, String index) throws XWikiException { if (!NumberUtils.isDigits(index)) { return null; } XWikiDeletedDocument dd = this.xwiki.getDeletedDocument(fullname, lang, Integer.parseInt(index), this.context); if (dd == null) { return null; } return new DeletedDocument(dd, this.context); }
From source file:com.erudika.para.utils.Constraint.java
/** * The 'digits' constraint - field must be a {@link Number} or {@link String} containing digits where the * number of digits in the integral part is limited by 'integer', and the * number of digits for the fractional part is limited * by 'fraction'.//from w w w . j av a 2 s .co m * @param integer the max number of digits for the integral part * @param fraction the max number of digits for the fractional part * @return constraint */ public static Constraint digits(final Object integer, final Object fraction) { return new Constraint("digits", digitsPayload(integer, fraction)) { public boolean isValid(Object actualValue) { if (actualValue != null) { if (!((actualValue instanceof Number) || (actualValue instanceof String))) { return false; } else { if (integer != null && fraction != null && integer instanceof Number && fraction instanceof Number) { String val = actualValue.toString(); String[] split = val.split("[,.]"); if (!NumberUtils.isDigits(split[0])) { return false; } if (((Number) integer).intValue() < split[0].length()) { return false; } if (split.length > 1 && ((Number) fraction).intValue() < split[1].length()) { return false; } } } } return true; } }; }
From source file:com.omertron.slackbot.listeners.BoardGameListener.java
/** * Get information on a specific game//from w ww .j a v a 2 s. c o m * * @param session * @param msgChannel * @param msgSender * @param query */ private void commandGame(SlackSession session, SlackChannel msgChannel, String query) { int bggId = 0; // If the query is a string, first search for the game if (!NumberUtils.isDigits(query)) { try { // Assume an exact search request SearchWrapper wrapper = BGG.searchBoardGame(query, true, false); if (wrapper.getTotal() > 0) { bggId = wrapper.getItems().get(0).getId(); } } catch (BggException ex) { LOG.warn("Failed to get exact search for {} from BGG", ex.getMessage(), ex); session.sendMessage(msgChannel, "Unable to find information on *'" + query + "'*"); return; } } else { // Try converting the number bggId = NumberUtils.toInt(query, 0); } if (bggId > 0) { try { List<BoardGameExtended> results = BGG.getBoardGameInfo(bggId); if (results == null || results.isEmpty()) { session.sendMessage(msgChannel, "No results found for BGG ID " + bggId); return; } session.sendMessage(msgChannel, null, makeDetailedAttachment(results.get(0))); } catch (BggException ex) { LOG.warn("Failed to get information from BGG on game ID {} - Query '{}'", bggId, query, ex); session.sendMessage(msgChannel, "Failed to get information from BGG on game ID " + bggId + " - Query '" + query + "'"); } } else { session.sendMessage(msgChannel, "Unable to find information for game with ID *" + query + "*"); } }
From source file:com.nridge.core.base.field.Field.java
/** * Returns an <i>int</i> representation of the field * value string./*from w w w . j a v a2 s .c om*/ * * @param aValue Numeric string value. * * @return Converted value. */ public static int createInt(String aValue) { if (NumberUtils.isDigits(aValue)) return Integer.parseInt(aValue); else return Integer.MIN_VALUE; }
From source file:com.nridge.core.base.field.Field.java
/** * Returns an <i>Integer</i> representation of the field * value string./* w ww .j av a2 s . co m*/ * * @param aValue Numeric string value. * * @return Converted value. */ public static Integer createIntegerObject(String aValue) { if (NumberUtils.isDigits(aValue)) return Integer.valueOf(aValue); else return Integer.MIN_VALUE; }
From source file:com.nridge.core.base.field.Field.java
/** * Returns a <i>long</i> representation of the field * value string./*from w ww. j a v a 2 s .c o m*/ * * @param aValue Numeric string value. * * @return Converted value. */ public static long createLong(String aValue) { if (NumberUtils.isDigits(aValue)) return Long.parseLong(aValue); else return Long.MIN_VALUE; }
From source file:net.gerosyab.dailylog.activity.MainActivity.java
private void importCategory() { DialogProperties properties = new DialogProperties(); properties.selection_mode = DialogConfigs.SINGLE_MODE; properties.selection_type = DialogConfigs.FILE_SELECT; properties.root = new File(DialogConfigs.DEFAULT_DIR); properties.extensions = null;/*from w w w . j a va 2s .c om*/ dialog = new FilePickerDialog(MainActivity.this, properties); dialog.setDialogSelectionListener(new DialogSelectionListener() { @Override public void onSelectedFilePaths(String[] files) { ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setTitle("Importing data [" + files[0] + "]"); progressDialog.show(); //files is the array of the paths of files selected by the Application User. try { String newCategoryUUID = UUID.randomUUID().toString(); // CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(files[0]), "UTF-8"), '\t'); CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(files[0]), "UTF-8"), ','); String[] nextLine; long lineNum = 0; boolean dbVersionCheck = false, categoryNameCheck = false, categoryUnitCheck = false; boolean categoryTypeCheck = false, defaultValueCheck = false, headerCheck = false; boolean isCategoryNameExists = false, rowDataCheck = false, dataCheck = false; String dbVersion = null, categoryName = null, categoryUnit = null; long categoryType = -1, defaultValue = -1; // Category category = null; List<Record> records = new ArrayList<Record>(); while ((nextLine = reader.readNext()) != null) { // nextLine[] is an array of values from the line String temp2 = ""; for (int i = 0; i < nextLine.length; i++) { temp2 += nextLine[i] + ", "; } MyLog.d("opencsv", temp2); if (lineNum == 0) { //header MyLog.d("opencsv", "nextLine.length : " + nextLine.length); for (int i = 0; i < nextLine.length; i++) { String[] split2 = nextLine[i].split(":"); MyLog.d("opencsv", "split2.length : " + split2.length); MyLog.d("opencsv", "split2[0] : " + split2[0]); if (split2[0].replaceAll("\\s+", "").equals("Version")) { if (split2[1] != null && !split2[1].equals("")) { dbVersion = split2[1]; dbVersionCheck = true; } } else if (split2[0].replaceAll("\\s+", "").equals("Name")) { if (split2[1] != null && !split2[1].equals("")) { categoryName = split2[1]; if (categoryName.length() <= Category.getMaxCategoryNameLength()) { categoryNameCheck = true; } } } else if (split2[0].replaceAll("\\s+", "").equals("Unit")) { if (split2.length == 1) { categoryUnitCheck = true; } else if (split2[1] != null && !split2[1].equals("")) { categoryUnit = split2[1]; categoryUnitCheck = true; } } else if (split2[0].replaceAll("\\s+", "").equals("Type")) { if (split2[1] != null && !split2[1].equals("")) { if (split2[1].equals("0") || split2[1].equals("1") || split2[1].equals("2")) { categoryType = Long.parseLong(split2[1]); categoryTypeCheck = true; } } } else if (split2[0].replaceAll("\\s+", "").equals("DefaultValue")) { if (split2.length == 1) { defaultValueCheck = true; } else if (split2[1] != null && !split2[1].equals("")) { if (NumberUtils.isDigits(split2[1]) && NumberUtils.isNumber(split2[1])) { defaultValue = Long.parseLong(split2[1]); MyLog.d("opencsv", "split2[1] : " + split2[1]); if (defaultValue >= 0) { defaultValueCheck = true; } } } } } if (dbVersionCheck && categoryNameCheck && categoryTypeCheck) { if (categoryType == 1) { //number if (categoryUnitCheck && defaultValueCheck) { headerCheck = true; } } else { //boolean, string headerCheck = true; } } if (!headerCheck) { break; //header parsing, data checking failed } else if (Category.isCategoryNameExists(realm, categoryName)) { isCategoryNameExists = true; break; } else { // category = new Category(categoryName, categoryUnit, Category.getLastOrderNum(realm), categoryType); } } else { //data Record record; rowDataCheck = true; if (nextLine.length != 2) { rowDataCheck = false; break; } else { record = new Record(); record.setRecordType(categoryType); DateTime dateTime = StaticData.fmtForBackup.parseDateTime(nextLine[0]); if (dateTime != null) { record.setDate(new java.sql.Date(dateTime.toDate().getTime())); } else { rowDataCheck = false; break; } if (categoryType == StaticData.RECORD_TYPE_BOOLEAN) { if (nextLine[1].equals("true")) { record.setBool(true); } else { rowDataCheck = false; break; } } else if (categoryType == StaticData.RECORD_TYPE_NUMBER) { if (NumberUtils.isNumber(nextLine[1]) && NumberUtils.isDigits(nextLine[1])) { long value = Long.parseLong(nextLine[1]); if (value > Category.getMaxValue()) { rowDataCheck = false; break; } else { record.setNumber(value); } } else { dataCheck = false; break; } } else if (categoryType == StaticData.RECORD_TYPE_MEMO) { String value = nextLine[1]; if (value.length() > Category.getMaxMemoLength()) { rowDataCheck = false; break; } else { record.setString(nextLine[1]); } } } if (record != null && rowDataCheck == true) { record.setCategoryId(newCategoryUUID); record.setRecordId(UUID.randomUUID().toString()); records.add(record); } } lineNum++; } if (!headerCheck) { Toast.makeText(context, "Data file's header context/value is not correct", Toast.LENGTH_LONG).show(); } else if (isCategoryNameExists) { Toast.makeText(context, "Category Name [" + categoryName + "] is already exists", Toast.LENGTH_LONG).show(); } else if (!rowDataCheck) { Toast.makeText(context, "Data file's record data is not correct", Toast.LENGTH_LONG).show(); } else { long newOrder = Category.getNewOrderNum(realm); realm.beginTransaction(); Category category = realm.createObject(Category.class, newCategoryUUID); category.setName(categoryName); category.setUnit(categoryUnit); category.setOrder(newOrder); category.setRecordType(categoryType); realm.insert(category); realm.insertOrUpdate(records); realm.commitTransaction(); Toast.makeText(context, "Data import [ " + categoryName + " ] is completed!!", Toast.LENGTH_LONG).show(); // refreshList(); // categoryHolderList.add(getHolderFromCategory(category)); // mDragListView.getAdapter().notifyDataSetChanged(); // mDragListView.getAdapter().notifyItemInserted((int) newOrder); // setCategoryHolderList(); // mDragListView.getAdapter().setItemList(categoryHolderList); adapter.notifyDataSetChanged(); } } catch (FileNotFoundException e) { Toast.makeText(context, "Selected file is not found", Toast.LENGTH_LONG).show(); e.printStackTrace(); } catch (IOException e) { Toast.makeText(context, "File I/O exception occured", Toast.LENGTH_LONG).show(); e.printStackTrace(); } finally { progressDialog.dismiss(); } } }); dialog.show(); }
From source file:com.nridge.core.base.field.Field.java
/** * Returns a <i>Long</i> representation of the field * value string./* w w w . j a v a2s. c om*/ * * @param aValue Numeric string value. * * @return Converted value. */ public static Long createLongObject(String aValue) { if (NumberUtils.isDigits(aValue)) return Long.valueOf(aValue); else return Long.MIN_VALUE; }
From source file:org.drftpd.commands.imdb.IMDBParser.java
private boolean getInfo() { try {/*from w w w.j a v a 2s. c om*/ String url = _url + "/reference"; String data = HttpUtils.retrieveHttpAsString(url); _title = parseData(data, "<div id=\"tn15title\">", "<span>"); _genre = parseData(data, "<h5>Genre:</h5>", "</div>").replaceAll("See more", "").trim() .replaceAll("\\s+", ""); _director = parseData(data, "<h5>Director:</h5>", "</div>"); if (_director.equals("N|A")) { _director = parseData(data, "Directors:", "</div>").replaceAll("\\s{2,}", "|"); } String rating = parseData(data, "<div class=\"starbar-meta\">", "</b>").replaceAll("/10", ""); if (!rating.equals("N|A") && NumberUtils.isDigits(rating.replaceAll("\\D", "")) && !rating.contains("(awaiting 5 votes)")) { _rating = Integer.valueOf(rating.replaceAll("\\D", "")); String votes = parseData(data, "<a href=\"ratings\" class=\"tn15more\">", " votes</a>"); if (!votes.equals("N|A") && NumberUtils.isDigits(votes.replaceAll("\\D", ""))) _votes = Integer.valueOf(votes.replaceAll("\\D", "")); } _plot = parseData(data, "<h5>Plot:</h5>", "<a class=\"tn15more inline\"").replaceAll("\\s\\|", ""); String year = parseData(data, "<a href=\"/year/", "</a>", true).replaceAll("\\D", ""); if (year.length() == 4) { _year = Integer.valueOf(year); } _limited = ""; try { url = _url + "/business"; data = HttpUtils.retrieveHttpAsString(url); String screens = parseData(data, "<h5>Opening Weekend</h5>", "<br/>"); if (!screens.equals("N|A") && screens.contains(" Screens)") && screens.lastIndexOf(") (") >= 0) { int start = screens.lastIndexOf(") (") + 3; int end = screens.indexOf(" Screens)"); if (start < end) { screens = screens.substring(start, end).replaceAll("\\D", "").trim(); if (!screens.isEmpty()) { _screens = Integer.valueOf(screens); if (_screens < 600) { _limited = " (Limited)"; } } } } } catch (Exception e) { logger.warn("", e); } } catch (Exception e) { logger.error("", e); return false; } return true; }
From source file:org.drftpd.vfs.index.lucene.extensions.flac.FlacDataExtension.java
@Override public void addData(Document doc, ImmutableInodeHandle inode) { VorbisTag vorbisTag = null;/*from w w w .j a va 2s . c om*/ try { FlacInfo flacInfo = inode.getPluginMetaData(FlacInfo.FLACINFO); vorbisTag = flacInfo.getVorbisTag(); } catch (KeyNotFoundException e) { // Fields will be cleared below } if (vorbisTag == null) { FIELD_GENRE.setValue(""); FIELD_TITLE.setValue(""); FIELD_ARTIST.setValue(""); FIELD_ALBUM.setValue(""); FIELD_YEAR.setIntValue(-1); } else { FIELD_GENRE.setValue(vorbisTag.getGenre()); FIELD_TITLE.setValue(vorbisTag.getTitle()); FIELD_ARTIST.setValue(vorbisTag.getArtist()); FIELD_ALBUM.setValue(vorbisTag.getAlbum()); FIELD_YEAR.setIntValue( NumberUtils.isDigits(vorbisTag.getYear()) ? Integer.parseInt(vorbisTag.getYear()) : -1); } }