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:controllers.ApplicationBaseController.java

protected static String verifyRecordLimit(String limit) {
    try {/*  www .j  a  v  a  2  s .c  om*/
        if (StringUtils.isEmpty(limit) || !StringUtils.isNumeric(limit)) {
            limit = RECORDLIMIT_DEFAULT;
        } else {
            if (LocoUtils.stringToInteger(limit) > LocoUtils.stringToInteger(RECORDLIMIT_MAX))
                limit = RECORDLIMIT_DEFAULT;
        }
    } catch (Exception ex) {
        limit = RECORDLIMIT_DEFAULT;
    }

    return limit;
}

From source file:com.metabroadcast.common.webapp.query.DateTimeInQueryParser.java

public DateTime parse(String value) throws MalformedDateTimeException {

    if (!StringUtils.isBlank(value) && StringUtils.isNumeric(value)) {
        return new DateTime(Long.valueOf(value) * 1000, DateTimeZones.UTC);
    }//www. ja v a 2s.co m

    Matcher matcher = EXPRESSION.matcher(value);
    if (matcher.matches()) {
        String operator = matcher.group(1);
        if (operator == null) {
            return clock.now();
        } else {
            Period period = periodFrom(matcher.group(2));
            if ("plus".equals(operator)) {
                return clock.now().plus(period);
            } else {
                return clock.now().minus(period);
            }
        }
    }

    throw new MalformedDateTimeException();
}

From source file:de.thischwa.pmcms.tool.XY.java

/**
 * Constructor to interpret to comma-separated values, e.g.: <code>1,2</code>
 * /* w w  w .j a va 2  s.c om*/
 * @param str
 */
public XY(final String str) {
    if (StringUtils.isEmpty(str))
        return;
    String tmp = StringUtils.strip(str);
    String values[] = StringUtils.split(tmp, ",");
    if (values.length != 2 && !(StringUtils.isNumeric(values[0]) && StringUtils.isNumeric(values[1])))
        throw new IllegalArgumentException("Can't interpret coordinate string!");
    setLocation(Integer.parseInt(values[0].trim()), Integer.parseInt(values[1].trim()));
}

From source file:morphy.command.LLoginsCommand.java

