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

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

Introduction

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

Prototype

public static boolean isNumber(final String str) 

Source Link

Document

Checks whether the String a valid Java number.

Valid numbers include hexadecimal marked with the 0x or 0X qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.

Usage

From source file:comparetopics.CompareTopics.java

/**
 * @param args the command line arguments
 *///from  w w  w  .  j  av  a 2s. c  om
public static void main(String[] args) {
    try {
        File file1 = new File(
                "/Users/apple/Desktop/graduation-project/topic-modeling/output/jhotdraw-extracted-code/keys.txt");
        File file2 = new File(
                "/Users/apple/Desktop/graduation-project/topic-modeling/output/jhotdraw-extracted-code/keys.txt");

        CompareTopics compareTopics = new CompareTopics();
        String[] words1 = compareTopics.getWords(file1);
        String[] words2 = compareTopics.getWords(file2);
        StringBuffer words = new StringBuffer();

        File outputFile = new File("/Users/apple/Desktop/test.txt");
        if (outputFile.createNewFile()) {
            System.out.println("Create successful: " + outputFile.getName());
        }
        boolean hasSame = false;

        for (String w1 : words1) {
            if (!NumberUtils.isNumber(w1)) {
                for (String w2 : words2) {
                    if (w1.equals(w2)) {
                        words.append(w1);
                        //                            words.append("\r\n");
                        words.append(" ");
                        hasSame = true;
                        break;
                    }
                }
            }
        }
        if (!hasSame) {
            System.out.println("No same word.");
        } else {
            compareTopics.printToFile(words.toString(), outputFile);
        }

    } catch (IOException ex) {
        Logger.getLogger(CompareTopics.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.github.xbn.examples.lang.non_xbn.VerifyUserInputIsANumberWithIsNumber.java

public static final void main(String[] ignored) {

    int num = -1;
    boolean isNum = false;

    do {/*ww  w  .ja va 2 s . c  o m*/
        System.out.print("Number please: ");
        String strInput = (new Scanner(System.in)).next();
        if (!NumberUtils.isNumber(strInput)) {
            System.out.println(strInput + " is not a number. Try again.");
        } else {
            //Safe to convert
            num = Integer.parseInt(strInput);
            isNum = true;
        }
    } while (!isNum);

    System.out.println("Number: " + num);
}

From source file:com.github.xbn.examples.regexutil.non_xbn.UserInputNumInRangeWRegex.java

public static final void main(String[] ignored) {

    int num = -1;
    boolean isNum = false;

    int iRangeMax = 2055;

    //"": Dummy string, to reuse matcher
    Matcher mtchrNumNegThrPos = Pattern.compile("-?\\b(20(5[0-5]|[0-4][0-9])|1?[0-9]{1,3})\\b").matcher("");

    do {//  w w w.j av  a2s.  c  o  m
        System.out.print("Enter a number between -" + iRangeMax + " and " + iRangeMax + ": ");
        String strInput = (new Scanner(System.in)).next();
        if (!NumberUtils.isNumber(strInput)) {
            System.out.println("Not a number. Try again.");
        } else if (!mtchrNumNegThrPos.reset(strInput).matches()) {
            System.out.println("Not in range. Try again.");
        } else {
            //Safe to convert
            num = Integer.parseInt(strInput);
            isNum = true;
        }
    } while (!isNum);

    System.out.println("Number: " + num);
}

From source file:cn.com.sunjiesh.xcutils.common.VersionUtil.java

public static void main(String[] args) {
    System.out.println("NumberUtils.isNumber(version1)=" + NumberUtils.isNumber("2.3.1"));

    System.out.println("compareVersion=" + compareVersion("1.0", "2.3.1"));
}

From source file:net.sfr.tv.mom.mgt.HornetqConsole.java

/**
 * @param args the command line arguments
 *///from w  ww. j av a  2  s. c o  m
public static void main(String[] args) {

    try {

        String jmxHost = "127.0.0.1";
        String jmxPort = "6001";

        // Process command line arguments
        String arg;
        for (int i = 0; i < args.length; i++) {
            arg = args[i];
            switch (arg) {
            case "-h":
                jmxHost = args[++i];
                break;
            case "-p":
                jmxPort = args[++i];
                break;
            default:
                break;
            }
        }

        // Check for arguments consistency
        if (StringUtils.isEmpty(jmxHost) || !NumberUtils.isNumber(jmxPort)) {
            LOGGER.info("Usage : ");
            LOGGER.info("hq-console.jar <-h host(127.0.0.1)> <-p port(6001)>\n");
            System.exit(1);
        }

        System.out.println(
                SystemUtils.LINE_SEPARATOR.concat(Ansi.format("HornetQ Console ".concat(VERSION), Color.CYAN)));

        final StringBuilder _url = new StringBuilder("service:jmx:rmi://").append(jmxHost).append(':')
                .append(jmxPort).append("/jndi/rmi://").append(jmxHost).append(':').append(jmxPort)
                .append("/jmxrmi");

        final String jmxServiceUrl = _url.toString();
        JMXConnector jmxc = null;

        final CommandRouter router = new CommandRouter();

        try {
            jmxc = JMXConnectorFactory.connect(new JMXServiceURL(jmxServiceUrl), null);
            assert jmxc != null; // jmxc must be not null
        } catch (final MalformedURLException e) {
            System.out.println(SystemUtils.LINE_SEPARATOR
                    .concat(Ansi.format(jmxServiceUrl + " :" + e.getMessage(), Color.RED)));
        } catch (Throwable t) {
            System.out.println(SystemUtils.LINE_SEPARATOR.concat(
                    Ansi.format("Unable to connect to JMX service URL : ".concat(jmxServiceUrl), Color.RED)));
            System.out.print(SystemUtils.LINE_SEPARATOR.concat(
                    Ansi.format("Did you add jmx-staticport-agent.jar to your classpath ?", Color.MAGENTA)));
            System.out.println(SystemUtils.LINE_SEPARATOR.concat(Ansi.format(
                    "Or did you set the com.sun.management.jmxremote.port option in the hornetq server startup script ?",
                    Color.MAGENTA)));
            System.exit(-1);
        }

        System.out.println("\n".concat(Ansi
                .format("Successfully connected to JMX service URL : ".concat(jmxServiceUrl), Color.YELLOW)));

        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        // PRINT SERVER STATUS REPORT
        System.out.print((String) router.get(Command.STATUS, Option.VM).execute(mbsc, null));
        System.out.print((String) router.get(Command.STATUS, Option.SERVER).execute(mbsc, null));
        System.out.print((String) router.get(Command.STATUS, Option.CLUSTER).execute(mbsc, null));

        printHelp(router);

        // START COMMAND LINE
        Scanner scanner = new Scanner(System.in);
        System.out.print("> ");
        String input;
        while (!(input = scanner.nextLine().concat(" ")).equals("exit ")) {

            String[] cliArgs = input.split("\\ ");
            CommandHandler handler;

            if (cliArgs.length < 1) {
                System.out.print("> ");
                continue;
            }

            Command cmd = Command.fromString(cliArgs[0]);
            if (cmd == null) {
                System.out.print(Ansi.format("Syntax error !", Color.RED).concat("\n"));
                cmd = Command.HELP;
            }

            switch (cmd) {
            case STATUS:
            case LIST:
            case DROP:

                Set<Option> options = router.get(cmd);

                for (Option opt : options) {

                    if (cliArgs[1].equals(opt.toString())) {
                        handler = router.get(cmd, opt);

                        String[] cmdOpts = null;
                        if (cliArgs.length > 2) {
                            cmdOpts = new String[cliArgs.length - 2];
                            for (int i = 0; i < cmdOpts.length; i++) {
                                cmdOpts[i] = cliArgs[2 + i];
                            }
                        }

                        Object result = handler.execute(mbsc, cmdOpts);
                        if (result != null && String.class.isAssignableFrom(result.getClass())) {
                            System.out.print((String) result);
                        }
                        System.out.print("> ");
                    }
                }

                break;

            case FORK:
                // EXECUTE SYSTEM COMMAND
                ProcessBuilder pb = new ProcessBuilder(Arrays.copyOfRange(cliArgs, 1, cliArgs.length));
                pb.inheritIO();
                pb.start();
                break;

            case HELP:
                printHelp(router);
                break;
            }
        }
    } catch (MalformedURLException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }

    echo(SystemUtils.LINE_SEPARATOR.concat(Ansi.format("Bye!", Color.CYAN)));

}

From source file:cn.sixlab.sixutil.StrUtil.java

/**
 * ??//from w  w w .  j  av a2s  . c  o  m
 *
 * @param str ?
 * @return {@code str}?true {@code str}false
 */
public static Boolean isNotNumber(String str) {
    return !NumberUtils.isNumber(str);
}

From source file:dingwen.Command.java

public static void removeShapeCmd(String command, ShapeCache shapeCache) {
    BigInteger id = null;//  w  ww.j a  v a  2s .  com
    if (NumberUtils.isNumber(command.substring(command.indexOf(" ") + 1))) {
        id = new BigInteger(command.substring(command.indexOf(" ") + 1));
        Shape shape = shapeCache.removeShape(id);
        if (shape == null) {
            System.out.println(CommonStatement.SHAPE_NOT_EXISTS);
        } else {
            System.out.println("Removed shape " + id + " : " + shape.toString());
        }
    } else {
        System.out.println(CommonStatement.ID_INVALID);
    }
}

From source file:com.github.arnabk.App.java

private static boolean checkParams(String args[]) {
    boolean ret = false;
    if (args.length < 2) {
        printUsage();/*from  ww w  .j a v  a  2 s. c o  m*/
    } else {
        if (NumberUtils.isNumber(args[0])) {
            ret = true;
        } else {
            printUsage();
        }
    }
    return ret;
}

From source file:gov.nyc.doitt.gis.geoclient.service.domain.Borough.java

public static int parseInt(String boroughString) {
    if (NumberUtils.isNumber(boroughString)) {
        return Integer.valueOf(boroughString);
    }/*from w  w  w .  j  ava  2  s  .  c  o m*/

    for (Map.Entry<String, Integer> entry : NAMES.entrySet()) {
        if (entry.getKey().equalsIgnoreCase(boroughString)) {
            return entry.getValue();
        }
    }

    return 0;
}

From source file:it.f2informatica.core.aop.ServicesAspect.java

private static boolean isNotNumber(String value) {
    return !NumberUtils.isNumber(value);
}