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:gov.nih.nci.ncicb.tcga.dcc.common.generation.BioTabDataProcessorUtil.java

/**
 * returns date in YYYY-MM-DD format.//from w ww.  j av a 2s. c  o  m
 * For partial date:
 * - returns "NA" if year is not available
 * - returns "NA" if month is not available
 * - returns YYYY-00-00 if month and day are not available
 * - returns YYYY-MM-00 if day is not available
 *
 * @param bioTabData
 * @param dateObject
 * @return
 */
private String getDate(final Map<String, String> bioTabData, final String dateObject) {
    final StringBuffer date = new StringBuffer();
    String year = bioTabData.get(YEAR_OF + dateObject);
    String month = bioTabData.get(MONTH_OF + dateObject);
    String day = bioTabData.get(DAY_OF + dateObject);

    if (!StringUtils.isNumeric(year) || (StringUtils.isNumeric(day)) && !(StringUtils.isNumeric(month))) {
        date.append("NA");
    } else {
        date.append(year).append("-").append((StringUtils.isNumeric(month)) ? month : "00").append("-")
                .append((StringUtils.isNumeric(day)) ? day : "00");
    }
    return date.toString();
}

From source file:cn.vlabs.duckling.vwb.ui.action.emailnotify.EmailSubscribeSettingAction.java

private boolean isInputValid(SubscribeForm form, HttpServletRequest request) {
    boolean success = true;
    ActionMessages errors = new ActionMessages();
    if (StringUtils.isBlank(form.getPageName()) || !isValidPageName(form.getPageName())) {
        errors.add("pageName", new ActionMessage("emailnotifier.pagenameerror"));
        success = false;/*from   www . j a v a 2  s.c om*/
    }
    if (StringUtils.isBlank(form.getEmails())) {
        errors.add("emails", new ActionMessage("emailnotifier.emailerror"));
        success = false;
    }
    if (StringUtils.isBlank(form.getHour()) || !StringUtils.isNumeric(form.getHour())) {
        errors.add("rec_time", new ActionMessage("emailnotifier.timeerror"));
        success = false;
    } else {
        int iHour = Integer.parseInt(form.getHour());
        if (iHour < 0 || iHour > 23) {
            errors.add("rec_time", new ActionMessage("emailnotifier.timeerror"));
            success = false;
        }
    }

    if (!success) {
        saveErrors(request, errors);
    }
    return success;
}

From source file:fr.paris.lutece.plugins.suggest.service.SuggestSubmitExtendableResourceService.java

/**
 * {@inheritDoc}//from   w  ww .  j av  a2 s. com
 */
@Override
public String getResourceUrl(String strIdResource, String strResourceType) {
    if (StringUtils.isNotBlank(strIdResource) && StringUtils.isNumeric(strIdResource)) {
        int nIdSuggestSubmit = Integer.parseInt(strIdResource);
        SuggestSubmit suggestSubmit = SuggestSubmitService.getService().findByPrimaryKey(nIdSuggestSubmit,
                false, PluginService.getPlugin(SuggestPlugin.PLUGIN_NAME));

        if (suggestSubmit != null) {
            UrlItem urlItem = new UrlItem(AppPathService.getPortalUrl());
            urlItem.addParameter(MARK_PAGE, CONSTANT_SUGGEST);
            urlItem.addParameter(MARK_ID_SUGGEST, suggestSubmit.getSuggest().getIdSuggest());
            urlItem.addParameter(MARK_ID_SUGGEST_SUBMIT, strIdResource);
            urlItem.addParameter(MARK_ACTION, SuggestApp.ACTION_VIEW_SUGGEST_SUBMIT);

            return urlItem.getUrl();
        }
    }

    return null;
}

From source file:com.intellectualcrafters.plot.commands.TP.java

private Plot isAlias(final World world, String a) {
    int index = 0;
    if (a.contains(";")) {
        final String[] split = a.split(";");
        if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
            index = Integer.parseInt(split[1]);
        }/*  ww w  .  ja v a 2  s .c  o  m*/
        a = split[0];
    }
    @SuppressWarnings("deprecation")
    final Player player = Bukkit.getPlayer(a);
    if (player != null) {
        final java.util.Set<Plot> plotMainPlots = PlotMain.getPlots(world, player);
        final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
        if (plots.length > index) {
            return plots[index];
        }
        return null;
    }
    for (final Plot p : PlotMain.getPlots(world).values()) {
        if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
            return p;
        }
    }
    return null;
}

From source file:fr.paris.lutece.plugins.workflow.modules.mappings.web.component.ActionMappingTypeComponent.java

/**
 * {@inheritDoc}/*from  ww w.  j  a  va 2s  . co  m*/
 */
@Override
public String getCreateCodeMappingHtml(HttpServletRequest request, Locale locale) {
    Map<String, Object> model = new HashMap<String, Object>();
    String strIdWorkflow = request.getParameter(PARAMETER_ID_WORKFLOW);
    Workflow workflow = null;

    if (StringUtils.isNotBlank(strIdWorkflow) && StringUtils.isNumeric(strIdWorkflow)) {
        int nIdWorkflow = Integer.parseInt(strIdWorkflow);
        workflow = _workflowService.findByPrimaryKey(nIdWorkflow);

        if (workflow != null) {
            model.put(MARK_LIST_ACTIONS,
                    _codeMappingService.getListActions(getMappingType().getKey(), nIdWorkflow));
            model.put(MARK_WORKFLOW, workflow);
        }
    }

    model.put(MARK_LIST_WORKFLOWS, _codeMappingService.getListWorkflow());

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_CREATE_MAPPING, locale, model);

    return template.getHtml();
}

