当前位置: 首页>>代码示例>>Java>>正文


Java NumberUtils类代码示例

本文整理汇总了Java中org.apache.commons.lang3.math.NumberUtils的典型用法代码示例。如果您正苦于以下问题:Java NumberUtils类的具体用法?Java NumberUtils怎么用?Java NumberUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NumberUtils类属于org.apache.commons.lang3.math包,在下文中一共展示了NumberUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
@Override
public List<Proxy> parse(String html) {
    Document document = Jsoup.parse(html);
    Elements elements = document.select("table[id=ip_list] tr[class]");
    List<Proxy> proxyList = new LinkedList<>();
    for (int i = 0; i < elements.size(); i++) {
        if (i == 0) {
            continue;
        }
        Element element = elements.get(i);
        String ip = element.select("td:eq(1)").first().text();
        String port  = element.select("td:eq(2)").first().text();
        String isAnonymous = element.select("td:eq(4)").first().text();
        Proxy p = new Proxy();
        p.setIp(ip);
        p.setPort(NumberUtils.toInt(port));
        p.setAnonymity(isAnonymous);
        proxyList.add(p);
    }
    return proxyList;
}
 
开发者ID:jt120,项目名称:take,代码行数:22,代码来源:XiCiProxyParser.java

示例2: docsToCategories

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * Converts the given {@link DocumentsSearchResult} to a {@link ISearchResult} containing
 * the found {@link Category}s. It extracts all category 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 Category}s.
 */
