Example usage for org.apache.commons.lang3.math NumberUtils toInt

List of usage examples for org.apache.commons.lang3.math NumberUtils toInt

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils toInt.

Prototype

public static int toInt(final String str, final int defaultValue) 

Source Link

Document

Convert a String to an int, returning a default value if the conversion fails.

If the string is null, the default value is returned.

 NumberUtils.toInt(null, 1) = 1 NumberUtils.toInt("", 1)   = 1 NumberUtils.toInt("1", 0)  = 1 

Usage

From source file:com.houghtonassociates.bamboo.plugins.view.ViewGerritChainResultsAction.java

@Override
public String doExecute() throws Exception {
    updateChangeVO();/*from  ww  w.  j  a  va2  s.c o m*/

    if (getImmutableChain() == null || getImmutableChain().isMarkedForDeletion()) {
        addActionError(getText("chain.error.noChain", Lists.newArrayList(getPlanKey())));
        return ERROR;
    } else if (getChainResult() == null) {
        if (getChainResultNumber() > 0) {
            PlanResultKey planResultKey = PlanKeys.getPlanResultKey(getImmutableChain().getPlanKey(),
                    getChainResultNumber());
            ChainResultsSummary chainResult = resultsSummaryManager.getResultsSummary(planResultKey,
                    ChainResultsSummary.class);
            if (chainResult == null) {
                addActionError(getText("chain.error.noChainResult",
                        Lists.newArrayList(getPlanKey() + "-" + getChainResultNumber())));
                return ERROR;
            } else {
                setChainResult(chainResult);
            }
        } else {
            addActionError(getText("chain.error.noChainResult",
                    Lists.newArrayList(getPlanKey() + "-" + getChainResultNumber())));
            return ERROR;
        }
    }

    // Load / save lines
    if (linesToDisplay <= 0) {
        linesToDisplay = NumberUtils.toInt(cookieCutter.getValueFromCookie(BAMBOO_MAX_DISPLAY_LINES),
                DEFAULT_DISPLAY_LINES);
    }

    if (linesToDisplay <= 0) {
        linesToDisplay = DEFAULT_DISPLAY_LINES;
    }

    cookieCutter.saveValueInCookie(BAMBOO_MAX_DISPLAY_LINES, String.valueOf(linesToDisplay));

    commentsByEntity = commentService.getAllCommentsForPlanResult(getChainResult());

    return SUCCESS;
}

From source file:com.omertron.tvrageapi.model.ShowInfo.java

public void setRuntime(String runtime) {
    this.runtime = NumberUtils.toInt(runtime, 0);
}

From source file:com.axibase.tsd.client.ClientConfigurationFactory.java

private static int loadInt(String name, Properties clientProperties, int defaultValue) {
    return NumberUtils.toInt(load(name, clientProperties, ""), defaultValue);
}

From source file:com.omertron.tvrageapi.model.ShowInfo.java

public void setShowID(String showID) {
    this.showID = NumberUtils.toInt(showID, 0);
}

From source file:com.eastcom.hrmis.modules.emp.web.controller.api.EmployeeController.java

/**
 * /*from   ww w . ja va  2  s. c  o  m*/
 * @param session
 * @param request
 * @param params
 * @return
 */
