Java Code Examples for org.apache.commons.lang3.math.NumberUtils.isNumber()

The following are Jave code examples for showing how to use isNumber() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: InComb   File: UserDao.java   View Source Code Vote up 6 votes
/**
 * Converts the given {@link DocumentsSearchResult} to a {@link ISearchResult} containing
 * the found {@link User}s. It extracts all user ids from the {@link Document}s
 * and queries the database for them.
 * @param docsResult the {@link DocumentsSearchResult} to convert.
 * @return {@link ISearchResult} containing the {@link User}s.
 */
private ISearchResult<User> docsToUsers(final DocumentsSearchResult docsResult) {
	final List<Long> userIds = new ArrayList<>();

	for (final Document doc : docsResult.getResults()) {
		final String userId = doc.get(IIndexElement.FIELD_ID);
		if(NumberUtils.isNumber(userId)) {
			userIds.add(Long.valueOf(userId));
		}
		else {
			LOGGER.error("Not numeric user id from index {}.", userId);
		}
	}

	// no results -> return empty ISearchResult
	if(userIds.isEmpty()) {
		return new SimpleSearchResult<User>(new ArrayList<User>(), docsResult.getTotalHits());
	}

	return new SimpleSearchResult<>(DSL.using(jooqConfig).
			select().
			from(TABLE).
			where(TABLE.ID.in(userIds)).
			orderBy(DSL.field("FIELD(id, " + StringUtils.join(userIds, ", ") + ")", Long.class)).
			fetchInto(User.class), docsResult.getTotalHits());
}
 
Example 2
Project: InComb   File: ProviderDao.java   View Source Code Vote up 6 votes
/**
 * Builds {@link Provider}s for the given {@link Document}s.
 * @param docsResult the {@link Document}s to convert.
 * @return a new {@link ISearchResult} containing the {@link Provider}s and the
 * 			totalHits from the given {@link DocumentsSearchResult}.
 */
private ISearchResult<Provider> docsToProviders(final DocumentsSearchResult docsResult) {
	final List<Provider> providers = new ArrayList<>();

	for (final Document doc : docsResult.getResults()) {
		final String providerId = doc.get(IIndexElement.FIELD_ID);
		if(NumberUtils.isNumber(providerId)) {
			providers.add(getProvider(Integer.parseInt(providerId)));
		}
		else {
			LOGGER.error("Not numeric user id from index {}.", providerId);
		}
	}

	return new SimpleSearchResult<>(providers, docsResult.getTotalHits());
}
 
Example 3
Project: NGB-master   File: Utils.java   View Source Code Vote up 6 votes
/**
 * Parses a string, representing an array of integers (e.g. [1,2,3]) into an {@link Integer} array
 * @param arrayString an integer array string
 * @return an {@link Integer} array
 */
public static Integer[] parseIntArray(String arrayString) {
    String[] items = arrayString.replaceAll("\\[", "").replaceAll("\\]", "").split(",");

    Integer[] results = new Integer[items.length];

    for (int i = 0; i < items.length; i++) {
        String numberString = items[i].trim();
        if (NumberUtils.isNumber(numberString)) {
            results[i] = Integer.parseInt(numberString);
        } else {
            return null;
        }
    }

    return results;
}
 
Example 4
Project: Open_Source_ECOA_Toolset_AS5   File: ModuleOperationNode.java   View Source Code Vote up 6 votes
@Override
public ArrayList<String> validate() {
	ArrayList<String> ret = new ArrayList<>();
	if (name == null || name.equalsIgnoreCase("null") || name.trim().length() == 0)
		ret.add("Operation Name Cannot be empty");
	if (type == null || type.equalsIgnoreCase("null") || type.trim().length() == 0)
		ret.add("Operation Type Cannot be empty");
	if (getType().equalsIgnoreCase(Enums.ModuleOperationTypes.REQUEST_SENT.name())) {
		if (timeout == null || timeout.equalsIgnoreCase("null") || timeout.trim().length() == 0 || !NumberUtils.isNumber(timeout))
			ret.add("Timeout Cannot be empty");
	}
	if (getType().equalsIgnoreCase(Enums.ModuleOperationTypes.DATA_READ.name()) || getType().equalsIgnoreCase(Enums.ModuleOperationTypes.DATA_WRITE.name())) {
		if (dType == null || dType.equalsIgnoreCase("null") || dType.trim().length() == 0)
			ret.add("Data Type Cannot be empty");
	}
	return ret;
}
 
