Example usage for java.util Scanner nextLine

List of usage examples for java.util Scanner nextLine

Introduction

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

Prototype

public String nextLine() 

Source Link

Document

Advances this scanner past the current line and returns the input that was skipped.

Usage

From source file:com.joliciel.talismane.fr.TalismaneFrench.java

/**
 * @param args//from  ww  w  .  j  av a2s .  c  o m
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    Map<String, String> argsMap = TalismaneConfig.convertArgs(args);
    CorpusFormat corpusReaderType = null;
    String treebankDirPath = null;
    boolean keepCompoundPosTags = true;

    if (argsMap.containsKey("corpusReader")) {
        corpusReaderType = CorpusFormat.valueOf(argsMap.get("corpusReader"));
        argsMap.remove("corpusReader");
    }
    if (argsMap.containsKey("treebankDir")) {
        treebankDirPath = argsMap.get("treebankDir");
        argsMap.remove("treebankDir");
    }
    if (argsMap.containsKey("keepCompoundPosTags")) {
        keepCompoundPosTags = argsMap.get("keepCompoundPosTags").equalsIgnoreCase("true");
        argsMap.remove("keepCompoundPosTags");
    }

    Extensions extensions = new Extensions();
    extensions.pluckParameters(argsMap);

    TalismaneFrench talismaneFrench = new TalismaneFrench();

    TalismaneConfig config = new TalismaneConfig(argsMap, talismaneFrench);
    if (config.getCommand() == null)
        return;

    if (corpusReaderType != null) {
        if (corpusReaderType == CorpusFormat.ftbDep) {
            File inputFile = new File(config.getInFilePath());
            FtbDepReader ftbDepReader = new FtbDepReader(inputFile, config.getInputCharset());

            ftbDepReader.setKeepCompoundPosTags(keepCompoundPosTags);
            ftbDepReader.setPredictTransitions(config.isPredictTransitions());

            config.setParserCorpusReader(ftbDepReader);
            config.setPosTagCorpusReader(ftbDepReader);
            config.setTokenCorpusReader(ftbDepReader);

            if (config.getCommand().equals(Command.compare)) {
                File evaluationFile = new File(config.getEvaluationFilePath());
                FtbDepReader ftbDepEvaluationReader = new FtbDepReader(evaluationFile,
                        config.getInputCharset());
                ftbDepEvaluationReader.setKeepCompoundPosTags(keepCompoundPosTags);
                config.setParserEvaluationCorpusReader(ftbDepEvaluationReader);
                config.setPosTagEvaluationCorpusReader(ftbDepEvaluationReader);
            }
        } else if (corpusReaderType == CorpusFormat.ftb) {
            TalismaneServiceLocator talismaneServiceLocator = TalismaneServiceLocator.getInstance();
            TreebankServiceLocator treebankServiceLocator = TreebankServiceLocator
                    .getInstance(talismaneServiceLocator);
            TreebankUploadService treebankUploadService = treebankServiceLocator
                    .getTreebankUploadServiceLocator().getTreebankUploadService();
            TreebankExportService treebankExportService = treebankServiceLocator
                    .getTreebankExportServiceLocator().getTreebankExportService();
            File treebankFile = new File(treebankDirPath);
            TreebankReader treebankReader = treebankUploadService.getXmlReader(treebankFile);

            // we prepare both the tokeniser and pos-tag readers, just in case they are needed
            InputStream posTagMapStream = talismaneFrench.getDefaultPosTagMapFromStream();
            Scanner scanner = new Scanner(posTagMapStream, "UTF-8");
            List<String> descriptors = new ArrayList<String>();
            while (scanner.hasNextLine())
                descriptors.add(scanner.nextLine());
            FtbPosTagMapper ftbPosTagMapper = treebankExportService.getFtbPosTagMapper(descriptors,
                    talismaneFrench.getDefaultPosTagSet());
            PosTagAnnotatedCorpusReader posTagAnnotatedCorpusReader = treebankExportService
                    .getPosTagAnnotatedCorpusReader(treebankReader, ftbPosTagMapper, keepCompoundPosTags);
            config.setPosTagCorpusReader(posTagAnnotatedCorpusReader);

            TokeniserAnnotatedCorpusReader tokenCorpusReader = treebankExportService
                    .getTokeniserAnnotatedCorpusReader(treebankReader, ftbPosTagMapper, keepCompoundPosTags);
            config.setTokenCorpusReader(tokenCorpusReader);

            SentenceDetectorAnnotatedCorpusReader sentenceCorpusReader = treebankExportService
                    .getSentenceDetectorAnnotatedCorpusReader(treebankReader);
            config.setSentenceCorpusReader(sentenceCorpusReader);
        } else if (corpusReaderType == CorpusFormat.conll || corpusReaderType == CorpusFormat.spmrl) {
            File inputFile = new File(config.getInFilePath());

            ParserRegexBasedCorpusReader corpusReader = config.getParserService()
                    .getRegexBasedCorpusReader(inputFile, config.getInputCharset());

            corpusReader.setPredictTransitions(config.isPredictTransitions());

            config.setParserCorpusReader(corpusReader);
            config.setPosTagCorpusReader(corpusReader);
            config.setTokenCorpusReader(corpusReader);

            if (corpusReaderType == CorpusFormat.spmrl) {
                corpusReader.setRegex(
                        "%INDEX%\\t%TOKEN%\\t.*\\t.*\\t%POSTAG%\\t.*\\t.*\\t.*\\t%GOVERNOR%\\t%LABEL%");
            }

            if (config.getCommand().equals(Command.compare)) {
                File evaluationFile = new File(config.getEvaluationFilePath());
                ParserRegexBasedCorpusReader evaluationReader = config.getParserService()
                        .getRegexBasedCorpusReader(evaluationFile, config.getInputCharset());
                config.setParserEvaluationCorpusReader(evaluationReader);
                config.setPosTagEvaluationCorpusReader(evaluationReader);
            }
        } else {
            throw new TalismaneException("Unknown corpusReader: " + corpusReaderType);
        }
    }
    Talismane talismane = config.getTalismane();

    extensions.prepareCommand(config, talismane);

    talismane.process();
}

From source file:Graph_with_jframe_and_arduino.java

public static void main(String[] args) {

    // create and configure the window
    JFrame window = new JFrame();
    window.setTitle("Sensor Graph GUI");
    window.setSize(600, 400);/* w w w . jav a2  s  .  c o  m*/
    window.setLayout(new BorderLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a drop-down box and connect button, then place them at the top of the window
    JComboBox<String> portList_combobox = new JComboBox<String>();
    Dimension d = new Dimension(300, 100);
    portList_combobox.setSize(d);
    JButton connectButton = new JButton("Connect");
    JPanel topPanel = new JPanel();
    topPanel.add(portList_combobox);
    topPanel.add(connectButton);
    window.add(topPanel, BorderLayout.NORTH);
    //pause button
    JButton Pause_btn = new JButton("Start");

    // populate the drop-down box
    SerialPort[] portNames;
    portNames = SerialPort.getCommPorts();
    //check for new port available
    Thread thread_port = new Thread() {
        @Override
        public void run() {
            while (true) {
                SerialPort[] sp = SerialPort.getCommPorts();
                if (sp.length > 0) {
                    for (SerialPort sp_name : sp) {
                        int l = portList_combobox.getItemCount(), i;
                        for (i = 0; i < l; i++) {
                            //check port name already exist or not
                            if (sp_name.getSystemPortName().equalsIgnoreCase(portList_combobox.getItemAt(i))) {
                                break;
                            }
                        }
                        if (i == l) {
                            portList_combobox.addItem(sp_name.getSystemPortName());
                        }

                    }

                } else {
                    portList_combobox.removeAllItems();

                }
                portList_combobox.repaint();

            }

        }

    };
    thread_port.start();
    for (SerialPort sp_name : portNames)
        portList_combobox.addItem(sp_name.getSystemPortName());

    //for(int i = 0; i < portNames.length; i++)
    //   portList.addItem(portNames[i].getSystemPortName());

    // create the line graph
    XYSeries series = new XYSeries("line 1");
    XYSeries series2 = new XYSeries("line 2");
    XYSeries series3 = new XYSeries("line 3");
    XYSeries series4 = new XYSeries("line 4");
    for (int i = 0; i < 100; i++) {
        series.add(x, 0);
        series2.add(x, 0);
        series3.add(x, 0);
        series4.add(x, 10);
        x++;
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(series2);
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series3);
    dataset2.addSeries(series4);

    //create jfree chart
    JFreeChart chart = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading",
            dataset);
    JFreeChart chart2 = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading 2",
            dataset2);

    //color render for chart 1
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    r1.setSeriesPaint(0, Color.RED);
    r1.setSeriesPaint(1, Color.GREEN);
    r1.setSeriesShapesVisible(0, false);
    r1.setSeriesShapesVisible(1, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(0, r1);
    plot.setRenderer(1, r1);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.blue);

    //color render for chart 2
    XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer();
    r2.setSeriesPaint(0, Color.BLUE);
    r2.setSeriesPaint(1, Color.ORANGE);
    r2.setSeriesShapesVisible(0, false);
    r2.setSeriesShapesVisible(1, false);

    XYPlot plot2 = chart2.getXYPlot();
    plot2.setRenderer(0, r2);
    plot2.setRenderer(1, r2);

    ChartPanel cp = new ChartPanel(chart);
    ChartPanel cp2 = new ChartPanel(chart2);

    //multiple graph container
    JPanel graph_container = new JPanel();
    graph_container.setLayout(new BoxLayout(graph_container, BoxLayout.X_AXIS));
    graph_container.add(cp);
    graph_container.add(cp2);

    //add chart panel in main window
    window.add(graph_container, BorderLayout.CENTER);
    //window.add(cp2, BorderLayout.WEST);

    window.add(Pause_btn, BorderLayout.AFTER_LAST_LINE);
    Pause_btn.setEnabled(false);
    //pause btn action
    Pause_btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Pause_btn.getText().equalsIgnoreCase("Pause")) {

                if (chosenPort.isOpen()) {
                    try {
                        Output.write(0);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Start");
            } else {
                if (chosenPort.isOpen()) {
                    try {
                        Output.write(1);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Pause");
            }
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // configure the connect button and use another thread to listen for data
    connectButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (connectButton.getText().equals("Connect")) {
                // attempt to connect to the serial port
                chosenPort = SerialPort.getCommPort(portList_combobox.getSelectedItem().toString());
                chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                if (chosenPort.openPort()) {
                    Output = chosenPort.getOutputStream();
                    connectButton.setText("Disconnect");
                    Pause_btn.setEnabled(true);
                    portList_combobox.setEnabled(false);
                }

                // create a new thread that listens for incoming text and populates the graph
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        Scanner scanner = new Scanner(chosenPort.getInputStream());
                        while (scanner.hasNextLine()) {
                            try {
                                String line = scanner.nextLine();
                                int number = Integer.parseInt(line);
                                series.add(x, number);
                                series2.add(x, number / 2);
                                series3.add(x, number / 1.5);
                                series4.add(x, number / 5);

                                if (x > 100) {
                                    series.remove(0);
                                    series2.remove(0);
                                    series3.remove(0);
                                    series4.remove(0);
                                }

                                x++;
                                window.repaint();
                            } catch (Exception e) {
                            }
                        }
                        scanner.close();
                    }
                };
                thread.start();
            } else {
                // disconnect from the serial port
                chosenPort.closePort();
                portList_combobox.setEnabled(true);
                Pause_btn.setEnabled(false);
                connectButton.setText("Connect");

            }
        }
    });

    // show the window
    window.setVisible(true);
}

