下面列出了org.apache.commons.lang3.math.NumberUtils#isNumber ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Inject
public ArchivaRuntimeInfo( @Named( value = "archivaRuntimeProperties" ) Properties archivaRuntimeProperties )
{
this.version = (String) archivaRuntimeProperties.get( "archiva.version" );
this.buildNumber = (String) archivaRuntimeProperties.get( "archiva.buildNumber" );
String archivaTimeStamp = (String) archivaRuntimeProperties.get( "archiva.timestamp" );
if ( NumberUtils.isNumber( archivaTimeStamp ) )
{
this.timestamp = NumberUtils.createLong( archivaTimeStamp );
}
else
{
this.timestamp = new Date().getTime();
}
this.devMode = Boolean.getBoolean( "archiva.devMode" );
}
protected Collection<ProposalDescriptor> createEnumProposals(TypeDefinition type, AbstractNode node) {
final Collection<ProposalDescriptor> proposals = new LinkedHashSet<>();
final String subType = type.asJson().has("type") ? //
type.asJson().get("type").asText() : //
null;
String replStr;
for (String literal : enumLiterals(type)) {
// if the type of array is string and
// current value is a number, it should be put
// into quotes to avoid validation issues
if ((NumberUtils.isNumber(literal) && "string".equals(subType)) || "null".equals(literal)) {
replStr = "\"" + literal + "\"";
} else {
replStr = literal;
}
String labelType = type.getType().getValue();
proposals.add(new ProposalDescriptor(literal).replacementString(replStr).description(type.getDescription()).type(labelType));
}
return proposals;
}
/**
* Get the process ID of current JVM
*
* @return If can't get the process ID , return <code>-1</code>
*/
public static int getCurrentProcessId() {
int processId = -1;
Object result = invoke(getProcessIdMethod, jvm);
if (result instanceof Integer) {
processId = (Integer) result;
} else {
// no guarantee
String name = runtimeMXBean.getName();
String processIdValue = StringUtils.substringBefore(name, "@");
if (NumberUtils.isNumber(processIdValue)) {
processId = Integer.parseInt(processIdValue);
}
}
return processId;
}
/**
* 将字符串按空格分隔,连续的数字+空格分隔为一个词
* <p>
*
* @param keyWord
* @return
*/
public static List<String> processKeyWord(String keyWord) {
String[] keys = keyWord.trim().split("\\s+");
List<String> keys_list = new ArrayList<String>();
keys_list.add(keyWord);
for (String key : keys) {
if (keys_list.size() > 0 && NumberUtils.isNumber(key)) {
String pre = keys_list.get(keys_list.size() - 1);
if (NumberUtils.isNumber(pre.replace(" ", ""))) {
keys_list.set(keys_list.size() - 1, pre.concat(" ").concat(key));
continue;
}
}
if (!keys_list.contains(key)) {
keys_list.add(key);
}
}
return keys_list;
}
private DataValue getObjForValue(String value) {
if (value == null) {
return DataValueString.builder()
.value(StringUtils.EMPTY)
.build();
} else {
if (NumberUtils.isNumber(value)) {
if (Ints.tryParse(value) != null) {
return DataValueInteger.builder()
.value(Integer.parseInt(value))
.build();
} else {
return DataValueDouble.builder()
.value(Double.parseDouble(value))
.build();
}
} else {
return DataValueString.builder()
.value(value)
.build();
}
}
}
private Double[] extractEnvelope(String sBbox) {
Double[] envelope = null;
if (sBbox != null) {
String[] corners = sBbox.split(",");
if (corners != null && corners.length == 2) {
String[] minXminY = corners[0].split(" ");
String[] maxXmaxY = corners[1].split(" ");
if (minXminY != null && minXminY.length == 2 && maxXmaxY != null && maxXmaxY.length == 2) {
minXminY[0] = StringUtils.trimToEmpty(minXminY[0]);
minXminY[1] = StringUtils.trimToEmpty(minXminY[1]);
maxXmaxY[0] = StringUtils.trimToEmpty(maxXmaxY[0]);
maxXmaxY[1] = StringUtils.trimToEmpty(maxXmaxY[1]);
Double minX = NumberUtils.isNumber(minXminY[0]) ? NumberUtils.createDouble(minXminY[0]) : null;
Double minY = NumberUtils.isNumber(minXminY[1]) ? NumberUtils.createDouble(minXminY[1]) : null;
Double maxX = NumberUtils.isNumber(maxXmaxY[0]) ? NumberUtils.createDouble(maxXmaxY[0]) : null;
Double maxY = NumberUtils.isNumber(maxXmaxY[1]) ? NumberUtils.createDouble(maxXmaxY[1]) : null;
if (minX != null && minY != null && maxX != null && maxY != null) {
envelope = new Double[]{minX, minY, maxX, maxY};
}
}
}
}
return envelope;
}
/**
* 将 30*1000 转为 30000
* 不能出现小数点等
*
* @param val
* @return
*/
public static int multiplicativeStringToInteger(String val) {
try {
if (StringUtils.isEmpty(val)) {
return 0;
}
if (val.contains("*")) {
String[] vals = val.split("\\*");
int value = 1;
for (int vIndex = 0; vIndex < vals.length; vIndex++) {
if (!NumberUtils.isNumber(vals[vIndex])) {
throw new ClassCastException("配置的数据有问题,必须配置为30*1000格式");
}
value *= Integer.parseInt(vals[vIndex]);
}
return value;
}
if (NumberUtils.isNumber(val)) {
return Integer.parseInt(val);
}
} catch (Exception e) {
logger.error("---------------[CommonUtil.multiplicativeStringToInteger]----------------类型转换失败", e);
return 0;
}
return 0;
}
private static String readInteger(ConsoleReader reader, PrintWriter out, String prompt) {
try {
String inputString = readInputString(reader, out, prompt);
if (NumberUtils.isNumber(inputString)) {
return inputString;
}
if (InetAddresses.isInetAddress(inputString)) {
return inputString;
}
out.println("Error, " + inputString + " is not a number");
} catch (Exception exp) {
if (WorfCLI.verbose) {
exp.printStackTrace();
}
out.println("Error, unable to read the host. error=" + exp.getMessage());
}
return null;
}
@Override
public int getRedstoneValue(World world, int x, int y, int z, int sensorRange, String textBoxText, Set<ChunkPosition> positions){
double temperature = Double.MIN_VALUE;
for(ChunkPosition pos : positions) {
TileEntity te = world.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if(te instanceof IHeatExchanger) {
IHeatExchanger exchanger = (IHeatExchanger)te;
for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
IHeatExchangerLogic logic = exchanger.getHeatExchangerLogic(d);
if(logic != null) temperature = Math.max(temperature, logic.getTemperature());
}
}
}
return NumberUtils.isNumber(textBoxText) ? temperature - 273 > NumberUtils.toInt(textBoxText) ? 15 : 0 : TileEntityCompressedIronBlock.getComparatorOutput((int)temperature);
}
@Override
protected String getSingleItemDescription(String expression) {
if (!NumberUtils.isNumber(expression)) {
return DateTimeFormat.forPattern("MMM").withLocale(Locale.ENGLISH).parseDateTime(expression).toString("MMMM", Locale.ENGLISH);
}
return new DateTime().withDayOfMonth(1).withMonthOfYear(Integer.parseInt(expression)).toString("MMMM", Locale.ENGLISH);
}
private SqlQuery buildQuery(BrokerQuery query) {
IgniteDao.SimpleSqlBuilder sqlBuilder = IgniteDao.SimpleSqlBuilder.create(IgniteBroker.class);
if (query != null) {
if (query.getIp() != null && !query.getIp().isEmpty()) {
sqlBuilder.and(IgniteBroker.COLUMN_IP, query.getIp());
}
if (query.getBrokerId() > 0) {
sqlBuilder.and(IgniteBroker.COLUMN_BROKER_ID, query.getBrokerId());
}
if (query.getPort() > 0) {
sqlBuilder.and(IgniteBroker.COLUMN_PORT, query.getPort());
}
if (query.getRetryType() != null && !query.getRetryType().isEmpty()) {
sqlBuilder.and(IgniteBroker.COLUMN_RETRY_TYPE, query.getRetryType());
}
if (StringUtils.isNotEmpty(query.getKeyword())) {
sqlBuilder.and(IgniteBroker.COLUMN_IP,query.getKeyword());
if (NumberUtils.isNumber(query.getKeyword())){
sqlBuilder.or(IgniteBroker.COLUMN_BROKER_ID,Integer.valueOf(query.getKeyword()).intValue());
}
}
if (query.getBrokerList() != null && !query.getBrokerList().isEmpty()) {
sqlBuilder.in(IgniteBroker.COLUMN_BROKER_ID, query.getBrokerList());
}
}
return sqlBuilder.build();
}
public static Set<String> confirmPatternMatch(Set<String> setOfNames, String varName) {
Set<String> removeList = new HashSet<>();
for (String name : setOfNames) {
if (name.equals(varName)) continue;
String[] splitByPeriod = name.split("\\.");
//not a number - maybe another variable deeper in the same scope
if (!NumberUtils.isNumber(splitByPeriod[splitByPeriod.length - 1])) {
removeList.add(name);
} else if (!String.join(".", Arrays.copyOfRange(splitByPeriod, 0, splitByPeriod.length - 1)).equals(varName)) {
removeList.add(name);
}
}
return removeList;
}
protected int getExtensionElementValueAsInt(String name, UserTask userTask) {
int intValue = 0;
String value = getExtensionElementValue(name, userTask);
if (value != null && NumberUtils.isNumber(value)) {
intValue = Integer.valueOf(value);
}
return intValue;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public NavigationFuture navigate(final LogSource<? extends LogRawAccess<? extends LogInputStream>> logSource,
final LogRawAccess<? extends LogInputStream> logAccess, final Log log, final String strPosition)
throws IOException {
if (NumberUtils.isNumber(strPosition)) {
final Date from = new Date(Long.parseLong(strPosition));
if (logAccess instanceof ByteLogAccess) {
final LogEntryReader reader = logSource.getReader();
if (reader.getFieldTypes().containsKey(LogEntry.FIELD_TIMESTAMP)) {
return new TimestampNavigation(log, (ByteLogAccess) logAccess, reader).absolute(from);
} else {
throw new IOException(
"Navigation by date isn't supported, because the reader doesn't list the mandatory field: "
+ LogEntry.FIELD_TIMESTAMP);
}
} else {
final Navigation<?> nav = logAccess.getNavigation();
if (nav instanceof DateOffsetNavigation) {
return ((DateOffsetNavigation) nav).absolute(from);
}
throw new IOException("Navigation by date isn't supported by this log source: " + logSource);
}
} else {
throw new IOException("Position isn't of type numer/date: " + strPosition);
}
}
private double getGenericDoubleDisplay(ConfigData configData) {
if(conf.containsKey(configData.getKey())){
if(NumberUtils.isNumber(conf.getProperty(configData.getKey())))
return Double.parseDouble(conf.getProperty(configData.getKey()));
else
return Double.parseDouble(configData.getDefaultValue());
}else{
return Double.parseDouble(configData.getDefaultValue());
}
}
/**
* Get the JVM with parameters provided in a map
* @param serverInfoMap the map that contains the JVM id or name
* @return {@link Jvm}
*/
private Jvm getJvm(final Map serverInfoMap) {
final String id = getStringFromMessageMap(serverInfoMap, ID_KEY);
if (id != null && NumberUtils.isNumber(id)) {
return getJvmById(Long.parseLong(id));
}
// try to get the JVM by name instead
return getJvmByName(getStringFromMessageMap(serverInfoMap, NAME_KEY));
}
/**
* Returns {@link ParameterTool} for the given arguments. The arguments are keys followed by values.
* Keys have to start with '-' or '--'
*
* <p><strong>Example arguments:</strong>
* --key1 value1 --key2 value2 -key3 value3
*
* @param args Input array arguments
* @return A {@link ParameterTool}
*/
public static ParameterTool fromArgs(String[] args) {
final Map<String, String> map = new HashMap<>(args.length / 2);
int i = 0;
while (i < args.length) {
final String key = Utils.getKeyFromArgs(args, i);
if (key.isEmpty()) {
throw new IllegalArgumentException(
"The input " + Arrays.toString(args) + " contains an empty argument");
}
i += 1; // try to find the value
if (i >= args.length) {
map.put(key, NO_VALUE_KEY);
} else if (NumberUtils.isNumber(args[i])) {
map.put(key, args[i]);
i += 1;
} else if (args[i].startsWith("--") || args[i].startsWith("-")) {
// the argument cannot be a negative number because we checked earlier
// -> the next argument is a parameter name
map.put(key, NO_VALUE_KEY);
} else {
map.put(key, args[i]);
i += 1;
}
}
return fromMap(map);
}
/**
* 判断字符串是否合法数字
*/
public static boolean isNumber(String str) {
return NumberUtils.isNumber(str);
}
@Override
public CloseableIteration<Statement, QueryEvaluationException> performSearch(final String queryText,
final StatementConstraints contraints) throws QueryEvaluationException {
try {
final String[] args = queryText.split(NEAR_DELIM);
Optional<Double> maxDistanceOpt = Optional.empty();
Optional<Double> minDistanceOpt = Optional.empty();
final String query = args[0];
for (int ii = 1; ii < args.length; ii++) {
String numArg = args[ii];
// remove pre-padding 0's since NumberUtils.isNumber()
// will assume its octal if it starts with a 0.
while (numArg.startsWith("0")) {
numArg = numArg.substring(1);
}
// was 0
if (numArg.equals("")) {
// if max hasn't been set, set it to 0.
// Otherwise, min is just ignored.
if (!maxDistanceOpt.isPresent()) {
maxDistanceOpt = Optional.of(0.0);
}
} else {
if (!maxDistanceOpt.isPresent() && NumberUtils.isNumber(numArg)) {
// no variable identifier, going by order.
maxDistanceOpt = getDistanceOpt(numArg, "maxDistance");
} else if (NumberUtils.isNumber(numArg)) {
// no variable identifier, going by order.
minDistanceOpt = getDistanceOpt(numArg, "minDistance");
} else {
throw new IllegalArgumentException(numArg + " is not a valid Near function argument.");
}
}
}
final WKTReader reader = new WKTReader();
final Geometry geometry = reader.read(query);
final NearQuery nearQuery = new NearQuery(maxDistanceOpt, minDistanceOpt, geometry);
return geoIndexer.queryNear(nearQuery, contraints);
} catch (final ParseException e) {
throw new QueryEvaluationException(e);
}
}
/**
* BETA VERSION: trims the url of the web page, to get an meaningful name for
* the PO test the correct use of last index of and extension removal
*
* @param statesList
* @throws MalformedURLException
*/
public static String getClassNameFromUrl(State state, List<State> statesList) throws MalformedURLException {
// new add: check it does not lead to inconsistencies
if (state.getStateId().equals("index")) {
return toSentenceCase("index");
}
String s = state.getUrl();
String toTrim = "";
URL u = new URL(s);
toTrim = u.toString();
// retrieves the page name
toTrim = toTrim.substring(toTrim.lastIndexOf('/') + 1, toTrim.length());
// removes the php extension if any
toTrim = toTrim.replace(".php", "");
// removes the html extension if any
toTrim = toTrim.replace(".html", "");
// removes the & and ?
if (toTrim.contains("?"))
toTrim = toTrim.substring(0, toTrim.indexOf('?'));
// camel case the string
toTrim = toSentenceCase(toTrim);
// check the uniqueness, solve the ambiguity otherwise
toTrim = solveAmbiguity(toTrim, statesList);
if (toTrim == "") {
toTrim = u.getFile();
// retrieves the page name
toTrim = toTrim.substring(toTrim.lastIndexOf('/') + 1, toTrim.length());
// removes the php extension if any
toTrim = toTrim.replace(".php", "");
// removes the html extension if any
toTrim = toTrim.replace(".html", "");
// removes the & and ?
if (toTrim.contains("?"))
toTrim = toTrim.substring(0, toTrim.indexOf('?'));
// camel case the string
toTrim = toSentenceCase(toTrim);
// check the uniqueness, solve the ambiguity otherwise
toTrim = solveAmbiguity(toTrim, statesList);
}
if (toTrim == "") {
return toSentenceCase(state.getStateId());
}
if (NumberUtils.isNumber(toTrim) || NumberUtils.isDigits(toTrim)) {
return toSentenceCase("PageObject_" + toTrim);
}
return toTrim;
}