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

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

Introduction

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

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:com.inkubator.hrm.web.appraisal.AppraisalPerformGroupDetailController.java

@PostConstruct
@Override/*ww w.ja v a2 s. co m*/
public void initialization() {
    super.initialization();
    try {

        listPerformanceAppraisalIndicator = new ArrayList<AppraisalPerformanceIndicator>();
        String idAppraisalPerformanceGroup = FacesUtil.getRequestParameter("execution");
        if (StringUtils.isNotBlank(idAppraisalPerformanceGroup)
                && StringUtils.isNumeric(idAppraisalPerformanceGroup)) {
            selectedAppraisalPerformanceGroup = appraisalPerformanceGroupService
                    .getEntiyByPK(Long.valueOf(idAppraisalPerformanceGroup));
            listPerformanceAppraisalIndicator = appraisalPerformanceIndicatorService
                    .getListByIdAppraisalPerformanceGroup(Long.valueOf(idAppraisalPerformanceGroup));
        }

    } catch (Exception e) {
        LOGGER.error("Error", e);
    }
}

From source file:net.mindengine.galen.parser.MathParser.java

private String convertExpression(String initialValue, String expression) {
    String number = expression.substring(1);
    if (!StringUtils.isNumeric(number)) {
        throw new SyntaxException("Expected a number: " + number);
    }/*w  w  w.ja  va 2s.com*/

    if (StringUtils.isNumeric(initialValue)) {
        char operationSymbol = expression.charAt(0);

        int initial = Integer.parseInt(initialValue);
        int added = Integer.parseInt(number);

        if (operationSymbol == '+') {
            return Integer.toString(initial + added);
        } else if (operationSymbol == '-') {
            return Integer.toString(initial - added);
        } else if (operationSymbol == '*') {
            return Integer.toString(initial * added);
        } else if (operationSymbol == '/') {
            return Integer.toString(initial / added);
        } else if (operationSymbol == '%') {
            return Integer.toString(initial % added);
        } else
            throw new SyntaxException("Unknown operation: " + operationSymbol);
    } else {
        return initialValue;
    }
}

From source file:kenh.xscript.elements.Accum.java

public void process(@Attribute(ATTRIBUTE_VARIABLE) String var, @Attribute(ATTRIBUTE_STEP) int step)
        throws UnsupportedScriptException {
    var = StringUtils.trimToEmpty(var);

    if (StringUtils.isBlank(var)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "Variable name is empty.");
        throw ex;
    }/*w  ww .  j av a 2  s  .  c om*/

    String thisVar = var;
    if (StringUtils.contains(var, " ")) {
        thisVar = StringUtils.substringAfterLast(var, " ");
    }

    int defaultValue = 0;
    if (this.getEnvironment().containsVariable(thisVar)) {
        Object obj = this.getEnvironment().getVariable(thisVar);
        if (obj instanceof Integer) {
            defaultValue = ((Integer) obj).intValue();
        } else if (obj instanceof String) {
            if (StringUtils.isNumeric((String) obj)) {
                defaultValue = Integer.parseInt((String) obj);
            }

        } else {
            UnsupportedScriptException ex = new UnsupportedScriptException(this,
                    "Only support integer variable.");
            throw ex;
        }
    }
    defaultValue += step;

    saveVariable(var, defaultValue, defaultValue);
}

From source file:mase.spec.AbstractHybridExchanger.java

@Override
public void setup(EvolutionState state, Parameter base) {
    nAgents = state.parameters.getInt(new Parameter("pop.subpops"), null); // TODO: bad dependency
    allocations = new int[nAgents];
    behaviourIndex = state.parameters.getInt(base.push(P_BEHAVIOUR_INDEX), null);

    String initial = state.parameters.getString(base.push(P_INITIAL_ALLOCATION), null);

    if (initial.equalsIgnoreCase(V_HOMOGENEOUS)) {
        setInitialAllocation(1);/*w  w  w  .j  a  v  a 2  s. c  om*/
    } else if (initial.equalsIgnoreCase(V_HETEROGENEOUS)) {
        setInitialAllocation(nAgents);
    } else if (StringUtils.isNumeric(initial)) {
        int pops = Integer.parseInt(initial);
        setInitialAllocation(pops);
    } else {
        String[] split = initial.split("[\\s\\,\\-]+");
        if (split.length != nAgents) {
            state.output.fatal("Initial allocation (" + split.length + ") does not match the number of agents ("
                    + nAgents + ").", base.push(P_INITIAL_ALLOCATION));
        }
        for (int i = 0; i < allocations.length; i++) {
            allocations[i] = Integer.parseInt(split[i].trim());
        }
    }
}

