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:gobblin.util.recordcount.IngestionRecordCountProvider.java

/**
 * The record count should be the last component before the filename extension.
 *///from w  ww .j a v  a  2 s . c o m
@Override
public long getRecordCount(Path filepath) {
    String[] components = filepath.getName().split(Pattern.quote(SEPARATOR));
    Preconditions.checkArgument(
            components.length >= 2 && StringUtils.isNumeric(components[components.length - 2]),
            String.format("Filename %s does not follow the pattern: FILENAME.RECORDCOUNT.EXTENSION", filepath));
    return Long.parseLong(components[components.length - 2]);
}

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

/**
 * @see br.com.nordestefomento.jrimum.vallia.digitoverificador.AbstractDigitoVerificador#calcule(java.lang.String)
 * @since 0.3/* w  w  w. j ava 2s  .  co  m*/
 */
@Override
public int calcule(String numeroStr) throws IllegalArgumentException {

    int dv = 0;
    int resto = 0;

    if (StringUtils.isNotBlank(numeroStr) && StringUtils.isNumeric(numeroStr) && (numeroStr.length() == 11)) {

        resto = modulo.calcule(numeroStr);

        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 campo [ " + numeroStr + " ] da linha digitvel deve "
                + "conter apenas nmeros, com exatamento 11 dgitos, para que "
                + "o clculo do dgito verificador possa ser executado !");

    return dv;
}

From source file:controllers.ApplicationBaseController.java

protected static String verifyRadius(String radius) {
    try {//from  w  w  w  . j a v  a  2  s .  com
        if (StringUtils.isEmpty(radius) || !StringUtils.isNumeric(radius)) {
            radius = RADIUS_DEFAULT;
        } else {
            if (LocoUtils.stringToInteger(radius) > LocoUtils.stringToInteger(RADIUS_MAX))
                radius = RADIUS_DEFAULT;
        }
    } catch (Exception ex) {
        radius = RADIUS_DEFAULT;
    }

    return radius;
}

From source file:com.aimluck.eip.project.util.ProjectFormUtils.java

public static boolean isEditable(String taskId, Integer userId) {
    if (StringUtils.isEmpty(taskId) || !StringUtils.isNumeric(taskId) || null == userId) {
        return false;
    }/*from w  w  w  .  ja  v a2s. c o  m*/
    return isEditable(Integer.valueOf(taskId), userId);
}

From source file:com.flexive.rest.TreeService.java

protected Object getTree(String idOrPath) throws FxApplicationException {
    if (StringUtils.isNumeric(idOrPath)) {
        return doGetTree(Long.parseLong(idOrPath));
    } else {/*  ww  w.  j  ava  2 s  .co m*/
        final long nodeId = EJBLookup.getTreeEngine().getIdByPath(mode, idOrPath);
        return doGetTree(nodeId);
    }
}

From source file:com.qmetry.qaf.automation.ui.selenium.customcommands.SetAttributeCommand.java

@Override
public String doCommand(SeleniumCommandProcessor commandProcessor, String... args) {
    int atSign = args[0].lastIndexOf("@");
    String elementLocator = args[0].substring(0, atSign).trim();
    String attributeName = args[0].substring(atSign + 1).trim();
    String value = args[1];//from ww  w.ja v a  2 s .c  o m
    if (!(StringUtils.isNumeric(value) || "true".equals(value) || "false".equals(value) || value.startsWith("'")
            || value.startsWith("\""))) {
        value = "\"" + value + "\"";
    }
    String snippet = "";
    try {
        snippet = String.format("selenium.page().findElement(\"%s\").setAttribute('%s',%s);", elementLocator,
                attributeName, value);
    } catch (Exception e) {
        if (attributeName.equalsIgnoreCase("style")) {
            snippet = String.format("selenium.page().findElement(\"%s\").style.setAttribute('cssText',%s);",
                    elementLocator, value);
        } else if (attributeName.equalsIgnoreCase("class")) {
            snippet = String.format("selenium.page().findElement(\"%s\").className=%s);", elementLocator,
                    value);
        } else {
            snippet = String.format("selenium.page().findElement(\"%s\").%s=%s;", elementLocator, attributeName,
                    value);
        }
    }

    return commandProcessor.doDefaultDoCommand("getEval", new String[] { snippet, "" });
}

