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


Java NumberUtils.isCreatable方法代码示例

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


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

示例1: 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

示例2: getRedstoneValue

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
@Override
public int getRedstoneValue(World world, BlockPos pos, int sensorRange, String textBoxText, Set<BlockPos> positions) {
    double temperature = Double.MIN_VALUE;
    for (BlockPos p : positions) {
        TileEntity te = world.getTileEntity(p);
        if (te instanceof IHeatExchanger) {
            IHeatExchanger exchanger = (IHeatExchanger) te;
            for (EnumFacing d : EnumFacing.VALUES) {
                IHeatExchangerLogic logic = exchanger.getHeatExchangerLogic(d);
                if (logic != null) temperature = Math.max(temperature, logic.getTemperature());
            }
        }
    }
    return NumberUtils.isCreatable(textBoxText) ?
            temperature - 273 > NumberUtils.toInt(textBoxText) ? 15 : 0 :
            TileEntityCompressedIronBlock.getComparatorOutput((int) temperature);
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:18,代码来源:BlockHeatSensor.java

示例3: parse

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
@Override
public final Number parse(ExecutionContext context, Type type, String raw) {
    if (NumberUtils.isCreatable(raw)) {
        return NumberUtils.createNumber(raw);
    }
    return null;
}
 
开发者ID:ImpactDevelopment,项目名称:ClientAPI,代码行数:8,代码来源:NumberParser.java

示例4: doAuthentication

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
    final GoogleAuthenticatorTokenCredential tokenCredential = (GoogleAuthenticatorTokenCredential) credential;

    if (!NumberUtils.isCreatable(tokenCredential.getToken())) {
        throw new PreventedException("Invalid non-numeric OTP format specified.",
                new IllegalArgumentException("Invalid token " + tokenCredential.getToken()));
    }
    final int otp = Integer.parseInt(tokenCredential.getToken());
    LOGGER.debug("Received OTP [{}]", otp);

    final RequestContext context = RequestContextHolder.getRequestContext();
    if (context == null) {
        new IllegalArgumentException("No request context could be found to locate an authentication event");
    }
    final Authentication authentication = WebUtils.getAuthentication(context);
    if (authentication == null) {
        new IllegalArgumentException("Request context has no reference to an authentication event to locate a principal");
    }
    final String uid = authentication.getPrincipal().getId();

    LOGGER.debug("Received principal id [{}]", uid);
    final String secKey = this.credentialRepository.getSecret(uid);
    if (StringUtils.isBlank(secKey)) {
        throw new AccountNotFoundException(uid + " cannot be found in the registry");
    }

    if (this.tokenRepository.exists(uid, otp)) {
        throw new AccountExpiredException(uid + " cannot reuse OTP " + otp + " as it may be expired/invalid");
    }

    final boolean isCodeValid = this.googleAuthenticatorInstance.authorize(secKey, otp);
    if (isCodeValid) {
        this.tokenRepository.store(new GoogleAuthenticatorToken(otp, uid));
        return createHandlerResult(tokenCredential, this.principalFactory.createPrincipal(uid), null);
    }
    throw new FailedLoginException("Failed to authenticate code " + otp);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:39,代码来源:GoogleAuthenticatorAuthenticationHandler.java

示例5: shouldRenewAuthentication

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
 * Is authentication required?
 *
 * @param fedRequest the fed request
 * @param request    the request
 * @return the boolean
 */
protected boolean shouldRenewAuthentication(final WSFederationRequest fedRequest,
                                            final HttpServletRequest request) {
    if (StringUtils.isBlank(fedRequest.getWfresh()) || NumberUtils.isCreatable(fedRequest.getWfresh())) {
        return false;
    }
    final long ttl = Long.parseLong(fedRequest.getWfresh().trim());
    if (ttl == 0) {
        return false;
    }

    final SecurityToken idpToken = getSecurityTokenFromRequest(request);
    if (idpToken == null) {
        return true;
    }

    final long ttlMs = ttl * 60L * 1000L;
    if (ttlMs > 0) {
        final Date createdDate = idpToken.getCreated();
        if (createdDate != null) {
            final Date expiryDate = new Date();
            expiryDate.setTime(createdDate.getTime() + ttlMs);
            if (expiryDate.before(new Date())) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:36,代码来源:BaseWSFederationRequestController.java

示例6: CasConfigurationJasyptDecryptor

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public CasConfigurationJasyptDecryptor(final Environment environment) {
    this.decryptor = new StandardPBEStringEncryptor();

    final String alg = getJasyptParamFromEnv(environment, JasyptEncryptionParameters.ALGORITHM);
    if (StringUtils.isNotBlank(alg)) {
        LOGGER.debug("Configured decryptor algorithm [{}]", alg);
        decryptor.setAlgorithm(alg);
    }

    final String psw = getJasyptParamFromEnv(environment, JasyptEncryptionParameters.PASSWORD);
    if (StringUtils.isNotBlank(psw)) {
        LOGGER.debug("Configured decryptor password");
        decryptor.setPassword(psw);
    }

    final String pName = getJasyptParamFromEnv(environment, JasyptEncryptionParameters.PROVIDER);
    if (StringUtils.isNotBlank(pName)) {
        LOGGER.debug("Configured decryptor provider");
        if (StringUtils.equals(pName, BouncyCastleProvider.PROVIDER_NAME)) {
            Security.addProvider(new BouncyCastleProvider());
        }
        this.decryptor.setProviderName(pName);
    }
    final String iter = getJasyptParamFromEnv(environment, JasyptEncryptionParameters.ITERATIONS);
    if (StringUtils.isNotBlank(iter) && NumberUtils.isCreatable(iter)) {
        LOGGER.debug("Configured decryptor iterations");
        decryptor.setKeyObtentionIterations(Integer.valueOf(iter));
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:CasConfigurationJasyptDecryptor.java

示例7: newDuration

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
 * New duration. If the provided length is duration,
 * it will be parsed accordingly, or if it's a numeric value
 * it will be pared as a duration assuming it's provided as seconds.
 *
 * @param length the length in seconds.
 * @return the duration
 */
public static Duration newDuration(final String length) {
    try {
        if (NumberUtils.isCreatable(length)) {
            return Duration.ofSeconds(Long.valueOf(length));
        }
        return Duration.parse(length);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:Beans.java

示例8: changeProperty

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
 * Change the Username of the Bot
 * @param event MessageEvent
 * @param args Argumente
 * @return state
 */
@Command(
        command = "changeprop",
        arguments = {"Option", "Value"},
        description = "Change the Property",
        alias = "chp",
        permission = Globals.BOT_OWNER,
        prefix = Globals.ADMIN_PREFIX
)
public boolean changeProperty(MessageReceivedEvent event, String[] args) {
        if (args[0].equalsIgnoreCase("NA") || args[1].equalsIgnoreCase("NA")) {
            BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.ERROR+ LANG.getTranslation("notchanged_error")), true);
        } else {
            if (!DRIVER.getPropertyOnly(DRIVER.CONFIG, args[0]).equals("No Value")) {
                Object value = args[1];
                boolean error = false;
                if (args[1].equalsIgnoreCase("false") || args[1].equalsIgnoreCase("true")) {
                    value = Boolean.valueOf(args[1]);
                }
                try {
                    if (NumberUtils.isCreatable(args[1])) {
                        value = NumberFormat.getInstance().parse(args[1]);
                    }

                } catch (Exception ex) {
                    BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.ERROR + LANG.getTranslation("parse_error")), true);
                    error = true;
                }
                if (!error) {
                    DRIVER.setProperty(DRIVER.CONFIG, args[0], value);
                    BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS+LANG.getTranslation("command_success")), true);
                }
                DRIVER.saveJson();
            } else {
                BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.ERROR+ LANG.getTranslation("changeprop_error")), true);
            }
        }
    return true;
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:45,代码来源:ChangeCommands.java

示例9: plainJava

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/** Exposed for unit testing. */
static boolean plainJava(TypeKind kind, String text) {
    switch (kind) {
        case BOOLEAN: return "true".equals(text) || "false".equals(text);
        case BYTE:    return NumberUtils.isCreatable(text);  // Unfortunately doesn't handle "12_345".
        case CHAR:    return text.matches("'.'");            // e.g. 'a', '\t'; note that newline isn't a character
        case DOUBLE:  return NumberUtils.isCreatable(text);
        case FLOAT:   return NumberUtils.isCreatable(text);
        case INT:     return NumberUtils.isCreatable(text);
        case LONG:    return NumberUtils.isCreatable(text);
        case SHORT:   return NumberUtils.isCreatable(text);
        default:      return false;
    }
}
 
开发者ID:dleppik,项目名称:EgTest,代码行数:15,代码来源:GroovyInjector.java

示例10: generateRandomforRange

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
private int generateRandomforRange(final String range) {

        String arg = null;

        if (range.toUpperCase().contains(TO_ARG)) {
            arg = TO_ARG;
        } else if (range.toUpperCase().contains(UNTIL_ARG)) {
            arg = UNTIL_ARG;
        }

        if (arg == null) {
            throw new IllegalArgumentException("Expected '" + TO_ARG + "' or '" + UNTIL_ARG + "' arg in '" + ParamMatchTypeEnum.RANDOM_NUMBER.name() + "=' token");
        }

        final String[] rangeToArray = range.toUpperCase().split(arg);

        if (rangeToArray.length != 2) {
            throw new IllegalArgumentException("Missing number range for '" + arg + "' args. (i.e expect 1 " + arg + " 5)");
        }

        if (!NumberUtils.isCreatable(StringUtils.trim(rangeToArray[0]))
                || !NumberUtils.isCreatable(StringUtils.trim(rangeToArray[1]))) {
            throw new IllegalArgumentException("Range does not contain valid numbers. (i.e expect 1 " + arg + " 5)");
        }

        final int start = NumberUtils.toInt(StringUtils.trim(rangeToArray[0]));
        final int end = NumberUtils.toInt(StringUtils.trim(rangeToArray[1]));

        if (start >= 0 && end > 0) {

            return RandomUtils.nextInt(start, (arg.equals(TO_ARG))?(end+1):end);
        } else if (start <= 0 && end >= 0) {

            int s = -Math.abs(RandomUtils.nextInt(0, (arg.equals(TO_ARG))?(Math.abs(start)+1):Math.abs(start)));
            int e = RandomUtils.nextInt(0, (arg.equals(TO_ARG))?(end+1):end);

            return (e + s);
        } else if (start < 0 && end < 0) {

           return -Math.abs(RandomUtils.nextInt(Math.abs(end), (arg.equals(TO_ARG))?(Math.abs(start)+1):Math.abs(start)));
        }

        return 0;
    }
 
开发者ID:mgtechsoftware,项目名称:smockin,代码行数:45,代码来源:InboundParamMatchServiceImpl.java

示例11: isNumber

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
 * 判断字符串是否合法数字
 */
public static boolean isNumber(String str) {
	return NumberUtils.isCreatable(str);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:NumberUtil.java

示例12: getLong

import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
/**
 * 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.isCreatable(v)) {
        return Long.valueOf(v);
    }
    return nullValue;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:LdapUtils.java


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