Example usage for java.util Scanner hasNext

List of usage examples for java.util Scanner hasNext

Introduction

In this page you can find the example usage for java.util Scanner hasNext.

Prototype

public boolean hasNext(Pattern pattern) 

Source Link

Document

Returns true if the next complete token matches the specified pattern.

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0";

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.hasNext(Pattern.compile(".com")));

    System.out.println(scanner.hasNext(Pattern.compile("1")));

    // print the rest of the string
    System.out.println(scanner.nextLine());

    scanner.close();//from  www.ja  va  2 s.c  o m
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // check if next token is "java"
    System.out.println(scanner.hasNext("java"));

    // find the last match and print it
    System.out.println(scanner.match());

    System.out.println(scanner.nextLine());

    scanner.close();/*w w  w.j  av  a  2 s. c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0";

    Scanner scanner = new Scanner(s);

    // check if the scanner's next token matches "c"
    System.out.println(scanner.hasNext("c"));

    // check if the scanner's next token matches "="
    System.out.println(scanner.hasNext("="));

    // print the rest of the string
    System.out.println(scanner.nextLine());
    scanner.close();/* ww  w  . jav a 2  s  . c  o  m*/
}

From source file:com.excelsiorsoft.transformer.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*  w w w.j av  a 2  s. c o  m*/
 */
public static void main(final String... args) {

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n          Welcome to Spring Integration!                 "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       "
            + "\n                                                         "
            + "\n=========================================================");

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    SpringIntegrationUtils.displayDirectories(context);

    final Scanner scanner = new Scanner(System.in);

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n    Please press 'q + Enter' to quit the application.    "
            + "\n                                                         "
            + "\n=========================================================");

    while (!scanner.hasNext("q")) {
        //Do nothing unless user presses 'q' to quit.
    }

    LOGGER.info("Exiting application...bye.");

    System.exit(0);

}

From source file:org.springframework.integration.samples.storedprocedure.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from   ww w  .  j  a v  a2 s .  c o  m
 */
public static void main(final String... args) {

    LOGGER.info(LINE + LINE + "\n    Welcome to Spring Integration Coffee Database!       " + NEWLINE
            + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       " + NEWLINE + LINE);

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final CoffeeService service = context.getBean(CoffeeService.class);

    LOGGER.info(LINE + NEWLINE + "\n    Please press 'q + Enter' to quit the application." + NEWLINE + LINE);

    System.out.print("Please enter 'list' and press <enter> to get a list of coffees.");
    System.out.print("Enter a coffee id, e.g. '1' and press <enter> to get a description.\n\n");

    while (!scanner.hasNext("q")) {

        String input = scanner.nextLine();

        if ("list".equalsIgnoreCase(input)) {
            List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();

            for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
                System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName()));
            }

        } else {
            System.out.println("Retrieving coffee information...");
            String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));

            System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
            System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n");
        }

    }

    LOGGER.info("Exiting application...bye.");

    scanner.close();
    context.close();

}

From source file:com.vinod.spring.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//  w  w w  .j  a  v a 2  s.  co  m
 */
public static void main(final String... args) {

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n          Welcome to Spring Integration!                 "
                + "\n                                                         "
                + "\n    For more information please visit:                   "
                + "\n    http://www.springsource.org/spring-integration       "
                + "\n                                                         "
                + "\n=========================================================");
    }

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    SpringIntegrationUtils.displayDirectories(context);

    final Scanner scanner = new Scanner(System.in);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    while (!scanner.hasNext("q")) {
        //Do nothing unless user presses 'q' to quit.
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}

From source file:au.edu.uws.eresearch.cr8it.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from   ww w .  jav a2 s .co  m
 */
