當前位置: 首頁>>代碼示例>>Java>>正文


Java NumberUtils.isNumber方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.math.NumberUtils.isNumber方法的典型用法代碼示例。如果您正苦於以下問題:Java NumberUtils.isNumber方法的具體用法?Java NumberUtils.isNumber怎麽用?Java NumberUtils.isNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.math.NumberUtils的用法示例。


在下文中一共展示了NumberUtils.isNumber方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeNumberScript

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
 * 執行返回數字類型的腳本
 * @param script
 * @return
 */
private DetectResult.Metric executeNumberScript(Script script,int step) {
    if (script != null && script.isValid()){
        try {
            String cmd = "";
            if (script.getScriptType() == ScriptType.SHELL){
                cmd = "sh " + script.getPath();
            }
            if (script.getScriptType() == ScriptType.PYTHON){
                cmd = "python " + script.getPath();
            }
            CommandUtilForUnix.ExecuteResult executeResult = CommandUtilForUnix.execWithReadTimeLimit(cmd,false,5);
            String value = executeResult.msg.trim();
            if (NumberUtils.isNumber(value)){
                return new DetectResult.Metric(script.getMetric(),value, CounterType.valueOf(script.getCounterType()), script.getTags(),step);
            }
        } catch (Exception e) {
            log.error("腳本執行異常",e);
        }
    }
    return null;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:27,代碼來源:ScriptPlugin.java

示例2: getGlobalVariables

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
private Collection<? extends FalconReportObject> getGlobalVariables() throws SQLException, ClassNotFoundException {
        Set<FalconReportObject> reportObjectSet = new HashSet<>();
        String sql = "SHOW /*!50001 GLOBAL */ VARIABLES";
        PreparedStatement pstmt = connection.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()){
            String metric = rs.getString(1);
            String value = rs.getString(2);
            if (NumberUtils.isNumber(value)){
                //收集值為數字的結果
                FalconReportObject falconReportObject = new FalconReportObject();
                MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
                falconReportObject.setCounterType(CounterType.GAUGE);
                //時間戳會統一上報
//                falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
                falconReportObject.setMetric(metric);
                falconReportObject.setValue(value);
                falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
                reportObjectSet.add(falconReportObject);
            }
        }
        rs.close();
        pstmt.close();
        return reportObjectSet;
    }
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:26,代碼來源:Metrics.java

示例3: getGlobalStatus

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
private Collection<? extends FalconReportObject> getGlobalStatus() throws SQLException, ClassNotFoundException {
        Set<FalconReportObject> reportObjectSet = new HashSet<>();
        String sql = "SHOW /*!50001 GLOBAL */ STATUS";
        PreparedStatement pstmt = connection.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()){
            String value = rs.getString(2);
            if (NumberUtils.isNumber(value)){
                String metric = rs.getString(1);
                FalconReportObject falconReportObject = new FalconReportObject();
                MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
                falconReportObject.setCounterType(CounterType.GAUGE);
                //時間戳會統一上報
//                falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
                falconReportObject.setMetric(metric);
                falconReportObject.setValue(value);
                falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
                reportObjectSet.add(falconReportObject);
            }
        }
        rs.close();
        pstmt.close();
        return reportObjectSet;
    }
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:25,代碼來源:Metrics.java