@RequiresPermissions(value = { "emp:baseinfomgr:add", "emp:baseinfomgr:edit" }, logical = Logical.OR)
@OperationLog(content = "?", type = OperationType.CREATE)
@ResponseBody
@RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
public AjaxJson addOrUpdate(HttpSession session, HttpServletRequest request,
        @RequestParam Map<String, Object> params) {
    logger.info("--?--");
    AjaxJson json = new AjaxJson();
    try {
        String addOrUpdate = (String) params.get("addOrUpdate");
        if (StringUtils.isNotEmpty(addOrUpdate) && "add".equals(addOrUpdate)) {
            //??code
            Map<String, Object> reqParam = Maps.newHashMap();
            reqParam.put("code", (String) params.get("code"));
            List<Employee> temps = employeeService.find(reqParam);
            if (CollectionUtils.isNotEmpty(temps)) {
                json.setSuccess(false);
                json.setMessage("?,??");
                return json;
            }
            //?????
            reqParam = Maps.newHashMap();
            reqParam.put("cardNo", (String) params.get("cardNo"));
            temps = employeeService.find(reqParam);
            if (CollectionUtils.isNotEmpty(temps)) {
                json.setSuccess(false);
                json.setMessage("?,????");
                return json;
            }
        }

        String id = StringUtils.defaultIfBlank((String) params.get("id"), "0");
        Employee employee = employeeService.get(id);
        if (employee == null) {
            employee = new Employee();
            employee.setCreateDate(new Date());
        }
        employee.setCode((String) params.get("code"));
        employee.setName((String) params.get("name"));
        employee.setSex(NumberUtils.toInt((String) params.get("sex"), 1));
        employee.setAge(NumberUtils.toInt((String) params.get("age"), 0));
        employee.setEnrtyDate(DateUtils.parseDate((String) params.get("enrtyDate")));
        employee.setEnrtyDateType(NumberUtils.toInt((String) params.get("enrtyDateType"), 0));
        employee.setRegularDate(DateUtils.parseDate((String) params.get("regularDate")));
        employee.setRegularDateTwo(DateUtils.parseDate((String) params.get("regularDateTwo")));
        employee.setRetireDate(DateUtils.parseDate((String) params.get("retireDate")));
        employee.setNation((String) params.get("nation"));
        employee.setMarryType(NumberUtils.toInt((String) params.get("marryType"), 0));
        employee.setHeight((String) params.get("height"));
        employee.setCardNo((String) params.get("cardNo"));
        employee.setCardNoValidDate(DateUtils.parseDate((String) params.get("cardNoValidDate")));
        employee.setIsCardNoLongTerm(NumberUtils.toInt((String) params.get("isCardNoLongTerm"), 0));
        employee.setBirthDate(DateUtils.parseDate((String) params.get("birthDate")));
        employee.setEducation(NumberUtils.toInt((String) params.get("education"), 1));
        employee.setManageLevel(NumberUtils.toInt((String) params.get("manageLevel"), 1));
        employee.setJobTitle((String) params.get("jobTitle"));
        employee.setJobCapacity((String) params.get("jobCapacity"));
        employee.setPolity(NumberUtils.toInt((String) params.get("polity"), 1));
        employee.setDriveLicenseType(NumberUtils.toInt((String) params.get("driveLicenseType"), 0));
        employee.setDriveLicenseGetDate(DateUtils.parseDate((String) params.get("driveLicenseGetDate")));
        employee.setDriveLicenseValidDate(DateUtils.parseDate((String) params.get("driveLicenseValidDate")));
        employee.setMajor((String) params.get("major"));
        employee.setNativePlaceType(NumberUtils.toInt((String) params.get("nativePlaceType"), 1));
        employee.setNativePlaceAddr((String) params.get("nativePlaceAddr"));
        employee.setNativePlace((String) params.get("nativePlace"));
        employee.setContactAddr((String) params.get("contactAddr"));
        employee.setTelephone((String) params.get("telephone"));
        employee.setEmergentName((String) params.get("emergentName"));
        employee.setEmergentTelephone((String) params.get("emergentTelephone"));
        employee.setMealRoomType(NumberUtils.toInt((String) params.get("mealRoomType"), 1));
        employee.setPerformanceWageType(NumberUtils.toInt((String) params.get("performanceWageType"), 0));
        employee.setLaborType(NumberUtils.toInt((String) params.get("laborType"), 1));
        employee.setContractStartDate(DateUtils.parseDate((String) params.get("contractStartDate")));
        employee.setContractEndDate(DateUtils.parseDate((String) params.get("contractEndDate")));
        employee.setContractSignDateType(NumberUtils.toInt((String) params.get("contractSignDateType"), 1));
        employee.setContractSignDate(DateUtils.parseDate((String) params.get("contractSignDate")));
        employee.setContractTermCond(NumberUtils.toInt((String) params.get("contractTermCond"), 0));
        employee.setHasRiskAgreement(NumberUtils.toInt((String) params.get("hasRiskAgreement"), 0));
        employee.setHasPercentAgreement(NumberUtils.toInt((String) params.get("hasPercentAgreement"), 0));
        employee.setBankType(NumberUtils.toInt((String) params.get("bankType"), 0));
        employee.setBankCard((String) params.get("bankCard"));
        employee.setCharacterRemark((String) params.get("characterRemark"));
        employee.setHasLaborDispute(NumberUtils.toInt((String) params.get("hasLaborDispute"), 0));
        employee.setLaborDisputeResult((String) params.get("laborDisputeResult"));
        employee.setEnrtyIntorducerCompany((String) params.get("enrtyIntorducerCompany"));
        employee.setEnrtyIntorducer((String) params.get("enrtyIntorducer"));
        employee.setHasDiseaseHistory(NumberUtils.toInt((String) params.get("hasDiseaseHistory"), 0));
        employee.setDiseaseHistory((String) params.get("diseaseHistory"));
        employee.setHasFriendInCompany(NumberUtils.toInt((String) params.get("hasFriendInCompany"), 0));
        employee.setFriendDept((String) params.get("friendDept"));
        employee.setFriendName((String) params.get("friendName"));
        employee.setFriendJobTitle((String) params.get("friendJobTitle"));
        employee.setContractType(NumberUtils.toInt((String) params.get("contractType"), 0));
        employee.setHasSignForm(NumberUtils.toInt((String) params.get("hasSignForm"), 0));
        employee.setHasInsure(NumberUtils.toInt((String) params.get("hasInsure"), 0));
        employee.setInsureNo((String) params.get("insureNo"));
        employee.setInsureDate(DateUtils.parseDate((String) params.get("insureDate")));
        employee.setInsurePayBase(NumberUtils.toDouble((String) params.get("insurePayBase"), 0));
        employee.setHasPersionInsure(NumberUtils.toInt((String) params.get("hasPersionInsure"), 0));
        employee.setHasInjuryInsure(NumberUtils.toInt((String) params.get("hasInjuryInsure"), 0));
        employee.setHasBirthInsure(NumberUtils.toInt((String) params.get("hasBirthInsure"), 0));
        employee.setHasMedicalInsure(NumberUtils.toInt((String) params.get("hasMedicalInsure"), 0));
        employee.setHasSeriousInsure(NumberUtils.toInt((String) params.get("hasSeriousInsure"), 0));
        employee.setHasGsbInsure(NumberUtils.toInt((String) params.get("hasGsbInsure"), 0));
        employee.setHasNonPurchaseCommit(NumberUtils.toInt((String) params.get("hasNonPurchaseCommit"), 0));
        employee.setHasPublicFund(NumberUtils.toInt((String) params.get("hasPublicFund"), 0));
        employee.setPublicFundPayBase(NumberUtils.toDouble((String) params.get("publicFundPayBase"), 0));
        employee.setPublicFundDate(DateUtils.parseDate((String) params.get("publicFundDate")));
        employee.setHasQuitCompany(NumberUtils.toInt((String) params.get("hasQuitCompany"), 0));
        employee.setQuitCompanyType(NumberUtils.toInt((String) params.get("quitCompanyType"), 0));
        employee.setQuitCompanyDate(DateUtils.parseDate((String) params.get("quitCompanyDate")));
        employee.setQuitCompanyResult((String) params.get("quitCompanyResult"));

        employee.setPostChangeRemark((String) params.get("postChangeRemark"));
        employee.setDeptChangeRemark((String) params.get("deptChangeRemark"));
        employee.setOperaChangeRemark((String) params.get("operaChangeRemark"));
        employee.setWageChangeRemark((String) params.get("wageChangeRemark"));

        employee.setEmployeeDept(
                employeeDeptService.get(StringUtils.defaultIfBlank((String) params.get("employeeDept"), "0")));
        employee.setEmployeePost(
                employeePostService.get(StringUtils.defaultIfBlank((String) params.get("employeePost"), "0")));
        employee.setWagePlan(
                wagePlanService.get(StringUtils.defaultIfBlank((String) params.get("wagePlan"), "0")));

        employee.setOverTimeRate(NumberUtils.toInt((String) params.get("overTimeRate"), 1));

        employee.setModifyer(SecurityCache.getLoginUser().getName());
        employee.setModifyDate(new Date());
        employee.setRecordStatus(1);

        //,??,???
        employee.setAuditStatus(NumberUtils.toInt((String) params.get("auditStatus"), 0));

        //?--???
        employeeCheckWorkStatMonthService.deleteByEmployeeId(employee.getId());

        // ?????
        Map<String, Object> orderParam = Maps.newHashMap();
        orderParam.put("employeeId", employee.getId());
        orderParam.put("type", 4);
        orderParam.put("status", 0);
        List<EmployeeOrder> orders = employeeOrderService.find(orderParam);
        if (CollectionUtils.isNotEmpty(orders)) {
            for (EmployeeOrder employeeOrder : orders) {
                employeeOrder.setStatus(1);
                employeeOrderService.saveOrUpdate(employeeOrder);
            }
        }

        //?  5???
        orderParam = Maps.newHashMap();
        orderParam.put("employeeId", employee.getId());
        orderParam.put("type", 5);
        orderParam.put("status", 0);
        orders = employeeOrderService.find(orderParam);
        //?????
        if (CollectionUtils.isEmpty(orders) && employee.getAuditStatus() == 1) {
            EmployeeOrder order = new EmployeeOrder();
            order.setEmployee(employee);
            order.setContent(employee.getName() + "???");
            order.setStatus(0);
            order.setType(5);
            employeeOrderService.save(order);
            logger.info(employee.getName() + " ?:" + order.getTypeDict() + "??");
        }
        //?????
        if (CollectionUtils.isNotEmpty(orders)
                && (employee.getAuditStatus() == 2 || employee.getAuditStatus() == 3)) {
            for (EmployeeOrder employeeOrder : orders) {
                employeeOrder.setStatus(1);
                employeeOrderService.saveOrUpdate(employeeOrder);
            }
        }

        employeeService.saveOrUpdate(employee);
        json.setSuccess(true);
        json.setMessage("??");
    } catch (Exception e) {
        e.printStackTrace();
        json.setSuccess(false);
        json.setMessage("?");
    }
    return json;
}