private ISearchResult<Category> docsToCategories(final DocumentsSearchResult docsResult) {
	final List<Category> categories = new ArrayList<>();

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

	return new SimpleSearchResult<>(categories, docsResult.getTotalHits());
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:23,代码来源:CategoryDao.java

示例3: docsToProviders

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:22,代码来源:ProviderDao.java

示例4: getCurrentPageNum

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * Gets the request page number from the specified path.
 *
 * @param path
 *            the specified path, see {@link #PAGINATION_PATH_PATTERN} for
 *            the details
 * @return page number, returns {@code 1} if the specified request URI can
 *         not convert to an number
 * @see #PAGINATION_PATH_PATTERN
 */
public static int getCurrentPageNum(final String path) {
	logger.trace("Getting current page number[path={}]", path);

	if (StringUtils.isBlank(path) || path.equals("/")) {
		return 1;
	}

	final String currentPageNumber = path.split("/")[0];

	if (!NumberUtils.isDigits(currentPageNumber)) {
		return 1;
	}

	return Integer.valueOf(currentPageNumber);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:26,代码来源:Requests.java

示例5: isCorrectNumericAnswer

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
private boolean isCorrectNumericAnswer(Element blank, Map<String, String> answers) {
    String key = blank.attr("id");
    if (!answers.containsKey(key) || answers.get(key) == null) {
        return false;
    }
    String answerText = answers.get(key);
    answerText = answerText.trim();
    if (!NumberUtils.isParsable(answerText)) {
        return false;
    }
    String precisionAttr = blank.attr("precision");
    Double answer = Double.parseDouble(answerText);
    Double correctAnswer = Double.parseDouble(blank.text().trim());
    Double precision = precisionAttr == null ? 0.0 : Double.parseDouble(precisionAttr);
    return correctAnswer - precision <= answer && answer <= correctAnswer + precision;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:ClozeTestAnswer.java

示例6: isAmbiguityMultipleBand

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * 
 * @param boat
 * @param xPos
 * @param yPos
 * @param deltaAzimuth azimuth correction in pixels
 * @param pxSize
 * @param pySize
 * @return
 * @throws IOException
 */
protected boolean isAmbiguityMultipleBand(Boat boat,int xPos, int yPos,int deltaAzimuth,double pxSize ,double pySize) throws IOException{
	for(int i=0;i<band.length;i++){
 	Window winUp=Window.createWindowFromAzimuth(xPos, yPos, deltaAzimuth,pxSize ,pySize,true);
    // logger.info(new StringBuffer().append("\nSearch Window start from: ").append(winUp.x).append(" ").append(winUp.sizeY).append("  D Azimuth:").append(deltaAzimuth).toString());
     int maxVal=getWindowMaxPixelValue(winUp.x,winUp.y,winUp.sizeX,winUp.sizeY,band[i]);
     
     String bb=sumoImage.getBandName(band[i]);
     int boatMaxValue=NumberUtils.max(boat.getStatMap().getMaxValue(bb));
     if(maxVal>(boatMaxValue*AZIMUT_FACTOR)){
     	return true;
     }else{
     	Window winDown=Window.createWindowFromAzimuth(xPos, yPos, deltaAzimuth,pxSize ,pySize,false);
     	maxVal=getWindowMaxPixelValue(winDown.x,winDown.y,winDown.sizeX,winDown.sizeY,band[i]);
     	if(maxVal>(boatMaxValue*AZIMUT_FACTOR)){
         	return true;
     	}	
     }	
  
	}
	return false;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:33,代码来源:Ambiguity.java

示例7: mafMasterDataSource

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
@Bean(name = ConfigConstant.NAME_DS_MASTER)
@Primary
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_MASTER)
public DataSource mafMasterDataSource() {
    logger.info("----- MAFIA master data source INIT -----");
    DruidDataSource ds = new DruidDataSource();
    try {
        ds.setFilters(env.getProperty("ds.filters"));
    } catch (SQLException e) {
        logger.warn("Data source set filters ERROR:", e);
    }
    ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
    ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
    ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
    ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
    ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
    ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
    ds.setValidationQuery(env.getProperty("ds.validationQuery"));
    ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
    ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
    ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
    ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
    ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
    return ds;
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:26,代码来源:DsMasterConfig.java

示例8: reset

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * Reset password from a mail challenge :token + mail + user name.
 * 
 * @param request
 *            the user request.
 * @param uid
 *            the user UID.
 */
@POST
@Path("reset/{uid}")
@Consumes(MediaType.APPLICATION_JSON)
public void reset(final ResetPasswordByMailChallenge request, @PathParam("uid") final String uid) {
	// check token in database : Invalid token, or out-dated, or invalid
	// user ?
	final PasswordReset passwordReset = repository.findByLoginAndTokenAndDateAfter(uid, request.getToken(),
			DateTime.now().minusHours(NumberUtils.INTEGER_ONE).toDate());
	if (passwordReset == null) {
		throw new BusinessException(BusinessException.KEY_UNKNOW_ID);
	}

	// Check the user and update his/her password
	create(uid, request.getPassword(), false);

	// Remove password reset request since this token is no more valid
	repository.delete(passwordReset);
}
 
开发者ID:ligoj,项目名称:plugin-password,代码行数:27,代码来源:PasswordResource.java

示例9: parseIntArray

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:Utils.java

示例10: parseFloatArray

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * Parses a string, representing an array of float numbers (e.g. [1.4,2.12,3.5]) into a {@link Float} array
 * @param arrayString a float array string
 * @return an {@link Float} array
 */
public static Float[] parseFloatArray(String arrayString) {
    String[] items = arrayString.replaceAll("\\[", "").replaceAll("\\]", "").split(",");

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

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

    return results;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:Utils.java

示例11: handleEquals

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
boolean handleEquals(RestfulMockDefinitionRuleGroupCondition condition, final String inboundValue) {

        if (inboundValue == null) {
            return false;
        }

        final RuleDataTypeEnum ruleMatchDataType = condition.getDataType();
        final String ruleMatchValue = condition.getMatchValue();

        if (RuleDataTypeEnum.TEXT.equals(ruleMatchDataType)) {

            if (condition.isCaseSensitive() != null && condition.isCaseSensitive()) {
                return ruleMatchValue.equals(inboundValue);
            }

            return ruleMatchValue.equalsIgnoreCase(inboundValue);
        } else if (RuleDataTypeEnum.NUMERIC.equals(ruleMatchDataType)
                && NumberUtils.isCreatable(inboundValue)
                && NumberUtils.toDouble(inboundValue) == NumberUtils.toDouble(ruleMatchValue)) {
            return true;
        }

        return false;
    }
 
开发者ID:mgtechsoftware,项目名称:smockin,代码行数:25,代码来源:RuleResolverImpl.java

示例12: WeightedSegmentsFormatter

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
public WeightedSegmentsFormatter(final String[] args) {
    if (args != null) {
        prependPriority = ArrayUtils.contains(args, "-pp") || ArrayUtils.contains(args, "-prependPriority");

        int index1 = ArrayUtils.indexOf(args, "-weight");
        if (index1 < args.length - 1) {
            final String weightString = args[index1 + 1];
            Validate.isTrue(NumberUtils.isParsable(weightString), "Please provide a numeric value for weight.");
            this.weight = Integer.parseInt(weightString);
        }

        int index2 = ArrayUtils.indexOf(args, "-separator");
        if (index2 < args.length - 1) {
            valueSeparator = args[index2 + 1];
        }
    }
}
 
开发者ID:KayLerch,项目名称:alexa-utterance-generator,代码行数:18,代码来源:WeightedSegmentsFormatter.java

示例13: resolveSlotValue

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
public static List<String> resolveSlotValue(final String placeHolderName) {
    final List<String> values = new ArrayList<>();

    Arrays.stream(placeHolderName.split("\\|")).forEach(value -> {
        final String[] ranges = value.split("-");
        if (ranges.length == 2 && NumberUtils.isParsable(ranges[0]) && NumberUtils.isParsable(ranges[1])) {
            final int r1 = Integer.parseInt(ranges[0]);
            final int r2 = Integer.parseInt(ranges[1]);
            final int min = Integer.min(r1, r2);
            final int max = Integer.max(r1, r2);

            for (Integer i = min; i <= max; i++) {
                values.add(i.toString());
            }
        } else {
            values.add(value);
        }
    });
    return values;
}
 
开发者ID:KayLerch,项目名称:alexa-utterance-generator,代码行数:21,代码来源:Resolver.java

示例14: createResponse

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
@Override
public MockResponse createResponse(MockRequest request) {
  int maxNumberOfMessages = NumberUtils
      .toInt(request.getBodyParameters().get("MaxNumberOfMessages"), DEFAULT_FETCH_SIZE);
  // int visibilityTimeout =
  // NumberUtils.toInt(request.getBodyParameters().get("VisibilityTimeout"),DEFAULT_VISIBILITY_TIMEOUT);
  String receiptHandle = UUID.randomUUID().toString();
  String queueName = extractQueueName(request);
  List<SqsMessage> messages = new ArrayList<>();

  if (request.getQueues().containsKey(queueName)) {
    AwsQueue queue = request.getQueues().get(queueName);
    messages = pollMaxMessages(maxNumberOfMessages, queue, receiptHandle);
  }
  String messageResponses =
      messages.stream().map(this::getMessageResponseXml).collect(Collectors.joining("\n"));
  return new MockResponse(request.utils().successBody(RECEIVE_MESSAGE_ACTION, messageResponses));
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:19,代码来源:ReceiveMessageResponder.java

示例15: toVm

import org.apache.commons.lang3.math.NumberUtils; //导入依赖的package包/类
/**
 * Build a described {@link Vm} bean from a XML VMRecord entry.
 */
private VCloudVm toVm(final Element record) {
	final VCloudVm result = new VCloudVm();
	result.setId(StringUtils.removeStart(record.getAttribute("id"), "urn:vcloud:vm:"));
	result.setName(record.getAttribute("name"));
	result.setOs(record.getAttribute("guestOs"));

	// Optional attributes
	result.setStorageProfileName(record.getAttribute("storageProfileName"));
	result.setStatus(EnumUtils.getEnum(VmStatus.class, record.getAttribute("status")));
	result.setCpu(NumberUtils.toInt(StringUtils.trimToNull(record.getAttribute("numberOfCpus"))));
	result.setBusy(Boolean.parseBoolean(ObjectUtils.defaultIfNull(StringUtils.trimToNull(record.getAttribute("isBusy")), "false")));
	result.setVApp(StringUtils.trimToNull(record.getAttribute("containerName")));
	result.setVAppId(StringUtils.trimToNull(StringUtils.removeStart(record.getAttribute("container"), "urn:vcloud:vapp:")));
	result.setRam(NumberUtils.toInt(StringUtils.trimToNull(record.getAttribute("memoryMB"))));
	result.setDeployed(
			Boolean.parseBoolean(ObjectUtils.defaultIfNull(StringUtils.trimToNull(record.getAttribute("isDeployed")), "false")));
	return result;
}
 
开发者ID:ligoj,项目名称:plugin-vm-vcloud,代码行数:22,代码来源:VCloudPluginResource.java


注:本文中的org.apache.commons.lang3.math.NumberUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。