示例4: getRabbitMQFromAddress

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
private RabbitMQ getRabbitMQFromAddress(String address){
    if (StringUtils.isEmpty(address)){
        log.error("轉換的地址為空");
        return null;
    }
    RabbitMQ rabbitMQ = new RabbitMQ();
    String[] split = address.split(":");
    if (split.length != 4){
        log.error("RabbitMQ監控配置不合規:{}",address);
        return null;
    }
    if (!NumberUtils.isNumber(split[1])){
        log.error("端口號配置不合規:{}",split[1]);
        return null;
    }
    rabbitMQ.setIp(split[0]);
    rabbitMQ.setPort(Integer.parseInt(split[1]));
    rabbitMQ.setUsername(split[2]);
    rabbitMQ.setPassword(split[3]);
    return rabbitMQ;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:22,代碼來源:RabbitMQPlugin.java

示例5: setValue

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
public void setValue(String value) {
    if (NumberUtils.isNumber(value) && value.contains("E")) {
        this.value = String.format("%.3f",NumberUtils.toDouble(value)).replace(".000","");
    }else {
        this.value = value;
    }
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:8,代碼來源:FalconReportObject.java

示例6: getLong

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
 * Reads a Long value from the LdapEntry.
 *
 * @param ctx       the ldap entry
 * @param attribute the attribute name
 * @param nullValue the value which should be returning in case of a null value
 */
public static Long getLong(final LdapEntry ctx, final String attribute, final Long nullValue) {
    final String v = getString(ctx, attribute, nullValue.toString());
    if (v != null && NumberUtils.isNumber(v)) {
        return Long.valueOf(v);
    }
    return nullValue;
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:15,代碼來源:LdapUtils.java

示例7: init

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
public void init() {
    String chdelay = System.getProperty("com.oneops.sensor.channel.uptimedelay");
    if (chdelay != null) {
        this.hbChannelUpTimeout = Long.valueOf(chdelay);
    }
    String heartbeatCheckProperty = System.getProperty("sensor.heartbeat.datacheck.minperfevents");
    if (NumberUtils.isNumber(heartbeatCheckProperty)) {
        heartbeatPerfDataPoints = Integer.valueOf(heartbeatCheckProperty.trim());
        logger.info("using property : sensor.heartbeat.datacheck.minperfevents = " + heartbeatCheckProperty);
    }
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:12,代碼來源:OpsEventListener.java

示例8: toBean

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
* 自動匹配參數賦值到實體bean中
  */
 public static void toBean(Object bean, HttpServletRequest req){
     Class<?> clazz = bean.getClass();
     Method ms[] = clazz.getDeclaredMethods();
     String mname;
     String field;
     String fieldType;
     String value;
     for(Method m : ms){
         mname = m.getName();
         if(!mname.startsWith("set")
                 || ArrayUtils.isEmpty(m.getParameterTypes())){
             continue;
         }
         try{
             field = mname.toLowerCase().charAt(3) + mname.substring(4, mname.length());
             value = req.getParameter(field);
             if(LOG.isDebugEnabled()){
             	LOG.debug(field + " = " + value);
             }
             if(StringUtils.isEmpty(value)){
                 continue;
             }
             fieldType = m.getParameterTypes()[0].getName();
             //以下可以確認value為String類型
             if(String.class.getName().equals(fieldType)){
                 m.invoke(bean, (String)value);
             }else if((Byte.class.getName().equals(fieldType)||byte.class.getName().equals(fieldType)) && NumberUtils.isDigits((String)value)){
                 m.invoke(bean, Byte.valueOf((String)value));
             }else if((Integer.class.getName().equals(fieldType)||int.class.getName().equals(fieldType)) && NumberUtils.isDigits((String)value)){
                 m.invoke(bean, Integer.valueOf((String)value));
             }else if((Short.class.getName().equals(fieldType)||short.class.getName().equals(fieldType)) && NumberUtils.isDigits((String)value)){
                 m.invoke(bean, Short.valueOf((String)value));
             }else if((Long.class.getName().equals(fieldType)||long.class.getName().equals(fieldType)) && NumberUtils.isDigits((String)value)){
                 m.invoke(bean, Long.valueOf((String)value));
             }else if((Float.class.getName().equals(fieldType)||float.class.getName().equals(fieldType)) && NumberUtils.isNumber((String)value)){
                 m.invoke(bean, Float.valueOf((String)value));
             }else if((Double.class.getName().equals(fieldType)||double.class.getName().equals(fieldType)) && NumberUtils.isNumber((String)value)){
                 m.invoke(bean, Double.valueOf((String)value));
             }else if(BigDecimal.class.getName().equals(fieldType) && NumberUtils.isNumber((String)value)){
                 m.invoke(bean, new BigDecimal(value));
             }else if(Date.class.getName().equals(fieldType)){
             	String attach0 = "";
             	value = value.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "");
             	for(int i =0; i < (17 - value.length()); i++) {
             		attach0 += "0";
             	}
                 m.invoke(bean, DateUtil.toDate(value + attach0));
             }else{
                 m.invoke(bean, value);
             }
         }catch(Exception e){
             e.printStackTrace();
             continue;
         }
     }
 }
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:60,代碼來源:ReqtoBeanUtil.java

示例9: generateColumnDefaultValueClause

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
 * Generates a clause for any default column value.
 *
 * @param definition the column definition.
 * @return a string containing a readable version of the default value
 */
private static String generateColumnDefaultValueClause(final Column definition) {
  if (StringUtils.isEmpty(definition.getDefaultValue())) {
    return "";
  }
  if (NumberUtils.isNumber(definition.getDefaultValue())) {
    return ", set to " + definition.getDefaultValue();
  } else {
    return ", set to " + generateLiteral(definition.getDefaultValue());
  }
}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:17,代碼來源:HumanReadableStatementHelper.java

示例10: getDBFilesSize

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
     * 獲取宿主機對應連接的數據庫文件大小信息的采集
     * @return
     * @throws SQLException
     * @throws SocketException
     * @throws UnknownHostException
     */
    private Collection<FalconReportObject> getDBFilesSize() throws Exception {
        Set<FalconReportObject> reportObjectSet = new HashSet<>();
        //jdbc:mysql://10.250.140.104:3306
        String url = ((JDBC4Connection) connection).getURL();
        List<String> ips = HostUtil.getHostIps();
        ips.add("127.0.0.1");
        ips.add("localhost");
        ips.add("0.0.0.0");
        for (String ip : ips) {
            url = url.replace(String.format("jdbc:mysql://%s:",ip),"");
        }
        if (NumberUtils.isNumber(url)){ //若有得到該連接下本機有效的端口地址
            String dataDir = getDataDirByPort(url);
            if (dataDir != null){
                List<String> filter = Arrays.asList("mysql","performance_schema","temp","information_schema");
                File dataDirFile = new File(dataDir);
                String[] dirList = dataDirFile.list();
                if (dirList != null){
                    for (String dbName : dirList) {
                        if (!filter.contains(dbName)){
                            try {
                                Path path = Paths.get(dataDir + File.separator + dbName);
                                if (path.toFile().isDirectory()){
                                    Files.walkFileTree(path,new SimpleFileVisitor<Path>(){
                                        @Override
                                        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                                            String fileName = file.getFileName().toString();
                                            String fileNameLower = fileName.toLowerCase();
                                            if(fileNameLower.endsWith(".myi") || fileNameLower.endsWith(".ibd")){
                                                FalconReportObject falconReportObject = new FalconReportObject();
                                                MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
                                                falconReportObject.setCounterType(CounterType.GAUGE);
                                                //時間戳會統一上報
//                                                falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
                                                falconReportObject.setMetric("mysql-file-size");
                                                falconReportObject.setValue(String.valueOf(file.toFile().length()));
                                                falconReportObject.appendTags("database=" + dbName);
                                                falconReportObject.appendTags("table=" + fileName.split("\\.")[0]);
                                                falconReportObject.appendTags("type=" + fileName.split("\\.")[1].toUpperCase());
                                                falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
                                                reportObjectSet.add(falconReportObject);
                                            }

                                            return super.visitFile(file, attrs);
                                        }
                                    });
                                }
                            } catch (IOException e) {
                                log.error("遍曆目錄 {} 發生異常",dbName,e);
                            }
                        }
                    }
                }
            }
        }
        return reportObjectSet;
    }
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:65,代碼來源:Metrics.java

示例11: generatorReportObject

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
 * 生成監控報告的輔助方法
 *
 * @param kitObjectNameMetricses
 * @param metricsValueInfo
 * @return
 */
private Set<FalconReportObject> generatorReportObject(Collection<KitObjectNameMetrics> kitObjectNameMetricses, JMXMetricsValueInfo metricsValueInfo) {
    Set<FalconReportObject> result = new HashSet<>();

    //用於判斷監控值是否重複添加,若出現重複添加,進行監控值比較
    Map<String, FalconReportObject> repeat = new HashMap<>();

    for (KitObjectNameMetrics kitObjectNameMetrics : kitObjectNameMetricses) {
        JMXObjectNameInfo jmxObjectNameInfo = kitObjectNameMetrics.jmxObjectNameInfo;
        JMXMetricsConfiguration jmxMetricsConfiguration = kitObjectNameMetrics.jmxMetricsConfiguration;
        Object metricsValue = jmxObjectNameInfo.getMetricsValue().get(jmxMetricsConfiguration.getMetrics());
        if (metricsValue != null) {
            //服務的標識後綴名
            String name = metricsValueInfo.getJmxConnectionInfo().getName();

            FalconReportObject requestObject = new FalconReportObject();
            setReportCommonValue(requestObject, jmxPlugin.step());
            requestObject.setMetric(getMetricsName(jmxMetricsConfiguration.getAlias()));//設置push obj 的 metrics
            try {
                //設置push obj 的 Counter
                requestObject.setCounterType(CounterType.valueOf(jmxMetricsConfiguration.getCounterType()));
            } catch (IllegalArgumentException e) {
                log.error("錯誤的{} counterType配置:{},隻能是 {} 或 {},未修正前,將忽略此監控值", jmxMetricsConfiguration.getAlias(), jmxMetricsConfiguration.getCounterType(), CounterType.COUNTER, CounterType.GAUGE, e);
                continue;
            }
            requestObject.setTimestamp(metricsValueInfo.getTimestamp());
            requestObject.setObjectName(jmxObjectNameInfo.getObjectName());
            Object newValue = executeJsExpress(kitObjectNameMetrics.jmxMetricsConfiguration.getValueExpress(), metricsValue.toString());
            if (NumberUtils.isNumber(String.valueOf(newValue).trim())) {
                requestObject.setValue(String.valueOf(newValue).trim());
            } else {
                log.error("異常:監控指標值{} - {} : {}不能轉換為數字,將忽略此監控值", jmxMetricsConfiguration.getObjectName(), jmxMetricsConfiguration.getMetrics(), metricsValue);
                continue;
            }

            requestObject.appendTags(getTags(name, jmxPlugin, jmxPlugin.serverName())).appendTags(jmxMetricsConfiguration.getTag());

            //監控值重複性判斷
            FalconReportObject reportInRepeat = repeat.get(jmxMetricsConfiguration.getMetrics());
            if (reportInRepeat == null) {
                //第一次添加
                result.add(requestObject);
                repeat.put(jmxMetricsConfiguration.getMetrics(), requestObject);
            } else {
                if (!reportInRepeat.equals(requestObject)) {
                    // 若已有記錄而且不相同,進行區分保存
                    result.remove(reportInRepeat);
                    reportInRepeat.appendTags(requestObject.getObjectName().toString());//JMX 的ObjectName名稱符合tag格式
                    result.add(reportInRepeat);

                    requestObject.appendTags(requestObject.getObjectName().toString());
                    if (!result.contains(requestObject)) {
                        result.add(requestObject);
                    }
                }
            }
        }
    }
    return result;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:67,代碼來源:JMXMetricsValue.java

示例12: isRightAlign

import org.apache.commons.lang.math.NumberUtils; //導入方法依賴的package包/類
/**
 * Check if the value can be right aligned. Does not trim the values before checking if numeric since it assumes
 * the spaces mean that the value is already padded.
 *
 * @param value to check
 * @return true if the value is a right alignable
 */
protected static boolean isRightAlign(final String value) {
    return value == null || RIGHT_ALIGN_STRINGS.contains(value) || NumberUtils.isNumber(value.trim());
}
 
開發者ID:PAA-NCIC,項目名稱:SparkSeq,代碼行數:11,代碼來源:GATKReportColumn.java


注:本文中的org.apache.commons.lang.math.NumberUtils.isNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。