public static void main(final String... args) {

    String contextFilePath = "spring-integration-context.xml";
    String configFilePath = "config/config-file.groovy";
    String environment = System.getProperty("environment");

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n          Welcome to C8it Integration!                 "
                + "\n                                                         "
                + "\n    For more information please visit:                   "
                + "\n    http://www.springsource.org/spring-integration       "
                + "\n                                                         "
                + "\n=========================================================");
    }

    ConfigObject config = Config.getConfig(environment, configFilePath);
    Map configMap = config.flatten();
    System.setProperty("environment", environment);
    System.setProperty("cr8it.client.config.file", (String) configMap.get("file.runtimePath"));

    //final AbstractApplicationContext context =
    //new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");

    String absContextPath = "config/integration/" + contextFilePath;
    File contextFile = new File(absContextPath);
    final AbstractApplicationContext context;
    if (!contextFile.exists()) {
        absContextPath = "classpath:" + absContextPath;
        context = new ClassPathXmlApplicationContext(absContextPath);
    } else {
        absContextPath = "file:" + absContextPath;
        context = new FileSystemXmlApplicationContext(absContextPath);
    }

    context.registerShutdownHook();

    SpringIntegrationUtils.displayDirectories(context);

    final Scanner scanner = new Scanner(System.in);

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    while (!scanner.hasNext("q")) {
        //Do nothing unless user presses 'q' to quit.
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}

From source file:gis.proj.drivers.Snyder.java