From source file:net.jmhertlein.alphonseirc.MSTDeskEngRunner.java

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    loadConfig();//from   w w  w .  ja va 2 s. c o  m

    AlphonseBot bot = new AlphonseBot(nick, pass, server, channels, maxXKCD, noVoiceNicks, masters,
            dadLeaveTimes);
    bot.setMessageDelay(500);
    try {
        bot.startConnection();
    } catch (IOException | IrcException ex) {
        Logger.getLogger(MSTDeskEngRunner.class.getName()).log(Level.SEVERE, null, ex);
    }

    boolean quit = false;
    while (!quit) {
        String curLine = scan.nextLine();

        switch (curLine) {
        case "exit":
            System.out.println("Quitting.");
            bot.onPreQuit();
            bot.disconnect();
            bot.dispose();
            writeConfig();
            quit = true;
            System.out.println("Quit'd.");
            break;
        case "msg":
            Scanner lineScan = new Scanner(scan.nextLine());
            try {
                bot.sendMessage(lineScan.next(), lineScan.nextLine());
            } catch (Exception e) {
                System.err.println(e.getClass().toString());
                System.err.println("Not enough args");
            }
            break;
        default:
            System.out.println("Invalid command.");
        }
    }
}

From source file:com.lv.tica.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/* ww w.  j ava2 s.  c  om*/
 */
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();

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

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

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

    System.out.print("Please enter a string and press <enter>: ");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

        try {

            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));

        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

        System.out.print("Please enter a string and press <enter>:");

    }

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

    System.exit(0);

}

From source file:in.datashow.zla.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from w  ww .  j a va 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();

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

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

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

    System.out.print("Please enter a string and press <enter>: ");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

        try {

            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));

        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

        System.out.print("Please enter a string and press <enter>:");

    }

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

    System.exit(0);

}

From source file:com.hillert.spring.validation.Main.java

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

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n          Welcome!                                       "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://blog.hillert.com                              "
            + "\n                                                         "
            + "\n=========================================================");

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

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in).useDelimiter("\n");

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

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

    System.out.println("Please enter a string and press <enter>: ");

    while (true) {

        System.out.print("$ ");
        String input = scanner.nextLine();

        LOGGER.debug("Input string: '{}'", input);

        if ("q".equalsIgnoreCase(input)) {
            break;
        } else if ("null".equals(input)) {
            input = null;
        }

        try {
            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));
        } catch (MethodConstraintViolationException e) {
            Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
            LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size());

            for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) {
                LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor());
            }

        }
    }

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

    System.exit(0);

}

From source file:com.somnus.spring.validation.Main.java

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

    LOGGER.info("\n========================================================="
            + "\n                                                         "
            + "\n          Welcome!                                       "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://blog.hillert.com                              "
            + "\n                                                         "
            + "\n=========================================================");

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

    context.registerShutdownHook();

    final Scanner scanner = new Scanner(System.in).useDelimiter("\n");

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

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

    System.out.println("Please enter a string and press <enter>: ");

    while (true) {

        System.out.print("$ ");
        String input = scanner.nextLine();

        LOGGER.debug("Input string: '{}'", input);

        if ("q".equalsIgnoreCase(input)) {
            break;
        } else if ("null".equals(input)) {
            input = null;
        }

        try {
            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));
        } catch (MethodConstraintViolationException e) {
            Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
            LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size());

            for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) {
                LOGGER.info("Method Validation: {}", violation.getPropertyPath().toString());
                LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor());
                LOGGER.info("Method Validation: {}", violation.getMessage());
            }

        }
    }

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

    System.exit(0);

}