From source file:com.formkiq.core.service.entry.WorkflowEntryFlowEventProcessor.java

/**
 * Generate Signature Form.//from  www  . jav a2 s  .  co  m
 *
 * @param flow {@link WebFlow}
 * @param request {@link HttpServletRequest}
 * @param fieldids String[]
 * @return {@link HTMLSnippet}
 */
public HTMLSnippet eventIdsignatureform(final WebFlow flow, final HttpServletRequest request,
        final String[] fieldids) {

    int fieldid = NumberUtils.toInt(Arrays.first(fieldids), -1);
    FormJSON form = flow.getCurrentState().getData();

    form.getSections().get(0).getFields().forEach(f -> {
        f.setHide(true);
    });

    findField(form, fieldid).get().setHide(false);

    return this.printRenderer.generateFormHTML(request, form, flow.getCurrentState().getFielderrors());
}

From source file:com.moviejukebox.plugin.MovieMeterPlugin.java

/**
 * Get the ID for the movie/*from   ww w .  ja  va 2s .co m*/
 *
 * @param title Movie title to get the ID for
 * @param year Movie year to get the ID for
 * @return The ID, or empty if no idea found
 */
public String getMovieId(final String title, final String year) {
    String id = UNKNOWN;

    LOG.debug("Looking for MovieMeter ID for {} ({})", title, year);
    List<SearchResult> results;
    try {
        results = api.search(title);
    } catch (MovieMeterException ex) {
        LOG.warn("Failed to get Movie Meter search results for {} ({}): {}", title, year, ex.getMessage(), ex);
        return id;
    }

    if (results.isEmpty()) {
        return id;
    }

    int fYear = NumberUtils.toInt(year, 0);
    double maxMatch = 0.0;

    for (SearchResult sr : results) {
        // if we have a year, check that first
        if (fYear > 0 && sr.getYear() != fYear) {
            continue;
        }

        // Check for best text similarity
        double result = StringUtils.getJaroWinklerDistance(title, sr.getTitle());
        if (result > maxMatch) {
            LOG.trace("Better match found for {} ({}) = {} ({}) [{}]", title, year, sr.getTitle(), sr.getYear(),
                    maxMatch);
            maxMatch = result;
            // Update the best result
            id = Integer.toString(sr.getId());
        }
    }

    if (isValidString(id)) {
        LOG.debug("MovieMeter ID '{}' found for {} ({}), Match confidence: {}", id, title, year, maxMatch);
    }

    return id;
}