public static void main(String... args) {
    Snyder snyder = new Snyder();
    JCommander jc = new JCommander(snyder);

    try {// w w w  .ja va2  s.  com
        jc.parse(args);
    } catch (Exception e) {
        jc.usage();
        System.exit(-10);
    }

    String fFormat = "(forward)   X: %18.9f,   Y: %18.9f%n";
    String iFormat = "(inverse) Lon: %18.9f, Lat: %18.9f%n%n";

    double[][] xy, ll = null;

    java.util.regex.Pattern pq = java.util.regex.Pattern.compile("quit",
            java.util.regex.Pattern.CASE_INSENSITIVE);
    java.util.Scanner s = new java.util.Scanner(System.in);

    Projection proj = null;

    printLicenseInformation("Snyder");

    try {
        System.out.println("Loading projection: " + snyder.projStr);
        Class<?> cls = Class.forName(snyder.projStr);
        proj = (Projection) cls.newInstance();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    double lon = 0.0, lat = 0.0, x = 0.0, y = 0.0;

    Datum d = new Datum();
    Ellipsoid e = EllipsoidFactory.getInstance().getEllipsoid(snyder.ellpStr);
    System.out.println("\nEllipsoid: " + snyder.ellpStr + ", " + e.getName() + ", " + e.getId() + ", "
            + e.getDescription());

    for (String prop : e.getPropertyNames()) {
        System.out.println("\t" + prop + "\t" + e.getProperty(prop));
    }

    String cmdEntryLine = (snyder.inverse ? "\nx y " : "\nlon lat") + ": ";

    for (String dProp : proj.getDatumProperties()) {
        d.setUserOverrideProperty(dProp, 0.0);
    }
    System.out.print(cmdEntryLine);

    while (s.hasNext(pq) == false) {
        if (snyder.inverse == false) {
            lon = parseDatumVal(s.next());
            lat = parseDatumVal(s.next());
        } else {
            x = parseDatumVal(s.next());
            y = parseDatumVal(s.next());
        }

        for (String dp : d.getPropertyNames()) {
            System.out.print(dp + ": ");
            d.setUserOverrideProperty(dp, parseDatumVal(s.next()));
        }

        System.out.println();

        if (snyder.inverse == false) {
            xy = proj.forward(new double[] { lon }, new double[] { lat }, e, d);

            System.out.printf(fFormat, xy[0][0], xy[1][0]);

            ll = proj.inverse(new double[] { xy[0][0] }, new double[] { xy[1][0] }, e, d);

            System.out.printf(iFormat, StrictMath.toDegrees(ll[0][0]), StrictMath.toDegrees(ll[1][0]));
        } else {
            ll = proj.inverse(new double[] { x }, new double[] { y }, e, d);

            System.out.printf(iFormat, StrictMath.toDegrees(ll[0][0]), StrictMath.toDegrees(ll[1][0]));

            xy = proj.forward(new double[] { ll[0][0] }, new double[] { ll[1][0] }, e, d);

            System.out.printf(fFormat, xy[0][0], xy[1][0]);
        }

        System.out.print(cmdEntryLine);
    }

    s.close();
}

From source file:org.springframework.integration.samples.enricher.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from  w  ww.j  av a 2  s .  c  om
 */
public static void main(final String... args) {

    LOGGER.info(LINE_SEPARATOR + EMPTY_LINE + "\n          Welcome to Spring Integration!                 "
            + EMPTY_LINE + "\n    For more information please visit:                   "
            + "\n    http://www.springsource.org/spring-integration       " + EMPTY_LINE + LINE_SEPARATOR);

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in);

    final UserService service = context.getBean(UserService.class);

    LOGGER.info(LINE_SEPARATOR + EMPTY_LINE
            + "\n    Please press 'q + Enter' to quit the application.                     " + EMPTY_LINE
            + LINE_SEPARATOR + EMPTY_LINE
            + "\n    This example illustrates the usage of the Content Enricher.           " + EMPTY_LINE
            + "\n    Usage: Please enter 1 or 2 or 3 + Enter                               " + EMPTY_LINE
            + "\n    3 different message flows are triggered. For sample 1+2 a             "
            + "\n    user object containing only the username is passed in.                "
            + "\n    For sample 3 a Map with the 'username' key is passed in and enriched  "
            + "\n    with the user object using the 'user' key.                            " + EMPTY_LINE
            + "\n    1: In the Enricher, pass the full User object to the request channel. "
            + "\n    2: In the Enricher, pass only the username to the request channel.    "
            + "\n    3: In the Enricher, pass only the username to the request channel.    " + EMPTY_LINE
            + LINE_SEPARATOR);

    while (!scanner.hasNext("q")) {

        final String input = scanner.nextLine();

        User user = new User("foo", null, null);

        if ("1".equals(input)) {

            final User fullUser = service.findUser(user);
            printUserInformation(fullUser);

        } else if ("2".equals(input)) {

            final User fullUser = service.findUserByUsername(user);
            printUserInformation(fullUser);

        } else if ("3".equals(input)) {

            final Map<String, Object> userData = new HashMap<String, Object>();
            userData.put("username", "foo_map");

            final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData);

            final User fullUser = (User) enrichedUserData.get("user");

            printUserInformation(fullUser);

        } else {
            LOGGER.info("\n\n    Please enter '1', '2', or '3' <enter>:\n\n");
        }

    }

    LOGGER.info("\n\nExiting application...bye.");

    scanner.close();
    context.close();

}

From source file:com.japp.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*from  w  w w  . j  a  v  a 2  s .co m*/
 */
public static void main(final String... args) {

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n       SFTP-File Transfer POC                 "
                + "\n                                                         "
                + "\n=========================================================");
    }

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:/launch-context.xml");

    context.registerShutdownHook();

    SpringIntegrationUtils.displayDirectories(context);

    final Scanner scanner = new Scanner(System.in);

    JobLauncher jobLauncher = context.getBean("jobLauncher", JobLauncher.class);
    Job job = context.getBean("job1", Job.class);

    try {
        jobLauncher.run(job, new JobParameters());
    } catch (JobExecutionAlreadyRunningException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (JobRestartException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (JobInstanceAlreadyCompleteException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (JobParametersInvalidException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("\n========================================================="
                + "\n                                                         "
                + "\n    Please press 'q + Enter' to quit the application.    "
                + "\n                                                         "
                + "\n=========================================================");
    }

    while (!scanner.hasNext("q")) {
        //Do nothing unless user presses 'q' to quit.
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Exiting application...bye.");
    }

    System.exit(0);

}