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:org.drftpd.vfs.index.lucene.extensions.mp3.MP3DataExtension.java
@Override public void addData(Document doc, ImmutableInodeHandle inode) { ID3Tag id3Tag = null;/*from w w w . j av a 2s . c om*/ try { MP3Info mp3Info = inode.getPluginMetaData(MP3Info.MP3INFO); id3Tag = mp3Info.getID3Tag(); } catch (KeyNotFoundException e) { // Fields will be cleared below } if (id3Tag == null) { FIELD_GENRE.setValue(""); FIELD_TITLE.setValue(""); FIELD_ARTIST.setValue(""); FIELD_ALBUM.setValue(""); FIELD_YEAR.setIntValue(-1); } else { FIELD_GENRE.setValue(id3Tag.getGenre()); FIELD_TITLE.setValue(id3Tag.getTitle()); FIELD_ARTIST.setValue(id3Tag.getArtist()); FIELD_ALBUM.setValue(id3Tag.getAlbum()); FIELD_YEAR .setIntValue(NumberUtils.isDigits(id3Tag.getYear()) ? Integer.parseInt(id3Tag.getYear()) : -1); } }
From source file:org.efaps.esjp.admin.index.transformer.StringRight2Long.java
/** * Transform./* ww w. j a v a2s . c o m*/ * * @param _object the object * @return the object * @throws EFapsException on error */ @Override public Object transform(final Object _object) throws EFapsException { Object ret = 0; if (_object instanceof String) { int i = 0; String subStr = "0"; while (NumberUtils.isDigits(subStr) && i - 1 < ((String) _object).length()) { i++; subStr = StringUtils.right((String) _object, i); } if (i - 1 > 0) { ret = Long.parseLong(StringUtils.right((String) _object, i - 1)); } } else { ret = _object; } return ret; }
From source file:org.efaps.esjp.common.uiform.Create_Base.java
/** * Method that insert the basic object./*from w ww . j a va 2s . co m*/ * * @param _parameter Parameter as passed from the efaps API. * @return Instance on the insert * @throws EFapsException on error */ public Instance basicInsert(final Parameter _parameter) throws EFapsException { final AbstractCommand command = (AbstractCommand) _parameter.get(ParameterValues.UIOBJECT); final Instance parent = _parameter.getInstance(); final List<FieldSet> fieldsets = new ArrayList<FieldSet>(); Status status = null; if (getProperty(_parameter, "StatusGroup") != null && getProperty(_parameter, "Status") != null) { status = Status.find(getProperty(_parameter, "StatusGroup"), getProperty(_parameter, "Status")); } Type createType = command.getTargetCreateType(); if (createType.isAbstract()) { final String typeStr = _parameter.getParameterValue(getProperty(_parameter, "TypeFieldName")); if (typeStr != null && !typeStr.isEmpty()) { if (isUUID(typeStr)) { createType = Type.get(UUID.fromString(typeStr)); } else if (Instance.get(typeStr).isValid()) { createType = Type.get(Instance.get(typeStr).getId()); } else if (NumberUtils.isDigits(typeStr)) { createType = Type.get(Long.parseLong(typeStr)); } else { createType = Type.get(typeStr); } } else { createType = null; } } final Insert insert = new Insert(createType); if (status != null) { insert.add(command.getTargetCreateType().getStatusAttribute(), status.getId()); } for (final Field field : command.getTargetForm().getFields()) { final String attrName = field.getAttribute(); if (attrName != null && (field.isEditableDisplay(TargetMode.CREATE) || field.isHiddenDisplay(TargetMode.CREATE))) { if (field instanceof FieldSet) { fieldsets.add((FieldSet) field); } else { final Attribute attr = command.getTargetCreateType().getAttribute(attrName); // check if not a file-upload field if (attr != null && !AbstractFileType.class.isAssignableFrom(attr.getAttributeType().getClassRepr())) { if (_parameter.getParameters().containsKey(field.getName())) { add2Insert(_parameter, insert, attr, field.getName(), 0); } } } } } if (command.getTargetConnectAttribute() != null) { insert.add(command.getTargetConnectAttribute(), parent); } add2basicInsert(_parameter, insert); insert.execute(); final Instance instance = insert.getInstance(); insertFieldSets(_parameter, instance, fieldsets); return instance; }
From source file:org.fabrician.enabler.DockerContainer.java
private String resolveDockerContainerTag() throws Exception { String tag = resolveToString(DOCKER_CONTAINER_NAME_VAR); if (tag.isEmpty() || NumberUtils.isDigits(tag)) { tag = createDockerContainerTag(); getEngineLogger().info("Auto-generate Docker container name tag to [" + tag + "]"); }/* ww w.j av a2 s .c o m*/ return tag; }
From source file:org.flockdata.transform.ExpressionHelper.java
public static Long parseDate(ColumnDefinition colDef, String value) { if (value == null || value.equals("")) return null; if (colDef.isDateEpoc()) { return Long.parseLong(value) * 1000; }// ww w. j ava 2 s .com if (colDef.getDateFormat() == null || colDef.getDateFormat().equalsIgnoreCase("automatic")) { try { return Date.parse(value); } catch (IllegalArgumentException e) { // Try other formats } } if (colDef.getDateFormat() != null && colDef.getDateFormat().equalsIgnoreCase("timestamp")) { try { return Timestamp.valueOf(value).getTime(); } catch (IllegalArgumentException e) { // attempt other conversions } } if (NumberUtils.isDigits(value)) // plain old java millis return Long.parseLong(value); // Custom Date formats String tz = colDef.getTimeZone(); if (tz == null) tz = TimeZone.getDefault().getID(); try { // Try first as DateTime return new SimpleDateFormat(colDef.getDateFormat()).parse(value).getTime(); } catch (DateTimeParseException | IllegalArgumentException | ParseException e) { // Just a plain date DateTimeFormatter pattern = DateTimeFormatter.ofPattern(colDef.getDateFormat(), Locale.ENGLISH); LocalDate date = LocalDate.parse(value, pattern); return new DateTime(date.toString(), DateTimeZone.forID(tz)).getMillis(); } }
From source file:org.forgerock.openidm.shell.impl.RemoteCommandScope.java
private void processOptions(final String userPass, final String idmUrl, final String idmPort) { String username = ""; String password = ""; if (StringUtils.isNotBlank(userPass)) { int passwordIdx = userPass.indexOf(":") + 1; if (passwordIdx > 0) { username = userPass.substring(0, passwordIdx - 1); password = userPass.substring(passwordIdx); } else {/*w w w. java2 s. c o m*/ username = userPass; password = new String(System.console().readPassword("Password:")); } resource.setUsername(username); resource.setPassword(password); } if (StringUtils.isNotBlank(idmUrl)) { resource.setBaseUri(idmUrl.endsWith("/") ? idmUrl : idmUrl + "/"); } if (StringUtils.isNotBlank(idmPort)) { if (NumberUtils.isDigits(idmPort)) { resource.setPort(Integer.decode(idmPort)); } else { throw new IllegalArgumentException("Port must be a number"); } } }
From source file:org.kuali.coeus.common.impl.compliance.core.SpecialReviewServiceImpl.java
@Override public int getProtocolIndex(String prefix) { int index = -1; int lastLeftBracketIndex = StringUtils.lastIndexOf(prefix, '['); int lastRightBracketIndex = StringUtils.lastIndexOf(prefix, ']'); if (lastLeftBracketIndex != -1 && lastRightBracketIndex != -1) { String lineNumber = prefix.substring(lastLeftBracketIndex + 1, lastRightBracketIndex); if (NumberUtils.isDigits(lineNumber)) { index = Integer.parseInt(lineNumber); }/*from w w w .ja v a 2 s . c o m*/ } return index; }
From source file:org.lockss.exporter.biblio.BibliographicUtil.java
/** * Check whether the supplied strings indicate a change of format in their * field; this is inevitably a fuzzy concept, and for the moment we check * for the very simple distinction between digit-numerical and * non-numerical strings. A numerical string is one that represents an integer * with either digits or Roman numerals. Note that digit-numerical and * non-numerical are not complementary concepts. * <p>/*from www.j a v a2 s . c o m*/ * A change between Roman numerals and Arabic numbers is not considered a * change of formats. Strings that consist of only Roman numerals can be * interpreted as either integers or strings (depending on the normalisation * applied to Roman numerals). It is therefore not possible to say strictly * whether a particular string that meets * {@link org.lockss.util.NumberUtil.isRomanNumeral()} is intended as an * integer or a string, so we allow it to meet either criterion. If either * <code>lastVal</code> or <code>thisVal</code> can be parsed as a Roman * numeral, and the other mixes digits and non-digits, it is considered a * change of formats; however if either value can be parsed as a Roman numeral * while the other consists only of digits (is parsable as an integer) or of * non-digits (does not contain digits), we cannot decide if there is a change * of formats and return false. * <p> * If both values are empty, the result is false. * <p> * In future it might be desirable to use a more complex measure * of similarity or difference, for example Levenstein distance or a regexp * and tokenisation. (For example if the formats are both string, test that * there is a common substring at the start.) * * @param lastVal the last value * @param thisVal the current value * @return true if one string contains only digits while the other is not parsable as a number */ public static final boolean changeOfFormats(String lastVal, String thisVal) { if (lastVal == null && thisVal == null) return false; boolean rn1 = NumberUtil.isRomanNumber(lastVal); boolean rn2 = NumberUtil.isRomanNumber(thisVal); // TODO It might be better to only allow normalised Roman numbers using NumberUtil.parseRomanNumber(s, true); boolean mf1 = NumberUtil.isMixedFormat(lastVal); boolean mf2 = NumberUtil.isMixedFormat(thisVal); // If one is Roman and the other is mixed, consider it a change of formats //if ((rn1 && mf2) || (rn2 && mf1)) return true; // If either is a Roman number while the other is not mixed formats, // we can't be sure there is a change //if ((rn1 && !mf2) || (rn2 && !mf1)) return false; // If one is parsable as a Roman numeral, the return value depends upon // whether the other is mixed format. if (rn1) return mf2; if (rn2) return mf1; // Are these strings digit-numerical and/or numerical? boolean i1 = NumberUtils.isDigits(lastVal); boolean i2 = NumberUtils.isDigits(thisVal); boolean n1 = NumberUtil.isNumber(lastVal); boolean n2 = NumberUtil.isNumber(thisVal); // If one is digit-numerical and the other is non-numerical, // there is a definite change of formats. return (i1 && !n2) || (!n1 && i2); }
From source file:org.lockss.util.NumberUtil.java
/** * Determines whether the input string is a mix of digits and non-digits. * This is established by checking that it does not consist of purely digits * but does contain digits. It does not check whether the string has tokens that * can be parsed as Roman numbers, so a string like "vol-XI" is not considered * to have mixed formats.// ww w . j av a 2 s . co m * @param s the input string * @return <tt>true</tt> if the input string contains both digits and non-digits */ public static boolean isMixedFormat(String s) { return !NumberUtils.isDigits(s) && containsDigit(s); }
From source file:org.phenotips.data.internal.controller.APGARController.java
@Override public PatientData<Integer> load(Patient patient) { try {//from ww w. j a v a 2 s . c om XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, Integer> result = new LinkedHashMap<>(); for (String propertyName : getProperties()) { String value = data.getStringValue(propertyName); if (NumberUtils.isDigits(value)) { result.put(propertyName, Integer.valueOf(value)); } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }