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:moe.encode.airblock.commands.localization.sources.ArrayValueSource.java

@Nullable
@Override/*from   w  w  w  .j a  va 2  s.c o  m*/
public Optional<?> get(@NonNull String value) {
    if (!StringUtils.isNumeric(value))
        return Optional.empty();

    int index = Integer.valueOf(value);
    if (index < 0 || index >= this.values.size())
        return Optional.empty();
    return Optional.from(this.values.get(index));
}

From source file:com.peso.Registro.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from www . j ava2 s  .  c  om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    boolean bError = false;
    String mensajeError = "";
    String nombre = "";
    String peso = "";
    //Errores

    if (request.getSession().getAttribute(Constantes.ATRIBUTO_NOMBRE) != null) {
        mensajeError = Constantes.MENSAJE_ERROR_NOMBRE_EXISTE;
        bError = true;
    } else {
        nombre = request.getParameter(Constantes.ATRIBUTO_NOMBRE);
        peso = request.getParameter(Constantes.ATRIBUTO_PESO);

        if (nombre == null) {
            mensajeError = Constantes.MENSAJE_ERROR_NO_NOMBRE;
            bError = true;
        } else if (peso == null) {
            mensajeError = Constantes.MENSAJE_ERROR_NO_PESO;
            bError = true;
        } else if (!StringUtils.isNumeric(peso)) {
            mensajeError = Constantes.MENSAJE_ERROR_PESO_NO_NUMERO;
            bError = true;
        }
    }
    if (!bError) {
        //Registrar el usuario
        request.getSession().setAttribute(Constantes.ATRIBUTO_NOMBRE,
                request.getParameter(Constantes.ATRIBUTO_NOMBRE));
        request.getSession().setAttribute(Constantes.ATRIBUTO_PESO,
                request.getParameter(Constantes.ATRIBUTO_PESO));
        //Bienvenida
        request.setAttribute(Constantes.ATRIBUTO_NOMBRE, nombre);
        request.setAttribute(Constantes.ATRIBUTO_PESO, peso);
        response.getWriter().print("TRUE");
        //request.getRequestDispatcher(Constantes.PAGINA_REGISTRO).forward(request, response);

    } else {
        request.setAttribute(Constantes.ATRIBUTO_ERROR, mensajeError);
        response.getWriter().print("FALSE");
        //request.getRequestDispatcher(Constantes.PAGINA_ERROR).forward(request, response);
    }

}

From source file:co.foxdev.foxbot.commands.CommandMcPing.java

public void execute(final MessageEvent event, final String[] args) {
    User sender = event.getUser();/*from w  ww.ja va  2 s . c  o m*/
    Channel channel = event.getChannel();

    if (args.length > 0 && args.length <= 2) {
        String host = args[0];
        int port = 25565;

        if (args.length == 2 && StringUtils.isNumeric(args[1])) {
            port = Integer.parseInt(args[1]);
        }

        MinecraftPingReply mcping;

        try {
            MinecraftPingOptions mcpo = new MinecraftPingOptions().setHostname(host).setPort(port)
                    .setTimeout(500);
            mcping = new MinecraftPing().getPing(mcpo);
        } catch (IOException ex) {
            foxbot.getLogger().error("Error occurred while pinging " + host, ex);
            channel.send().message(String.format("(%s) Looks like %s:%s isn't up.",
                    Utils.munge(sender.getNick()), host, port));
            return;
        }

        String motd = mcping.getDescription().replace("\n", " ");
        String players = mcping.getPlayers().getOnline() + "/" + mcping.getPlayers().getMax();
        String version = mcping.getVersion().getName();
        String finalPing = String.format("%s%s - %s - %s", motd, Colors.NORMAL, players, version);
        channel.send().message(
                Utils.colourise(String.format("(%s) %s", Utils.munge(sender.getNick()), finalPing), '\u00A7'));
        return;
    }

    sender.send().notice(String.format("Wrong number of args! Use %smcping <host> [port]",
            foxbot.getConfig().getCommandPrefix()));
}

From source file:com.glaf.jbpm.web.springmvc.MxJbpmImageController.java

@RequestMapping
@ResponseBody//  w  ww  . j a  va 2s  .  c o m
public byte[] showImage(
        @RequestParam(value = "processDefinitionId", required = false) String processDefinitionId,
        @RequestParam(value = "processName", required = false) String processName) {
    byte[] bytes = null;
    JbpmContext jbpmContext = null;
    try {
        if (StringUtils.isNotEmpty(processDefinitionId) && StringUtils.isNumeric(processDefinitionId)) {
            bytes = JbpmProcessConfig.getImage(Long.parseLong(processDefinitionId));
        } else if (StringUtils.isNotEmpty(processName)) {
            jbpmContext = ProcessContainer.getContainer().createJbpmContext();
            ProcessDefinition processDefinition = jbpmContext.getGraphSession()
                    .findLatestProcessDefinition(processName);
            if (processDefinition != null) {
                bytes = JbpmProcessConfig.getImage(processDefinition.getId());
            }
        }
    } catch (Exception ex) {
        logger.debug(ex);
    } finally {
        Context.close(jbpmContext);
    }
    return bytes;
}

From source file:gov.ca.cwds.cals.service.FacilityInspectionService.java

/**
 * Numeric IDS are considered for FAS facility,
 * Other IDS are considered for CWS facility
 *
 * @param facilityId gets facility number for inspections search in FAS
 * @return Facility ID for FAS facility and License number for CWS facility
 *///from  w w w. j  a  v  a  2s .  c om
public String getFacilityNumber(String facilityId) {
    if (StringUtils.isNumeric(facilityId)) {
        return facilityId;
    } else {
        return getFacilityLicenseNo(facilityId);
    }
}

From source file:com.nridge.connector.fs.con_fs.core.Constants.java

public static int getCfgSleepValue(AppMgr anAppMgr, String aCfgName, int aDefaultValue) {
    int sleepInSeconds = aDefaultValue;

    String timeString = anAppMgr.getString(aCfgName);
    if (StringUtils.isNotEmpty(timeString)) {
        if (StringUtils.endsWithIgnoreCase(timeString, "m")) {
            String minuteString = StringUtils.stripEnd(timeString, "m");
            if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) {
                int minuteAmount = Integer.parseInt(minuteString);
                sleepInSeconds = minuteAmount * 60;
            }/*from  w w w .  j  a v  a2  s  .c om*/
        } else if (StringUtils.endsWithIgnoreCase(timeString, "h")) {
            String hourString = StringUtils.stripEnd(timeString, "h");
            if ((StringUtils.isNotEmpty(hourString)) && (StringUtils.isNumeric(hourString))) {
                int hourAmount = Integer.parseInt(hourString);
                sleepInSeconds = hourAmount * 60 * 60;
            }
        } else if (StringUtils.endsWithIgnoreCase(timeString, "d")) {
            String dayString = StringUtils.stripEnd(timeString, "d");
            if ((StringUtils.isNotEmpty(dayString)) && (StringUtils.isNumeric(dayString))) {
                int dayAmount = Integer.parseInt(dayString);
                sleepInSeconds = dayAmount * 60 * 60 * 24;
            }
        } else // we assume seconds
        {
            String secondString = StringUtils.stripEnd(timeString, "s");
            if ((StringUtils.isNotEmpty(secondString)) && (StringUtils.isNumeric(secondString))) {
                sleepInSeconds = Integer.parseInt(secondString);
            }
        }
    }

    return sleepInSeconds;
}

From source file:com.ijuru.kwibuka.WordSequence.java

/**
 * Scores this sequence/*from  w ww  . j  av  a2  s  .  co  m*/
 */
public void score() {
    int numericTokens = 0;
    for (String token : this) {
        if (StringUtils.isNumeric(token)) {
            ++numericTokens;
        }
    }

    this.score = 100 / size() - numericTokens;
}

From source file:ch.jamiete.hilda.moderatortools.commands.ClearCommand.java