From source file:morphy.command.AddListCommand.java

public void process(String arguments, UserSession userSession) {

    String[] args = arguments.split(" ");
    if (args.length != 2) {
        userSession.send(getContext().getUsage());
        return;/*from   ww w.  j av a  2  s. c  o  m*/
    }
    String listName = args[0].toLowerCase();
    String value = args[1];

    UserService us = UserService.getInstance();
    if (us.isAdmin(userSession.getUser().getUserName())) {
        ServerListManagerService serv = ServerListManagerService.getInstance();
        ServerList s = serv.getList(listName);
        if (s != null) {
            if (userSession.getUser().getUserLevel().ordinal() >= s.getPermissions().ordinal()) {
                if (s.getType().equals(ListType.Integer) && !StringUtils.isNumeric(value)) {
                    userSession.send("Bad value provided for that list (Integer required)");
                    return;
                } else if (s.getType().equals(ListType.Username) && !us.isValidUsername(value)) {
                    userSession.send("Bad value provided for that list (Username required)");
                    return;
                } else if (s.getType().equals(ListType.IPAddress)
                        && !value.matches("\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}")) {
                    userSession.send("Bad value provided for that list (IPAddress required)");
                    return;
                } else if (s.getType().equals(ListType.String) && value.contains(" ")) {
                    userSession.send("Bad value provided for that list (String required)");
                    return;
                }

                if (listName.equals("admin") && !us.isRegistered(value)) {
                    userSession.send("Guests cannot be added to that list.");
                    return;
                }

                if (!serv.isOnList(s, value)) {
                    serv.getElements().get(s).add(value);
                    userSession.send("[" + value + "] added to the " + listName + " list.");
                    UserSession user = us.getUserSession(value);
                    if (listName.equals("admin")) {
                        user.getUser().setUserLevel(UserLevel.Admin);
                    }
                    if (listName.equals("admin") || listName.equals("sr") || listName.equals("tm")
                            || listName.equals("td") || listName.equals("computer")) {
                        if (user != null) {
                            user.send("You have been added to the " + listName + " list by "
                                    + userSession.getUser().getUserName() + ".");
                        }
                    }
                    return;
                } else {
                    userSession.send("[" + value + "] is already on the " + listName + " list.");
                    return;
                }
            } else {
                userSession.send("\"" + listName
                        + "\" is not an appropriate list name or you have insufficient rights.");
                return;
            }
        }
    }

    listName = listName.toLowerCase();
    PersonalList list = null;
    try {
        list = PersonalList.valueOf(listName);
    } catch (Exception e) {
        userSession.send("\"" + listName + "\" does not match any list name.");
        return;
    }

    List<String> myList = userSession.getUser().getLists().get(list);
    if (myList == null) {
        myList = new ArrayList<String>(User.MAX_LIST_SIZE);
        userSession.getUser().getLists().put(list, myList);
    }
    if (!myList.contains(value)) {
        if (list == PersonalList.channel) {
            ChannelService cS = ChannelService.getInstance();
            try {
                int intVal = Integer.parseInt(value);
                if (intVal < Channel.MINIMUM || intVal > Channel.MAXIMUM)
                    throw new NumberFormatException();
                Channel c = cS.getChannel(intVal);
                if (c != null)
                    c.addListener(userSession);
                else
                    userSession.send("That channel should, but does not, exist.");
            } catch (NumberFormatException e) {
                userSession.send("The channel to add must be a number between " + Channel.MINIMUM + " and "
                        + Channel.MAXIMUM + ".");
                return;
            }
        }

        if (list != PersonalList.channel) {
            String[] matches = us.completeHandle(value);
            //System.err.println(value + " " + java.util.Arrays.toString(matches));
            if (matches.length > 0) {
                if (matches.length == 1) {
                    value = matches[0];
                }
            }
        }

        myList.add(value);
        userSession.send("[" + value + "] added to your " + listName + " list.");

        int dbid = userSession.getUser().getDBID();
        boolean isGuest = dbid == 0;
        if (!isGuest) {
            DatabaseConnectionService dbcs = DatabaseConnectionService.getInstance();
            dbcs.getDBConnection().executeQueryWithRS(
                    "INSERT IGNORE INTO personallist VALUES(NULL," + dbid + ",'" + listName + "');");
            Integer listid = userSession.getUser().getPersonalListDBIDs().get(list);
            if (listid == null) {
                java.sql.ResultSet rs = dbcs.getDBConnection()
                        .executeQueryWithRS("SELECT `id`,`name` FROM personallist WHERE user_id = '" + dbid
                                + "' && name = '" + listName + "';");
                try {
                    if (rs.next()) {
                        userSession.getUser().getPersonalListDBIDs().put(PersonalList.valueOf(rs.getString(2)),
                                rs.getInt(1));
                        listid = rs.getInt(1);
                    }
                } catch (java.sql.SQLException e) {
                    Morphy.getInstance().onError(e);
                }
            }
            String query = "INSERT INTO personallist_entry VALUES(NULL," + listid + ",'" + value + "');";
            dbcs.getDBConnection().executeQuery(query);
        }
    } else {
        userSession.send("[" + value + "] is already on your " + listName + " list.");
    }
}