From source file:com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor.java

private synchronized void initNodes(List<String> nodes) {
    List<Long> nids = new ArrayList<Long>();
    for (String node : nodes) {
        if (StringUtils.isNumeric(node)) {
            nids.add(Long.valueOf(node));
        }//from w  ww  .j  ava  2  s. co m
    }
    Collections.sort(nids);

    if (!aliveNodes.equals(nids)) {// ???
        if (logger.isDebugEnabled()) {
            logger.debug("old aliveNodes{} ,current aliveNodes{}", new Object[] { aliveNodes, nids });
        }

        aliveNodes = nids; // ?volatile??&??
        processChanged(nids);// ?
    }
}

From source file:eu.stork.peps.auth.commons.PersonalAttributeList.java

/**
 * {@inheritDoc}//from   ww w.  j ava  2  s .  c  om
 */
public PersonalAttribute put(final String key, final PersonalAttribute val) {
    if (StringUtils.isNotEmpty(key) && val != null) {
        // Validate if attribute name already exists!
        String attrAlias = key;
        if (this.containsKey(attrAlias)) {
            //TODO isAgeOver should not be hardcoded, a better way of handling multipe isAgeOver requests should be implemented.
            if (!val.isEmptyValue() && StringUtils.isNumeric(val.getValue().get(0))
                    && "isAgeOver".equals(val.getName())) {
                final String attrValue = val.getValue().get(0);
                attrAlias = key + attrValue;
                this.attrAliasNumber.put(key, Integer.valueOf(attrValue));
            } else {
                final PersonalAttribute attr = super.get(key);
                if (!attr.isEmptyValue() && StringUtils.isNumeric(attr.getValue().get(0))) {
                    attrAlias = key + attr.getValue().get(0);
                    super.put(key, (PersonalAttribute) attr);
                    this.attrAliasNumber.put(key, null);
                }
            }
        }
        return super.put(attrAlias, val);
    } else {
        return null;
    }
}

From source file:com.cinchapi.concourse.util.ConvertTest.java

@Test
public void testCannotConvertLinkFromStringValue() {
    String number = Random.getString();
    while (StringUtils.isNumeric(number)) {
        number = Random.getString();
    }//  w  ww  . jav a2  s  .c o  m
    String value = MessageFormat.format("{0}{1}{0}", "@", number.toString());
    Assert.assertFalse(Convert.stringToJava(value) instanceof Link);
}

From source file:fr.paris.lutece.plugins.calendar.service.CalendarService.java

/**
 * Get the agenda/*from  w  ww. j  a v  a 2s  . c o m*/
 * @param strAgendaKeyName the agenda key name
 * @return The AgendaResource object
 */
public AgendaResource getAgendaResource(String strAgendaKeyName) {
    AgendaResource agenda = null;
    if (StringUtils.isNotBlank(strAgendaKeyName) && StringUtils.isNumeric(strAgendaKeyName)) {
        int nAgendaId = Integer.parseInt(strAgendaKeyName);
        agenda = getAgendaResource(nAgendaId);
    }
    return agenda;
}

From source file:com.agiletec.apsadmin.category.CategoryAction.java

public List<TreeNodeWrapper> getAvailableNodesForMoveTreeAjax() {
    List<TreeNodeWrapper> result = new ArrayList<TreeNodeWrapper>();
    try {/*from   ww w.  j a v  a  2s.  c o  m*/
        System.out.println("ENTRATO getAvailableNodesForMoveTreeAjax");
        String startCategoryCode = this.getSelectedNode();
        if (StringUtils.isBlank(startCategoryCode)) {
            _logger.warn("required parameter 'selectedNode' missing");
            return result;
        }
        Category nodeToMove = this.getCategory(startCategoryCode);
        if (null == nodeToMove) {
            _logger.warn("category {} is null", startCategoryCode);
            return result;
        }

        List<String> allowedGroupCodes = new ArrayList<String>();
        allowedGroupCodes.add(nodeToMove.getGroup());

        //XXX FIX JS
        this.setCategoryCodeToken(super.getParameter("categoryCodeToken"));

        List<Category> searchResult = this.getCategoryManager().searchCategories(this.getCategoryCodeToken());
        if (null == searchResult || searchResult.isEmpty())
            return result;

        BeanComparator comparator = new BeanComparator("code");
        Collections.sort(result, comparator);

        int maxIndex = 30;
        String maxParam = super.getParameter("max");
        if (StringUtils.isNotBlank(maxParam) && StringUtils.isNumeric(maxParam))
            maxIndex = new Integer(maxParam).intValue();

        Iterator<Category> it = searchResult.iterator();
        while (result.size() < maxIndex && it.hasNext()) {
            ITreeNode candidate = it.next();
            if (!candidate.isChildOf(nodeToMove.getCode())
                    && !candidate.getCode().equals(nodeToMove.getParentCode())) {
                result.add(new TreeNodeWrapper(candidate, this.getCurrentLang().getCode()));
            }
        }
    } catch (Throwable t) {
        _logger.error("Error on searching categories ajax", t);
        throw new RuntimeException("Error on searching categories ajax", t);
    }
    return result;
}