Example 5
Project: Open_Source_ECOA_Toolset_AS5   File: LogicalComputingNode.java   View Source Code Vote up 6 votes
@Override
public ArrayList<String> validate() {
	ArrayList<String> ret = new ArrayList<>();
	if (name == null || name.equalsIgnoreCase("null") || name.trim().length() == 0)
		ret.add("Node Name Cannot be empty");
	if (endianess == null || endianess.equalsIgnoreCase("null") || endianess.trim().length() == 0)
		ret.add("Endianess Cannot be empty");
	if (osName == null || osName.equalsIgnoreCase("null") || osName.trim().length() == 0)
		ret.add("OS Name Cannot be empty");
	if (osVer == null || osVer.equalsIgnoreCase("null") || osVer.trim().length() == 0)
		ret.add("OS Version Cannot be empty");
	if (availMem == null || availMem.equalsIgnoreCase("null") || availMem.trim().length() == 0 || (!NumberUtils.isNumber(availMem)))
		ret.add("Available Memory Cannot be empty or a Non-numeric value");
	if (mst == null || mst.equalsIgnoreCase("null") || mst.trim().length() == 0 || (!NumberUtils.isNumber(mst)))
		ret.add("Module Switch Time Cannot be empty or a Non-numeric value");
	return ret;
}
 
Example 6
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static final Long getBigFileThreshold() {
  if (bigFileThreshold == null) {
    String bigThresholdValue = configure.get("filecloud.bigfile-threshold");
    if (StringUtils.isNotBlank(bigThresholdValue) && NumberUtils.isNumber(bigThresholdValue.trim())) {
      bigFileThreshold = NumberUtils.toLong(bigThresholdValue.trim());
    } else {
      bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD;
    }
  }
  return bigFileThreshold;
}
 
Example 7
Project: NGB-master   File: NggbBedCodec.java   View Source Code Vote up 5 votes
private void parseAndSetScore(String[] tokens, int tokenCount, NggbSimpleBedFeature feature) {
    if (tokenCount > SCORE_OFFSET && NumberUtils.isNumber(tokens[SCORE_OFFSET])) {
        try {
            float score = Float.parseFloat(tokens[SCORE_OFFSET]);
            feature.setScore(score);
        } catch (NumberFormatException numberFormatException) {
            feature.setScore(Float.NaN);
        }
    }
}
 
Example 8
Project: NGB-master   File: NggbBedCodec.java   View Source Code Vote up 5 votes
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]));
        }
    }
}
 
Example 9
Project: pay-xxpay-master   File: PayChannelController.java   View Source Code Vote up 5 votes
@RequestMapping("/edit.html")
public String editInput(String id, ModelMap model) {
    PayChannel item = null;
    if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
        item = payChannelService.selectPayChannel(Integer.parseInt(id));
    }
    if(item == null) item = new PayChannel();
    model.put("item", item);
    return "pay_channel/edit";
}
 
Example 10
Project: pay-xxpay-master   File: PayChannelController.java   View Source Code Vote up 5 votes
@RequestMapping("/view.html")
public String viewInput(String id, ModelMap model) {
    PayChannel item = null;
    if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
        item = payChannelService.selectPayChannel(Integer.parseInt(id));
    }
    if(item == null) item = new PayChannel();
    model.put("item", item);
    return "pay_channel/view";
}
 
Example 11
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static final Integer getMaxRetryUploadFastDFSTimes() {
  if (maxRetryUploadFastDFSTimes == null) {
    String maxRetryUploadFastDFSTimesValue = configure.get("filecloud.fdfs-max-retry-times");
    if (StringUtils.isNotBlank(maxRetryUploadFastDFSTimesValue) && NumberUtils.isNumber(maxRetryUploadFastDFSTimesValue.trim())) {
      maxRetryUploadFastDFSTimes = NumberUtils.toInt(maxRetryUploadFastDFSTimesValue.trim());
    } else {
      maxRetryUploadFastDFSTimes = DEFAULT_MAX_RETRY_UPLOAD_TIMES;
    }
  }
  return maxRetryUploadFastDFSTimes;
}
 
Example 12
Project: Open_Source_ECOA_Toolset_AS5   File: DynamicTriggerInstanceNode.java   View Source Code Vote up 5 votes
@Override
public ArrayList<String> validate() {
	ArrayList<String> ret = new ArrayList<>();
	if (name == null || name.equalsIgnoreCase("null") || name.trim().length() == 0)
		ret.add("Dynamic Trigger Instance Name Cannot be empty");
	if (priority == null || priority.equalsIgnoreCase("null") || priority.trim().length() == 0 || (!NumberUtils.isNumber(priority)))
		ret.add("Dynamic Trigger Instance Priority Cannot be empty or a non numeric value");
	return ret;
}
 
Example 13
Project: NGB-master   File: FeatureIndexManager.java   View Source Code Vote up 5 votes
private void addNumberInfo(Map<String, Object> permittedInfo, Map<String, Object> info, int count,
                           VCFHeaderLineType type, InfoItem key) {
    Object value;
    if (count > 1) {
        value = parseNumberArray(type, info.get(key.getName()));

        if (value == null) {
            LOGGER.error(MessageHelper.getMessage(
                MessagesConstants.ERROR_FEATURE_INDEX_WRITING_WRONG_PARAMETER_TYPE,
                key.getName(), key.getType(), info.get(key.getName()).toString()));
            return;
        }

        permittedInfo.put("_" + key.getName() + "_v", info.get(key.getName()).toString());
    } else {
        String numberString = info.get(key.getName()).toString();

        if (NumberUtils.isNumber(numberString)) {
            value = parseNumber(type, info.get(key.getName()));
        } else {
            LOGGER.error(MessageHelper.getMessage(
                MessagesConstants.ERROR_FEATURE_INDEX_WRITING_WRONG_PARAMETER_TYPE, key.getName(), key.getType(),
                numberString));
            return;
        }
    }

    permittedInfo.put(key.getName(), value);
}
 
