Example usage for org.apache.commons.lang StringUtils isNumeric

List of usage examples for org.apache.commons.lang StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isNumeric.

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:com.flexive.cmis.spi.SPIUtils.java

public static boolean isFolderId(String objectId) {
    return StringUtils.isNumeric(objectId);
}

From source file:com.ewcms.web.pubsub.PubsubServlet.java

private void initDelay() {
    String value = this.getInitParameter(DELAY_PARAM_NAME);
    if (StringUtils.isNumeric(value)) {
        delay = Long.valueOf(value);
    }/*  ww w. java  2s.c o  m*/
}

From source file:br.com.nordestefomento.jrimum.vallia.digitoverificador.GuiaCodigoDeBarrasDV.java

/**
 * @see /*w ww.  jav a 2  s.  co  m*/
 * @since 0.3
 */
@Override
public int calcule(String numero) throws IllegalArgumentException {

    int dv = 0;
    int resto = 0;

    if (StringUtils.isNotBlank(numero) && StringUtils.isNumeric(numero)
            && (numero.length() == TAMANHO_SEM_DV)) {

        // Realizando o clculo do dgito verificador.
        resto = modulo.calcule(numero);

        if (modulo.getMod() == TipoDeModulo.MODULO11) {
            // Seguindo as especificaes da FEBRABAN, caso o resto seja
            // (0), (1) ou (10), ser atribudo (1) ao digito verificador.         
            if ((resto == 0) || (resto == 1) || (resto == 10))
                dv = 1;
            // Caso contrrio, dv = 11 - resto.
            else
                dv = modulo.valor() - resto;
        }

        else if (modulo.getMod() == TipoDeModulo.MODULO10) {
            // Seguindo as especificaes da FEBRABAN, caso o resto seja
            // (0) ou (10), ser atribuido o valor zero.
            if ((resto == 0) || (resto == 10))
                dv = 0;
            // Caso contrrio, dv = 10 - resto.
            else
                dv = modulo.valor() - resto;
        }

    } else {
        throw new IllegalArgumentException("O cdigo de barras " + "[ " + numero
                + " ] deve conter apenas nmeros e " + TAMANHO_SEM_DV + " caracteres.");
    }

    return dv;
}

From source file:br.com.nordestefomento.jrimum.domkee.financeiro.banco.febraban.Modalidade.java

public Integer getCodigoAsInteger() {

    if (StringUtils.isNumeric(codigo)) {
        return Integer.parseInt(codigo);

    } else {//from w  w  w  . jav  a2  s.co  m
        return null;
    }
}

From source file:com.fengduo.spark.commons.test.BaseTestCase.java

/**
 * Assert string contains only unicode digits.
 */
protected void assertNumeric(String str) {
    Assert.assertTrue(StringUtils.isNumeric(str));
}

From source file:com.jfootball.dao.hibernate.CareerDaoImpl.java

/***************************************************************************
 * //www. j  a v a2s  . c  o  m
 * METHODS
 * 
 **************************************************************************/

@Transactional
public void saveOrUpdateCareer(Career career) {
    logger.info("Saving career...");

    if (career.getId() != null) {
        hibernateTemplate.merge(career);
    } else {
        if (career.getStagioni() == null || "".equals(career.getStagioni())
                || !(StringUtils.isNumeric(career.getStagioni())))
            career.setStagioni("1");

        int stagioni = Integer.parseInt(career.getStagioni());

        if ("1".equals(stagioni)) {
            hibernateTemplate.saveOrUpdate(career);
        } else {
            for (int i = 0; i < stagioni; i++) {
                Career bean = new Career();
                bean.setId(null);
                bean.setPlayer(career.getPlayer());
                bean.setSquadra(career.getSquadra());
                bean.setStagioni(career.getStagioni());
                bean.setPeriodo(career.getPeriodo());
                bean.setSerie(career.getSerie());
                bean.setPresenze("?");
                bean.setReti("?");

                hibernateTemplate.saveOrUpdate(bean);

                career.setPeriodo(ProjectUtil.getNextSeason(career.getPeriodo()));
            }
        }

    }
    logger.info("Career saved.");

}

From source file:com.strider.datadefender.extensions.BiographicFunctions.java

/**
 * Algorithm is taken from https://en.wikipedia.org/wiki/Social_Insurance_Number
 * @param sin/*  w  w w  .  ja  va 2s  .co  m*/
 * @return boolean true, if SIN is valid, otherwise false
 */
public static boolean isValidSIN(final String sin) {
    boolean valid = false;

    if (sin.length() < 9) {
        log.debug("SIN length is < 9");

        return valid;
    }

    if (!StringUtils.isNumeric(sin)) {
        log.debug("SIN " + sin + " is not number");

        return valid;
    }

    final int[] sinArray = new int[sin.length()];
    final int[] checkArray = { 1, 2, 1, 2, 1, 2, 1, 2, 1 };
    final List<Integer> sinList = new ArrayList();

    log.info(sin);

    for (int i = 0; i < 9; i++) {
        sinArray[i] = Integer.valueOf(sin.substring(i, i + 1));
        sinArray[i] = sinArray[i] * checkArray[i];
    }

    int sum = 0;

    for (int i = 0; i < 9; i++) {
        final String tmp = String.valueOf(sinArray[i]);

        if (tmp.length() == 1) {
            sinList.add(Integer.valueOf(tmp));
            sum += Integer.valueOf(tmp);
        } else {
            sinList.add(Integer.valueOf(tmp.substring(0, 1)));
            sum += Integer.valueOf(tmp.substring(0, 1));
            sinList.add(Integer.valueOf(tmp.substring(1, 2)));
            sum += Integer.valueOf(tmp.substring(1, 2));
        }
    }

    if ((sum % 10) == 0) {
        valid = true;
    }

    return valid;
}