From source file:com.ctrip.infosec.rule.util.Emitter.java

/**
 * ?Counter//from w w  w.  jav  a 2 s.c  o  m
 */
public static void emit(RiskFact fact, PolicyExecuteResult counterPolicyExecuteResult) {
    if (counterPolicyExecuteResult.getRuleExecuteResults() == null
            || counterPolicyExecuteResult.getRuleExecuteResults().isEmpty()) {
        String resultCode = counterPolicyExecuteResult.getResultCode();
        String resultMessage = counterPolicyExecuteResult.getResultMessage();
        if (!"000".equals(resultCode)) {
            emit(fact, resultCode, resultMessage);
        }
    } else {
        boolean _isAsync = MapUtils.getBoolean(fact.ext, Constants.key_isAsync, false);
        for (CounterRuleExecuteResult ruleExecuteResult : counterPolicyExecuteResult.getRuleExecuteResults()) {
            if (StringUtils.isNotBlank(ruleExecuteResult.getRuleNo())
                    && StringUtils.isNumeric(ruleExecuteResult.getResultCode())) {

                String ruleNo = ruleExecuteResult.getRuleNo();
                int riskLevel = NumberUtils.toInt(ruleExecuteResult.getResultCode(), 0);
                String riskMessage = ruleExecuteResult.getResultMessage();
                String scenes = ruleExecuteResult.getScenes();
                if (riskLevel > 0) {
                    Map<String, Object> result = Maps.newHashMap();
                    result.put(Constants.riskLevel, riskLevel);
                    result.put(Constants.riskMessage, riskMessage);
                    result.put(Constants.async, _isAsync);

                    if (StringUtils.isBlank(scenes)) {
                        if (!_isAsync) {
                            result.put(Constants.ruleType, "N");
                            fact.results.put(ruleNo, result);
                        } else {
                            result.put(Constants.ruleType, "NA");
                            fact.results4Async.put(ruleNo, result);
                        }
                    } else {
                        List<String> riskScenes = Splitter.on(",").omitEmptyStrings().trimResults()
                                .splitToList(scenes);
                        result.put(Constants.riskScene, riskScenes);
                        if (!_isAsync) {
                            result.put(Constants.ruleType, "S");
                            fact.resultsGroupByScene.put(ruleNo, result);
                        } else {
                            result.put(Constants.ruleType, "SA");
                            fact.resultsGroupByScene4Async.put(ruleNo, result);
                        }
                    }

                    boolean withScene = Constants.eventPointsWithScene.contains(fact.eventPoint);
                    TraceLogger.traceLog("[trace] withScene = " + withScene + ", scenes = ["
                            + (scenes == null ? "" : scenes) + "]");
                    if (!withScene) {
                        if (StringUtils.isNotBlank(scenes)) {
                            TraceLogger.traceLog(">>>> [" + ruleNo
                                    + "] : [???] riskLevel = "
                                    + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes
                                    + "]");
                        } else {
                            TraceLogger.traceLog(">>>> [" + ruleNo + "] : riskLevel = " + riskLevel
                                    + ", riskMessage = " + riskMessage);
                        }
                    } else if (withScene) {
                        if (StringUtils.isBlank(scenes)) {
                            TraceLogger.traceLog(">>>> [" + ruleNo
                                    + "] [?]: [?] riskLevel = "
                                    + riskLevel + ", riskMessage = " + riskMessage);
                        } else {
                            TraceLogger.traceLog(">>>> [" + ruleNo + "] [?]: riskLevel = "
                                    + riskLevel + ", riskMessage = " + riskMessage + ", riskScene = [" + scenes
                                    + "]");
                        }
                    }
                }
            }
        }
    }
}