From source file:com.webarch.common.lang.StringSeriesTools.java

/**
 * ??0//from  w  ww . ja  v a  2  s. c om
 *
 * @param numString String
 * @return long
 */
public static long string2Long(final String numString) {
    if (StringUtils.isNumeric(numString)) {
        return Long.valueOf(numString);
    }
    return 0;
}

From source file:mesclasses.controller.PageController.java

public static final void markAsMin(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isBlank(newValue)) {
            return;
        }/*from  w  w  w . j a  va2s. com*/
        if (!StringUtils.isNumeric(newValue.substring(newValue.length() - 1))) {
            field.setText(newValue.substring(0, newValue.length() - 1));
            return;
        }
        if (newValue.length() > 2) {
            field.setText(oldValue);
            return;
        }
        if (Integer.parseInt(newValue) > 59) {
            field.setText("59");
        }

    });
}

From source file:com.inkubator.hrm.web.loan.LoanNewTypeFormController.java

@PostConstruct
@Override/* w w  w .  j  a v a2s. c  om*/
public void initialization() {
    super.initialization();
    try {
        String param = FacesUtil.getRequestParameter("param");
        loanNewTypeModel = new LoanNewTypeModel();
        isUpdate = Boolean.FALSE;

        List<Currency> currencyList = currencyService.getAllData();
        for (Currency currency : currencyList) {
            mapCurrency.put(currency.getName(), currency.getId());
        }

        if (StringUtils.isNumeric(param)) {
            LoanNewType loanNewType = loanNewTypeService.getEntityWithRelationByPk(Long.parseLong(param));
            if (loanNewType != null) {
                loanNewTypeModel.setId(loanNewType.getId());
                loanNewTypeModel.setLoanTypeCode(loanNewType.getLoanTypeCode());
                loanNewTypeModel.setLoanTypeName(loanNewType.getLoanTypeName());
                loanNewTypeModel.setCurrencyCode(loanNewType.getCurrency().getId());
                loanNewTypeModel.setCurrencyName(loanNewType.getCurrency().getName());
                loanNewTypeModel.setInterestMethod(loanNewType.getInterestMethod());
                loanNewTypeModel.setInterest(loanNewType.getInterest().doubleValue());
                loanNewTypeModel.setRoundingStatus(loanNewType.getRoundingStatus());
                loanNewTypeModel.setDescription(loanNewType.getDescription());
                isUpdate = Boolean.TRUE;
                rounding = loanNewTypeModel.getRoundingStatus().intValue() == 1 ? Boolean.TRUE : Boolean.FALSE;
                currencyId = loanNewType.getCurrency().getId();
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error", e);
    }
}

From source file:com.lcw.one.common.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*//from   w w w  .  java  2s .com
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

}

From source file:com.changhong.sso.api.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*//from  w w w  .  java2  s.c o m
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute(VALIDATE_CODE, s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

From source file:com.synopsys.integration.blackduck.service.model.ProjectNameVersionGuesser.java

private int findIndexBeforeNumeric(final String fullString, final String separator, final int fromIndex) {
    final int index = fullString.indexOf(separator, fromIndex);
    if (index == -1) {
        return -1;
    } else if (index + 1 < fullString.length()
            && StringUtils.isNumeric(fullString.substring(index + 1, index + 2))) {
        return index;
    } else {//from   ww w  . j ava2 s .  c  o m
        return findIndexBeforeNumeric(fullString, separator, index + 1);
    }
}