public void process(String arguments, UserSession userSession) {
    /* Sun Aug  7, 12:00 MDT 2011: GuestGYKQ(U)         logout */

    boolean empty = StringUtils.isEmpty(arguments);
    boolean numeric = StringUtils.isNumeric(arguments);

    int limit = 10; //200
    arguments = arguments.trim();/* w ww . jav a  2s  .  c  o  m*/
    if (empty) {
        limit = 10;
    } else if (numeric && !empty) {
        limit = Integer.parseInt(arguments);
    } else if (!numeric && !empty) {
        userSession.send(getContext().getUsage());
        return;
    }

    boolean isAdmin = UserService.getInstance().isAdmin(userSession.getUser().getUserName());
    StringBuilder b = new StringBuilder();

    final java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("EEE MMM dd, HH:mm z yyyy");

    int count = 0;
    String query = "SELECT COUNT(*) FROM `logins`";
    ResultSet rs = DatabaseConnectionService.getInstance().getDBConnection().executeQueryWithRS(query);
    try {
        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (SQLException e) {
        Morphy.getInstance().onError(e);
    }

    if (limit > count)
        limit = count;

    query = "SELECT `id` FROM `logins` ORDER BY `id` DESC LIMIT " + limit;
    rs = DatabaseConnectionService.getInstance().getDBConnection().executeQueryWithRS(query);
    int[] arr = new int[limit];
    try {
        int index = 0;
        while (rs.next()) {
            arr[index++] = rs.getInt(1);
        }
    } catch (SQLException e) {
        Morphy.getInstance().onError(e);
    }
    java.util.Arrays.sort(arr);

    Map<String, Boolean> registeredCache = new HashMap<String, Boolean>();

    query = "SELECT `id`,`username`,CONVERT_TZ(`timestamp`,'UTC','SYSTEM'),`type`"
            + (isAdmin ? ",`ipAddress`" : "") + " FROM logins WHERE "
            + MessagesCommand.formatIdListForQuery("id", arr) + " ORDER BY id ASC";
    rs = DatabaseConnectionService.getInstance().getDBConnection().executeQueryWithRS(query);
    try {
        while (rs.next()) {
            String line = "";
            String username = rs.getString(2);
            if (!registeredCache.containsKey(username.toLowerCase())) {
                boolean registered = UserService.getInstance().isRegistered(username);
                if (!registered)
                    username += "(U)";
                registeredCache.put(username.toLowerCase(), registered);
            } else /* we have cached information about whether this user is registered */ {
                boolean registered = registeredCache.get(username.toLowerCase());
                if (!registered)
                    username += "(U)";
            }

            if (!isAdmin)
                line = String.format("%26s: %-20s %s", sdf.format(rs.getTimestamp(3).getTime()), username,
                        rs.getString(4));
            if (isAdmin)
                line = String.format("%26s: %-20s %7s from %s", sdf.format(rs.getTimestamp(3).getTime()),
                        username, rs.getString(4), rs.getString(5));
            if (rs.next()) {
                line += "\n";
                rs.previous();
            }
            b.append(line);
        }
    } catch (SQLException e) {
        Morphy.getInstance().onError(e);
    }

    userSession.send(b.toString());
    return;

    /*UserSession uS = null;
    String[] array = UserService.getInstance().completeHandle(arguments);
    if (array.length == 0) {
       userSession.send(arguments + " is not logged in.");
       return;
    }
    if (array.length > 1) {
       StringBuilder b = new StringBuilder();
       b.append("-- Matches: " + array.length + " player(s) --\n");
       for(int i=0;i<array.length;i++) {
    b.append(array[i] + "  ");
       }
       userSession.send(b.toString());
       return;
    }
    uS = UserService.getInstance().getUserSession(array[0]);
    */
}

From source file:ips1ap101.lib.core.db.util.Exporter.java

private static int getLimiteFilasFuncionSelect(String archivo, UsuarioActual usuario) {
    Integer limiteFilas = Utils.getReportRowsLimit(archivo, FORMATO_GUARDAR, usuario);
    if (limiteFilas != null) {
        return limiteFilas;
    }/*from   w  ww .  j a v a2 s  .  c  o m*/
    String string = BaseBundle.getLimiteFilasFuncionExport(archivo);
    int limite = StringUtils.isNotBlank(string) && StringUtils.isNumeric(string) ? Integer.valueOf(string) : -1;
    return limite < 0 ? LIMITE_FILAS_FUNCION_SELECT : limite;
}

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

public static void emit(RiskFact fact, String riskLevelTxt, String riskMessage, String... riskScene) {
    if (!StringUtils.isNumeric(riskLevelTxt)) {
        throw new IllegalArgumentException("\"riskLevel\"");
    }//from   w  w w .j  a v  a2 s . c o  m
    int riskLevel = NumberUtils.toInt(riskLevelTxt, 0);
    emit(fact, riskLevel, riskMessage, riskScene);
}

From source file:eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.XLinkReference.java

@Override
public Object idToReference(Object id) {
    if (id == null || id.toString().isEmpty()) {
        throw new IllegalArgumentException("ID must not be null or empty");
    }// w ww.java 2s  .  c  o  m

    // XXX possible performance impact? this check is done for every
    // reference...
    if (!StringUtils.isNumeric(id.toString().substring(0, 1))
            && !StringUtils.containsAny(id.toString(), "\"\\ !#$%&'()*+,/:;<=>?@[]^`{|}~")) {
        // if the ID is a valid NCName convert it to a local XPointer
        return "#" + id.toString();
    } else {
        return super.idToReference(id);
    }
}

From source file:fr.paris.lutece.plugins.document.utils.IntegerUtils.java

/**
 * Convert a given String into an integer.
 * <br />/*from w  ww  .  j a  v  a 2  s  .  co m*/
 * If the String is blank or is not numerical, then it returns nDefault
 * @param strToParse the String to parse
 * @param nDefault the default value in case the conversion fails
 * @return the numerical value of the String
 */
public static int convert(String strToParse, int nDefault) {
    if (StringUtils.isNotBlank(strToParse) && StringUtils.isNumeric(strToParse)) {
        return Integer.parseInt(strToParse);
    }

    return nDefault;
}

From source file:eu.annocultor.tagger.postprocessors.PopulationTermFilter.java

@Override
public TermList disambiguate(TermList allTerms, DisambiguationContext disambiguationContext) throws Exception {

    // disambiguation not needed
    if (allTerms.size() < 2)
        return allTerms;

    Term largestPlace = null;//from   ww w.  ja v  a2  s.  c om
    long largestPopulation = 0;

    // disambiguate
    TermList selectedTerms = new TermList();
    for (Term term : allTerms) {

        if (largestPlace == null) {
            largestPlace = term;
        }

        String populationString = term.getProperty(VOCAB_ATTR_POPULATION);

        if (populationString != null && !populationString.isEmpty()
                && StringUtils.isNumeric(populationString)) {
            try {
                long population = Integer.parseInt(populationString);
                if (population > largestPopulation) {
                    largestPopulation = population;
                    largestPlace = term;
                }
            } finally {
                // just ignore
            }
        }
    }

    // choose the place with the largest population
    if (largestPopulation > 0) {
        selectedTerms = new TermList();
        selectedTerms.add(largestPlace);
        return selectedTerms;
    }

    return allTerms;
}

From source file:edu.usu.sdl.openstorefront.web.rest.model.DateParam.java

public DateParam(String input) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss");
    try {/*from w  w  w.  j a  v  a2  s. c  o m*/
        date = sdf.parse(input);
    } catch (ParseException e) {
        sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = sdf.parse(input);
        } catch (ParseException ex) {
            sdf = new SimpleDateFormat("MM/dd/yyyy");
            try {
                date = sdf.parse(input);
            } catch (ParseException exc) {
                if (StringUtils.isNumeric(input)) {
                    try {
                        date = new Date(Long.parseLong(input));
                    } catch (Exception exception) {
                        //Don't throw error here it's to low level. (it will get wrapped several times)
                        //if the date is not expected to be null handle error there.
                        log.log(Level.FINE, MessageFormat.format("Unsupport date format: {0}", input));
                    }
                } else {
                    log.log(Level.FINE, MessageFormat.format("Unsupport date format: {0}", input));
                }
            }
        }
    }
}