org.apache.commons.lang3.math.NumberUtils#isNumber ( )源码实例Demo

下面列出了org.apache.commons.lang3.math.NumberUtils#isNumber ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: archiva   文件: ArchivaRuntimeInfo.java
@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;
}
 
源代码3 项目: confucius-commons   文件: ManagementUtils.java
/**
 * 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;
}
 
源代码4 项目: es-service-parent   文件: KeyWordUtil.java
/**
 * 将字符串按空格分隔,连续的数字+空格分隔为一个词
 * <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;
}
 
源代码7 项目: MicroCommunity   文件: CommonUtil.java
/**
 * 将 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;
}
 
源代码8 项目: warp10-platform   文件: WorfInteractive.java
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;
}
 
源代码9 项目: PneumaticCraft   文件: BlockHeatSensor.java
@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);
}
 
源代码10 项目: quartz-glass   文件: MonthDescriptionBuilder.java
@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);
}
 
源代码11 项目: joyqueue   文件: IgniteBrokerDao.java
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();
}
 
源代码12 项目: nd4j   文件: TFGraphTestAllHelper.java
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;
}
 
源代码13 项目: activiti6-boot2   文件: UserTaskJsonConverter.java
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;
}
 
源代码14 项目: logsniffer   文件: LogEntriesRestController.java
@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);
	}
}
 
源代码15 项目: zest-writer   文件: Configuration.java
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());
    }
}
 
源代码16 项目: jwala   文件: JvmStateReceiverAdapter.java
/**
 * 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));
}
 
源代码17 项目: flink   文件: ParameterTool.java
/**
 * 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);
}
 
源代码18 项目: j360-dubbo-app-all   文件: NumberUtil.java
/**
 * 判断字符串是否合法数字
 */
public static boolean isNumber(String str) {
	return NumberUtils.isNumber(str);
}
 
源代码19 项目: rya   文件: GeoTupleSet.java
@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);
    }
}
 
源代码20 项目: apogen   文件: UtilsStaticAnalyzer.java
/**
 * 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;

}