From source file:com.alibaba.doris.admin.service.config.service.impl.AdminRouteConfigAction.java

public String execute(Map<String, String> params) {

    String configVersion = params.get(AdminServiceConstants.CONFIG_VERSION);

    boolean noVersion = false;
    if (StringUtils.isEmpty(configVersion) || !StringUtils.isNumeric(configVersion)) {
        noVersion = true;// w w  w .  j a v a 2  s  .  co m
    }

    if (noVersion) {
        if (logger.isInfoEnabled()) {
            logger.info("there is no route config version specified. Using 0 as default.");
        }
        configVersion = "0";
    }

    Long version = Long.valueOf(configVersion);

    RouterConfigInstanceDO configInstanceDO = null;

    try {
        if (version == 0) {
            configProcessor.refresh();
        }
        configInstanceDO = configProcessor.getCurrentConfigInstanceDo();
    } catch (DorisConfigServiceException e) {
        logger.error("Cannot get valida route configuration", e);
        SystemLogMonitor.error(MonitorEnum.ROUTER, MonitorWarnConstants.RE_GEN_ROUTE_FAILED, e);
    }

    if (configInstanceDO != null && version == configInstanceDO.getId()) {
        // ?
        configInstanceDO = null;
    }

    if (configInstanceDO != null && version > configInstanceDO.getId()) {
        try {
            // ??Admin configProcessor#urrentConfigInstanceDo
            // ? ?load??
            configProcessor.refreshWithDbLatest();

            RouterConfigInstanceDO refreshedConfigInstanceDO = configProcessor.getCurrentConfigInstanceDo();

            if (refreshedConfigInstanceDO.getId() > version) {
                configInstanceDO = refreshedConfigInstanceDO;
            } else if (refreshedConfigInstanceDO.getId() == version) {
                //? ??
                configInstanceDO = null;
            } else {
                // [??]????admin
                configInstanceDO = refreshedConfigInstanceDO;

                logger.error("Client route version is greater than the version of admin and db; client version:"
                        + version + ", admin version:" + configInstanceDO.getId());
                SystemLogMonitor.error(MonitorEnum.ROUTER, "Clietn route version is greater than admin");
            }
        } catch (DorisConfigServiceException e) {
            logger.error("Cannot get valida route configuration", e);
            SystemLogMonitor.error(MonitorEnum.ROUTER, MonitorWarnConstants.RE_GEN_ROUTE_FAILED, e);
        }
    }

    RouteConfigInstance routeConfigInstance = null;
    if (configInstanceDO != null) {
        routeConfigInstance = new RouteConfigInstance();
        routeConfigInstance.setVersion(configInstanceDO.getId());
        List<StoreNode> storeNodes = JSON.parseArray(configInstanceDO.getContent(), StoreNode.class);
        routeConfigInstance.setStoreNodes(storeNodes);
    }

    return JSON.toJSONString(routeConfigInstance, SerializerFeature.WriteEnumUsingToString);
}

From source file:com.enonic.cms.core.portal.ContentPathResolver.java

private static ContentKey resolveContentKey(String contentNameAndKey, int dotPosition) {
    String contentKeyString;/*w  ww  .  j av  a 2 s.c  o  m*/

    if (dotPosition < 0) {
        contentKeyString = contentNameAndKey;
    } else {
        contentKeyString = contentNameAndKey.substring(dotPosition + 1);
    }

    return StringUtils.isNumeric(contentKeyString) ? new ContentKey(contentKeyString) : null;
}

From source file:gov.medicaid.binders.FacilityCapacityFormBinder.java

/**
 * Binds the request to the model./*from w ww. j av a  2  s.  co m*/
 * @param enrollment the model to bind to
 * @param request the request containing the form fields
 *
 * @throws BinderException if the format of the fields could not be bound properly
 */
public List<BinderException> bindFromPage(CMSUser user, EnrollmentType enrollment, HttpServletRequest request) {
    List<BinderException> exceptions = new ArrayList<BinderException>();
    FacilityCredentialsType creds = XMLUtility.nsGetFacilityCredentials(enrollment);
    String beds = param(request, "numberOfBeds");
    if (StringUtils.isNumeric(beds)) {
        creds.setNumberOfBeds((int) BinderUtils.getAsLong(beds));
    }

    try {
        creds.setNumberOfBedsEffectiveDate(BinderUtils.getAsCalendar(param(request, "effectiveDate")));
    } catch (BinderException e) {
        e.setAttribute(name("effectiveDate"), param(request, "effectiveDate"));
        exceptions.add(e);
    }

    return exceptions;
}