From source file:hydrograph.ui.engine.util.FTPUtil.java

/**
 * Converts the String to {@link BigInteger} for widgets
 * /* w ww .  ja  v  a 2  s.com*/
 * @param propertyName
 * @return {@link BigInteger}
 */
public BigInteger getPortValue(String propertyName, String componentId, Map<String, Object> properties) {
    LOGGER.debug("Getting boolean Value for {}={}",
            new Object[] { propertyName, properties.get(propertyName) });
    BigInteger bigInteger = null;
    String propertyValue = (String) properties.get(propertyName);
    if (StringUtils.isNotBlank(propertyValue) && StringUtils.isNumeric(propertyValue)) {
        bigInteger = new BigInteger(String.valueOf(propertyValue));
    } else if (ParameterUtil.isParameter(propertyValue)) {
        ComponentXpath.INSTANCE.getXpathMap()
                .put((ComponentXpathConstants.COMPONENT_XPATH_BOOLEAN.value().replace("$id", componentId))
                        .replace(Constants.PARAM_PROPERTY_NAME, propertyName),
                        new ComponentsAttributeAndValue(null, properties.get(propertyName).toString()));
        return null;
    }
    return bigInteger;
}

From source file:fr.paris.lutece.plugins.crm.business.demand.DemandTypeCategoryRemovalListener.java

/**
* Check if the object can be safely removed
* @param strId The object id/*from www  . ja v a  2  s .  c  o m*/
* @return true if the object can be removed otherwise false
*/
public boolean canBeRemoved(String strId) {
    boolean bCanBeRemoved = true;

    if (StringUtils.isNotBlank(strId) && StringUtils.isNumeric(strId)) {
        int nIdCategory = Integer.parseInt(strId);
        DemandTypeFilter rtFilter = new DemandTypeFilter();
        rtFilter.setIdCategory(nIdCategory);

        List<DemandType> listDemandTypes = DemandTypeService.getService().findByFilter(rtFilter);

        if ((listDemandTypes != null) && (listDemandTypes.size() > 0)) {
            bCanBeRemoved = false;
        }
    }

    return bCanBeRemoved;
}

From source file:fr.paris.lutece.plugins.workflow.modules.rest.service.formatters.ActionFormatterJson.java

/**
 * {@inheritDoc }/*from   ww w. jav a  2 s  .  co m*/
 */
@Override
public String formatError(String strCode, String strMessage) {
    int nIdCode = WorkflowUtils.CONSTANT_ID_NULL;

    if (StringUtils.isNotBlank(strCode) && StringUtils.isNumeric(strCode)) {
        nIdCode = Integer.parseInt(strCode);
    }

    return JSONUtil.formatError(strMessage, nIdCode);
}