From source file:com.cjtotten.example.si.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments/*  w ww  . java  2s . c  o 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();

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

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

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

    System.out.print("Please enter a string and press <enter>: ");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        }

        try {

            System.out.println("Converted to upper-case: " + service.convertToUpperCase(input));

        } catch (Exception e) {
            LOGGER.error("An exception was caught: " + e);
        }

        System.out.print("Please enter a string and press <enter>:");

    }

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

    System.exit(0);

}

From source file:org.musa.tcpclients.Main.java

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

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

    //context.getB
    GenericXmlApplicationContext context = Main.setupContext();
    WarpGateway gateway = (WarpGateway) context.getBean("gw");

    System.out.println("running.\n\n");

    System.out.println("Please enter numbers to spawn spacemarines :");
    System.out.println("1: Gabriel Loken");
    System.out.println("2: Nathaniel Garro");
    System.out.println("3: Ezekyl Abaddon");
    System.out.println("4: Sanguinius");
    System.out.println("5: Lucius");

    System.out.println("\t- Entering q will quit the application");
    System.out.print("\n");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        } else {

            SpaceMarine gabriel = new SpaceMarine("Gabriel Loken", "Luna Wolves", 500, SMRank.CaptainBrother,
                    SMLoyalty.Loyalist, 100);
            SpaceMarine garro = new SpaceMarine("Nathaniel Garro", "Deathguard", 500, SMRank.CaptainBrother,
                    SMLoyalty.Loyalist, 100);
            SpaceMarine ezekyl = new SpaceMarine("Ezekyl Abaddon", "Black Legion", 500, SMRank.CaptainBrother,
                    SMLoyalty.Traitor, 100);
            SpaceMarine sanguinius = new SpaceMarine("Sanguinius", "Blood angels", 999, SMRank.Primarch,
                    SMLoyalty.Loyalist, 600);
            SpaceMarine lucius = new SpaceMarine("Lucius", "Emperor's children", 500, SMRank.SwordMaster,
                    SMLoyalty.Traitor, 700);

            SpaceMarine[] spaceMarines = { gabriel, garro, ezekyl, sanguinius, lucius };
            int max_id = spaceMarines.length;

            int num = 0; //input
            try {
                num = Integer.parseInt(input);
            } catch (NumberFormatException e) {
                System.out.println("unable to parse value");
            }
            if (num >= max_id) {
                System.out.println("no such spacemarine, using Loken");
                num = 0;
            }

            System.out.println("teleporting " + spaceMarines[num].getName() + "....");

            Message<SpaceMarine> m = MessageBuilder.withPayload(spaceMarines[num]).build();

            //context.
            String reply = (String) gateway.send(m);
            System.out.println(reply);

        }
    }

    System.out.println("Exiting application...bye.");
    System.exit(0);

}

From source file:io.github.mikesaelim.arxivoaiharvester.CommandLineInterface.java

public static void main(String[] args) throws InterruptedException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    ArxivOAIHarvester harvester = new ArxivOAIHarvester(httpClient);
    Scanner scanner = new Scanner(System.in);

    System.out.println();/*from  w w w .j  av a 2s . co m*/
    System.out.println("Welcome to the command line interface of the arXiv OAI Harvester!");
    System.out.println(
            "This program sends one query to the arXiv OAI repository and prints the results to STDOUT.");
    System.out.println("It uses the default settings for query retries.");
    System.out.println();
    System.out.println("Which verb would you like to use?");
    System.out.println("    1) GetRecord - retrieve a single record");
    System.out.println("    2) ListRecords - retrieve a range of records");
    System.out.println("    or enter anything else to quit.");

    switch (scanner.nextLine().trim()) {
    case "1":
        handleGetRecordRequest(scanner, harvester);
        break;
    case "2":
        handleListRecordsRequest(scanner, harvester);
    }
}