Example 14
Project: xxpay-master   File: PayChannelController.java   View Source Code Vote up 5 votes
@RequestMapping("/view.html")
public String viewInput(String id, ModelMap model) {
    PayChannel item = null;
    if(StringUtils.isNotBlank(id) && NumberUtils.isNumber(id)) {
        item = payChannelService.selectPayChannel(Integer.parseInt(id));
    }
    if(item == null) item = new PayChannel();
    model.put("item", item);
    return "pay_channel/view";
}
 
Example 15
Project: Open_Source_ECOA_Toolset_AS5   File: DeployedModuleInstanceNode.java   View Source Code Vote up 5 votes
@Override
public ArrayList<String> validate() {
	ArrayList<String> ret = new ArrayList<>();
	if (compName == null || compName.equalsIgnoreCase("null") || compName.trim().length() == 0)
		ret.add("Computing Platform Name Cannot be empty");
	if (moduleName == null || moduleName.equalsIgnoreCase("null") || moduleName.trim().length() == 0)
		ret.add("Module Instance Name Cannot be empty");
	if (priority == null || priority.equalsIgnoreCase("null") || priority.trim().length() == 0 || (!NumberUtils.isNumber(priority)))
		ret.add("Priority Cannot be empty or a Non-numeric value");
	return ret;
}
 
Example 16
Project: Open_Source_ECOA_Toolset_AS5   File: PlatformConfigurationNode.java   View Source Code Vote up 5 votes
@Override
public ArrayList<String> validate() {
	ArrayList<String> ret = new ArrayList<>();
	if (compPlatform == null || compPlatform.equalsIgnoreCase("null") || compPlatform.trim().length() == 0)
		ret.add("Computing Platform Name Cannot be empty");
	if (mcastAddr == null || mcastAddr.equalsIgnoreCase("null") || mcastAddr.trim().length() == 0)
		ret.add("Multicast Address Cannot be empty");
	if (notifMaxNumber == null || notifMaxNumber.equalsIgnoreCase("null") || notifMaxNumber.trim().length() == 0 || (!NumberUtils.isNumber(notifMaxNumber)))
		ret.add("Notification Max Number Cannot be empty or a Non-numeric value");
	if (port == null || port.equalsIgnoreCase("null") || port.trim().length() == 0 || (!NumberUtils.isNumber(port)))
		ret.add("Port Number Cannot be empty or a Non-numeric value");
	if (platNum == null || platNum.equalsIgnoreCase("null") || platNum.trim().length() == 0 || (!NumberUtils.isNumber(platNum)))
		ret.add("Platform Number Cannot be empty or a Non-numeric value");
	return ret;
}
 
Example 17
Project: fastdfs-quickstart   File: Constants.java   View Source Code Vote up 5 votes
public static Long getMinExpireTimeLength() {
  if (minExpireTimeLength == null) {
    String minExpireTime = configure.get("filecloud.min-expire-time-length");
    if (StringUtils.isNotBlank(minExpireTime) && NumberUtils.isNumber(minExpireTime)) {
      minExpireTimeLength = NumberUtils.toLong(minExpireTime);
      if (minExpireTimeLength < 600) {
        minExpireTimeLength = 600L;
      }
    } else {
      minExpireTimeLength = 600L;
    }
  }
  return minExpireTimeLength;
}
 
Example 18
Project: hue   File: CommonUtils.java   View Source Code Vote up 4 votes
public static boolean isNumber(String input) {
	return NumberUtils.isNumber(input);
}
 
Example 19
Project: springboot-shiro-cas-mybatis   File: LdapUtils.java   View Source Code Vote up 3 votes
/**
 * Reads a Long value from the LdapEntry.
 *
 * @param entry     the ldap entry
 * @param attribute the attribute name
 * @param nullValue the value which should be returning in case of a null value
 * @return the long value
 */
public static Long getLong(final LdapEntry entry, final String attribute, final Long nullValue) {
    final String v = getString(entry, attribute, nullValue.toString());
    if (v != null && NumberUtils.isNumber(v)) {
        return Long.valueOf(v);
    }
    return nullValue;
}
 
Example 20
Project: springboot-shiro-cas-mybatis   File: LdapUtils.java   View Source Code Vote up 3 votes
/**
 * Reads a Long value from the LdapEntry.
 *
 * @param entry       the ldap entry
 * @param attribute the attribute name
 * @param nullValue the value which should be returning in case of a null value
 * @return the long value
 */
public static Long getLong(final LdapEntry entry, final String attribute, final Long nullValue) {
    final String v = getString(entry, attribute, nullValue.toString());
    if (v != null && NumberUtils.isNumber(v)) {
        return Long.valueOf(v);
    }
    return nullValue;
}