@Override
public void execute(final Message message, final String[] args, final String label) {
    final Member member = message.getGuild().getMember(message.getAuthor());

    if (!member.hasPermission(message.getTextChannel(), Permission.MESSAGE_MANAGE)) {
        this.reply(message, "You don't have permission.");
        return;/*from w ww. jav a 2s.c  o  m*/
    }

    if (args.length < 1 || args.length > 2 || args.length == 1 && !StringUtils.isNumeric(args[0])
            || args.length == 2 && !StringUtils.isNumeric(args[1])) {
        this.usage(message, "[username] <number>");
        return;
    }

    if (!message.getGuild().getSelfMember().hasPermission(message.getTextChannel(),
            Permission.MESSAGE_HISTORY)) {
        this.reply(message, "I do not have permission to view the channel history.");
        return;
    }

    if (!message.getGuild().getSelfMember().hasPermission(message.getTextChannel(),
            Permission.MESSAGE_MANAGE)) {
        this.reply(message, "I do not have permission to delete messages.");
        return;
    }

    final int amount = Integer.valueOf(args.length == 2 ? args[1] : args[0]);
    final User user = message.getMentionedUsers().stream().findFirst().orElse(null);

    if (amount < 2) {
        this.reply(message, "You must delete at least 2 messages.");
        return;
    }

    if (amount > 1000) {
        this.reply(message, "You cannot bulk delete that many messages! Use purge instead.");
        return;
    }

    message.delete().reason("I automatically delete some command invocations.").queue(m -> this.hilda
            .getExecutor().execute(new ChannelClearTask(message.getTextChannel(), amount, user)));
}

From source file:com.peso.Workout.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  w w  w  . j a  v a 2  s.co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    boolean bError = false;
    String mensajeError = "";

    String nombre = "";
    String peso = "";
    String workout = "";
    LocalDateTime ultimaLlamada = null;
    LocalDateTime ahora = null;
    LocalDateTime lesionado = null;

    //Errores
    if (request.getSession().getAttribute("nombre") == null) {
        mensajeError = "no hay nombre resgistrado";
        bError = true;
    } else {
        workout = request.getParameter("workout");

        if (workout == null) {
            mensajeError = "falta el parametro workout";
            bError = true;
        } else if (!StringUtils.isNumeric(workout)) {
            mensajeError = "workout debe de ser numrico";
            bError = true;
        }
    }
    if (!bError) {
        //Registrar el usuario
        nombre = (String) request.getSession().getAttribute("nombre");
        peso = (String) request.getSession().getAttribute("peso");
        ahora = LocalDateTime.now();
        ultimaLlamada = (LocalDateTime) request.getSession().getAttribute("ultimaLlamada");
        if (ultimaLlamada == null) {
            ultimaLlamada = LocalDateTime.now();
        }
        //engordar cada 10 segundos, tiempo entre llamadas.
        Duration segundos = Duration.between(ultimaLlamada, ahora);
        int iPeso = NumberUtils.toInt(peso);
        iPeso += (segundos.getSeconds() / 10);

        //mirar si lesion
        lesionado = (LocalDateTime) request.getSession().getAttribute("lesionado");
        Duration segundosLesion = null;

        // si hay lesion esperar tiempo
        if (lesionado != null) {
            segundosLesion = Duration.between(lesionado, ahora);
            if (segundosLesion.getSeconds() >= 30) {
                // se le quita la lesion
                request.getSession().setAttribute("lesionado", null);
            }
            request.setAttribute("lesionado", (30 - segundosLesion.getSeconds()) + "");
        } else//si han pasado menos de 5 seg se lesiona
        {
            if (segundos.getSeconds() <= 5) {
                request.getSession().setAttribute("lesionado", ahora);
            } else {
                //si no la hay adelgaza el tiempo requerido.
                int kilosAdelgazar = (NumberUtils.toInt(workout) / 30);
                kilosAdelgazar *= (int) (0.2 * iPeso);
                iPeso -= kilosAdelgazar;
            }
        }
        peso = iPeso + "";
        request.getSession().setAttribute("peso", peso);
        request.getSession().setAttribute("ultimaLlamada", ahora);

        request.setAttribute("nombre", nombre);
        request.setAttribute("peso", peso);
        request.getRequestDispatcher("/workout.jsp").forward(request, response);
    } else {
        request.setAttribute(Constantes.ATRIBUTO_ERROR, mensajeError);
        request.getRequestDispatcher(Constantes.PAGINA_ERROR).forward(request, response);
    }
}

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

/**
 * ?//w  w  w  . j a  v  a2s  . co m
 *
 * @param numString String
 * @return int
 */
public static int string2Int(final String numString) {
    if (StringUtils.isNumeric(numString)) {
        return Integer.valueOf(numString);
    }
    return 0;
}