From source file:com.moviejukebox.plugin.AllocinePlugin.java

private String getAllocineMovieId(String title, String year) throws Exception {
    String cacheKey = CacheMemory.generateCacheKey(CACHE_SEARCH_MOVIE, title);
    Search search = (Search) CacheMemory.getFromCache(cacheKey);
    if (search == null) {
        search = allocineApi.searchMovies(title);
        // Add to the cache
        CacheMemory.addToCache(cacheKey, search);
    }/*from ww w  .j a v  a2s. co m*/

    if (!search.isValid()) {
        return Movie.UNKNOWN;
    }

    // If we have a valid year try to find the first movie that match
    if (search.getTotalResults() > 1 && isValidString(year)) {
        int yearMovie = NumberUtils.toInt(year, -1);
        for (com.moviejukebox.allocine.model.Movie movie : search.getMovies()) {
            if (movie != null) {
                int movieProductionYear = movie.getProductionYear();
                if (movieProductionYear <= 0) {
                    continue;
                }
                if (movieProductionYear == yearMovie) {
                    return String.valueOf(movie.getCode());
                }
            }
        }
    }
    // We don't find a movie or there only one result, return the first
    if (!search.getMovies().isEmpty()) {
        com.moviejukebox.allocine.model.Movie movie = search.getMovies().get(0);
        if (movie != null) {
            return String.valueOf(movie.getCode());
        }
    }

    return Movie.UNKNOWN;
}

From source file:mtsar.processors.answer.KOSAggregator.java

private int getKMax() {
    return NumberUtils.toInt(stage.getOptions().get("kMax"), 10);
}