Example usage for java.util Scanner nextInt

List of usage examples for java.util Scanner nextInt

Introduction

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

Prototype

public int nextInt() 

Source Link

Document

Scans the next token of the input as an int .

Usage

From source file:br.edu.ifes.bd2hibernate.cgt.Menu.java

public void load() {
    Scanner menuEntrada = new Scanner(System.in);
    int menu = -1;
    while (menu != 0) {
        System.out.println("\n\n1 - Cadastrar Jogador");
        System.out.println("2 - Cadastrar Time");
        System.out.println("3 - Listar Times");
        System.out.println("4 - Listar Jogadores");
        System.out.println("5 - Buscar Jogador");
        System.out.println("6 - Buscar Time");
        System.out.println("7 - Buscar Jogadores do Time");
        System.out.println("8 - Popular Banco");
        System.out.println("0 - Sair");

        menu = menuEntrada.nextInt();
        switch (menu) {
        case 1://from   w  ww . j  a  v  a  2  s  .c  om
            cadastrarJogador(lerJogador());
            imprimeMensagem("Jogador", "inserir");
            break;
        case 2:
            cadastrarTime(lerTime());
            imprimeMensagem("Time", "inserir");
            break;
        case 3:
            listar(buscarTodosTimes());
            break;
        case 4:
            listar(buscarTodosJogadores());
            break;
        case 5:
            System.out.println(new Jogador().selecionar(lerInt()));
            break;
        case 6:
            System.out.println(new Time().selecionar(lerInt()));
            break;
        case 7:
            listarJogadoresDoTime();
            break;
        case 8:
            popularBanco();
            break;
        case 0:
            HibernateUtil.shutdown();
            return;
        }
    }
}

From source file:org.forgerock.openidm.shell.impl.RemoteCommandScope.java

/**
 * Generate connector configuration./* w w w.  j  av  a  2  s. co  m*/
 *
 * @param session the command session
 * @param userPass the username/password
 * @param idmUrl the url of the OpenIDM instance
 * @param idmPort the OpenIDM instance's port
 * @param name the connector name
 */
@Descriptor("Generate connector configuration.")
public void configureconnector(CommandSession session,

        @Descriptor(USER_PASS_DESC) @MetaVar(USER_PASS_METAVAR) @Parameter(names = { "-u",
                "--user" }, absentValue = USER_PASS_DEFAULT) final String userPass,

        @Descriptor(IDM_URL_DESC) @MetaVar(IDM_URL_METAVAR) @Parameter(names = {
                "--url" }, absentValue = IDM_URL_DEFAULT) final String idmUrl,

        @Descriptor(IDM_PORT_DESC) @MetaVar(IDM_PORT_METAVAR) @Parameter(names = { "-P",
                "--port" }, absentValue = IDM_PORT_DEFAULT) final String idmPort,

        @Descriptor("Name of the new connector configuration.") @MetaVar("CONNECTOR") @Parameter(names = { "-n",
                "--name" }, absentValue = "test") String name) {
    processOptions(userPass, idmUrl, idmPort);

    try {
        // Prepare temp folder and file
        File temp = IdentityServer.getFileForPath("temp");
        if (!temp.exists()) {
            temp.mkdir();
        }
        // TODO Make safe file name

        if (StringUtils.isBlank(name) || !name.matches("\\w++")) {
            session.getConsole().append("The given name \"").append(name)
                    .println("\" must match [a-zA-Z_0-9] pattern");
            return;
        }

        File finalConfig = new File(temp, "provisioner.openicf-" + name + ".json");

        // Common request attributes
        ActionRequest request = Requests.newActionRequest("system", "CREATECONFIGURATION");

        JsonValue responseValue;
        Map<String, Object> configuration = null;

        // Phase#1 - Get available connectors
        if (!finalConfig.exists()) {
            responseValue = resource.action(null, request).getJsonContent();

            JsonValue connectorRef = responseValue.get("connectorRef");
            if (!connectorRef.isNull() && connectorRef.isList()) {
                int i = 0;
                for (JsonValue connector : connectorRef) {
                    String displayName = connector.get("displayName").asString();
                    if (null == displayName) {
                        displayName = connector.get("connectorName").asString();
                    }
                    String version = connector.get("bundleVersion").asString();
                    String connectorHostRef = connector.get("connectorHostRef").asString();

                    session.getConsole().append(Integer.toString(i)).append(". ").append(displayName);
                    if (null != connectorHostRef) {
                        session.getConsole().append(" Remote (").append(connectorHostRef).append(")");
                    }
                    session.getConsole().append(" version ").println(version);
                    i++;
                }

                session.getConsole().append(Integer.toString(connectorRef.size())).println(". Exit");
                Scanner input = new Scanner(session.getKeyboard());
                int index = -1;
                do {
                    session.getConsole().append("Select [0..").append(Integer.toString(connectorRef.size()))
                            .append("]: ");
                    index = input.nextInt();
                } while (index < 0 || index > connectorRef.size());
                if (index == connectorRef.size()) {
                    return;
                }
                configuration = responseValue.asMap();

                // If we don't getObject() JsonValue will wrap the object resulting in a JSON payload of
                // { "connectorRef": { ..., "wrappedObject": ... }
                configuration.put("connectorRef", connectorRef.get(index).getObject());
            } else {
                session.getConsole().println("There are no available connector!");
            }
        } else {
            configuration = new JsonValue(mapper.readValue(finalConfig, Map.class)).asMap();
            session.getConsole().append("Configuration was found and read from: ")
                    .println(finalConfig.getAbsolutePath());
        }

        if (null == configuration) {
            return;
        }

        // Repeatable phase #2 and #3
        request.setContent(new JsonValue(configuration));
        responseValue = resource.action(null, request).getJsonContent();

        configuration = responseValue.asMap();
        configuration.put("name", name);

        mapper.writerWithDefaultPrettyPrinter().writeValue(finalConfig, configuration);

        session.getConsole().append(
                "Edit the configuration file and run the command again. The configuration was saved to ")
                .println(finalConfig.getAbsolutePath());

    } catch (ResourceException e) {
        session.getConsole().append("Remote operation failed: ").println(e.getMessage());
    } catch (Exception e) {
        session.getConsole().append("Operation failed: ").println(e.getMessage());
    }
}

From source file:juicebox.windowui.QCDialog.java

public QCDialog(MainWindow mainWindow, HiC hic, String title) {
    super(mainWindow);

    Dataset dataset = hic.getDataset();/*from   w w w . j a  va  2 s . c  o m*/

    String text = dataset.getStatistics();
    String textDescription = null;
    String textStatistics = null;
    String graphs = dataset.getGraphs();
    JTextPane description = null;
    JTabbedPane tabbedPane = new JTabbedPane();
    HTMLEditorKit kit = new HTMLEditorKit();

    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("table { border-collapse: collapse;}");
    styleSheet.addRule("body {font-family: Sans-Serif; font-size: 12;}");
    styleSheet.addRule("td { padding: 2px; }");
    styleSheet.addRule(
            "th {border-bottom: 1px solid #000; text-align: left; background-color: #D8D8D8; font-weight: normal;}");

    if (text != null) {
        int split = text.indexOf("</table>") + 8;
        textDescription = text.substring(0, split);
        textStatistics = text.substring(split);
        description = new JTextPane();
        description.setEditable(false);
        description.setContentType("text/html");
        description.setEditorKit(kit);
        description.setText(textDescription);
        tabbedPane.addTab("About Library", description);

        JTextPane textPane = new JTextPane();
        textPane.setEditable(false);
        textPane.setContentType("text/html");

        textPane.setEditorKit(kit);
        textPane.setText(textStatistics);
        JScrollPane pane = new JScrollPane(textPane);
        tabbedPane.addTab("Statistics", pane);
    }
    boolean success = true;
    if (graphs != null) {

        long[] A = new long[2000];
        long sumA = 0;
        long[] mapq1 = new long[201];
        long[] mapq2 = new long[201];
        long[] mapq3 = new long[201];
        long[] intraCount = new long[100];
        final XYSeries intra = new XYSeries("Intra Count");
        final XYSeries leftRead = new XYSeries("Left");
        final XYSeries rightRead = new XYSeries("Right");
        final XYSeries innerRead = new XYSeries("Inner");
        final XYSeries outerRead = new XYSeries("Outer");
        final XYSeries allMapq = new XYSeries("All MapQ");
        final XYSeries intraMapq = new XYSeries("Intra MapQ");
        final XYSeries interMapq = new XYSeries("Inter MapQ");

        Scanner scanner = new Scanner(graphs);
        try {
            while (!scanner.next().equals("["))
                ;

            for (int idx = 0; idx < 2000; idx++) {
                A[idx] = scanner.nextLong();
                sumA += A[idx];
            }

            while (!scanner.next().equals("["))
                ;
            for (int idx = 0; idx < 201; idx++) {
                mapq1[idx] = scanner.nextInt();
                mapq2[idx] = scanner.nextInt();
                mapq3[idx] = scanner.nextInt();

            }

            for (int idx = 199; idx >= 0; idx--) {
                mapq1[idx] = mapq1[idx] + mapq1[idx + 1];
                mapq2[idx] = mapq2[idx] + mapq2[idx + 1];
                mapq3[idx] = mapq3[idx] + mapq3[idx + 1];
                allMapq.add(idx, mapq1[idx]);
                intraMapq.add(idx, mapq2[idx]);
                interMapq.add(idx, mapq3[idx]);
            }
            while (!scanner.next().equals("["))
                ;
            for (int idx = 0; idx < 100; idx++) {
                int tmp = scanner.nextInt();
                if (tmp != 0)
                    innerRead.add(logXAxis[idx], tmp);
                intraCount[idx] = tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    outerRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    rightRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    leftRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                if (idx > 0)
                    intraCount[idx] += intraCount[idx - 1];
                if (intraCount[idx] != 0)
                    intra.add(logXAxis[idx], intraCount[idx]);
            }
        } catch (NoSuchElementException exception) {
            JOptionPane.showMessageDialog(getParent(), "Graphing file improperly formatted", "Error",
                    JOptionPane.ERROR_MESSAGE);
            success = false;
        }

        if (success) {
            final XYSeriesCollection readTypeCollection = new XYSeriesCollection();
            readTypeCollection.addSeries(innerRead);
            readTypeCollection.addSeries(outerRead);
            readTypeCollection.addSeries(leftRead);
            readTypeCollection.addSeries(rightRead);

            final JFreeChart readTypeChart = ChartFactory.createXYLineChart("Types of reads vs distance", // chart title
                    "Distance (log)", // domain axis label
                    "Binned Reads (log)", // range axis label
                    readTypeCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot readTypePlot = readTypeChart.getXYPlot();

            readTypePlot.setDomainAxis(new LogarithmicAxis("Distance (log)"));
            readTypePlot.setRangeAxis(new LogarithmicAxis("Binned Reads (log)"));
            readTypePlot.setBackgroundPaint(Color.white);
            readTypePlot.setRangeGridlinePaint(Color.lightGray);
            readTypePlot.setDomainGridlinePaint(Color.lightGray);
            readTypeChart.setBackgroundPaint(Color.white);
            readTypePlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel = new ChartPanel(readTypeChart);

            final XYSeriesCollection reCollection = new XYSeriesCollection();
            final XYSeries reDistance = new XYSeries("Distance");

            for (int i = 0; i < A.length; i++) {
                if (A[i] != 0)
                    reDistance.add(i, A[i] / (float) sumA);
            }
            reCollection.addSeries(reDistance);

            final JFreeChart reChart = ChartFactory.createXYLineChart(
                    "Distance from closest restriction enzyme site", // chart title
                    "Distance (bp)", // domain axis label
                    "Fraction of Reads (log)", // range axis label
                    reCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot rePlot = reChart.getXYPlot();
            rePlot.setDomainAxis(new NumberAxis("Distance (bp)"));
            rePlot.setRangeAxis(new LogarithmicAxis("Fraction of Reads (log)"));
            rePlot.setBackgroundPaint(Color.white);
            rePlot.setRangeGridlinePaint(Color.lightGray);
            rePlot.setDomainGridlinePaint(Color.lightGray);
            reChart.setBackgroundPaint(Color.white);
            rePlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel2 = new ChartPanel(reChart);

            final XYSeriesCollection intraCollection = new XYSeriesCollection();

            intraCollection.addSeries(intra);

            final JFreeChart intraChart = ChartFactory.createXYLineChart("Intra reads vs distance", // chart title
                    "Distance (log)", // domain axis label
                    "Cumulative Sum of Binned Reads (log)", // range axis label
                    intraCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot intraPlot = intraChart.getXYPlot();
            intraPlot.setDomainAxis(new LogarithmicAxis("Distance (log)"));
            intraPlot.setRangeAxis(new NumberAxis("Cumulative Sum of Binned Reads (log)"));
            intraPlot.setBackgroundPaint(Color.white);
            intraPlot.setRangeGridlinePaint(Color.lightGray);
            intraPlot.setDomainGridlinePaint(Color.lightGray);
            intraChart.setBackgroundPaint(Color.white);
            intraPlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel3 = new ChartPanel(intraChart);

            final XYSeriesCollection mapqCollection = new XYSeriesCollection();
            mapqCollection.addSeries(allMapq);
            mapqCollection.addSeries(intraMapq);
            mapqCollection.addSeries(interMapq);

            final JFreeChart mapqChart = ChartFactory.createXYLineChart("MapQ Threshold Count", // chart title
                    "MapQ threshold", // domain axis label
                    "Count", // range axis label
                    mapqCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // include tooltips
                    false);

            final XYPlot mapqPlot = mapqChart.getXYPlot();
            mapqPlot.setBackgroundPaint(Color.white);
            mapqPlot.setRangeGridlinePaint(Color.lightGray);
            mapqPlot.setDomainGridlinePaint(Color.lightGray);
            mapqChart.setBackgroundPaint(Color.white);
            mapqPlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel4 = new ChartPanel(mapqChart);

            tabbedPane.addTab("Pair Type", chartPanel);
            tabbedPane.addTab("Restriction", chartPanel2);
            tabbedPane.addTab("Intra vs Distance", chartPanel3);
            tabbedPane.addTab("MapQ", chartPanel4);
        }
    }

    final ExpectedValueFunction df = hic.getDataset().getExpectedValues(hic.getZoom(),
            hic.getNormalizationType());
    if (df != null) {
        double[] expected = df.getExpectedValues();
        final XYSeriesCollection collection = new XYSeriesCollection();
        final XYSeries expectedValues = new XYSeries("Expected");
        for (int i = 0; i < expected.length; i++) {
            if (expected[i] > 0)
                expectedValues.add(i + 1, expected[i]);
        }
        collection.addSeries(expectedValues);
        String title1 = "Expected at " + hic.getZoom() + " norm " + hic.getNormalizationType();
        final JFreeChart readTypeChart = ChartFactory.createXYLineChart(title1, // chart title
                "Distance between reads (log)", // domain axis label
                "Genome-wide expected (log)", // range axis label
                collection, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, false);
        final XYPlot readTypePlot = readTypeChart.getXYPlot();

        readTypePlot.setDomainAxis(new LogarithmicAxis("Distance between reads (log)"));
        readTypePlot.setRangeAxis(new LogarithmicAxis("Genome-wide expected (log)"));
        readTypePlot.setBackgroundPaint(Color.white);
        readTypePlot.setRangeGridlinePaint(Color.lightGray);
        readTypePlot.setDomainGridlinePaint(Color.lightGray);
        readTypeChart.setBackgroundPaint(Color.white);
        readTypePlot.setOutlinePaint(Color.black);
        final ChartPanel chartPanel5 = new ChartPanel(readTypeChart);

        tabbedPane.addTab("Expected", chartPanel5);
    }

    if (text == null && graphs == null) {
        JOptionPane.showMessageDialog(this, "Sorry, no metrics are available for this dataset", "Error",
                JOptionPane.ERROR_MESSAGE);
        setVisible(false);
        dispose();

    } else {
        getContentPane().add(tabbedPane);
        pack();
        setModal(false);
        setLocation(100, 100);
        setTitle(title);
        setVisible(true);
    }
}

From source file:br.edu.ifes.bd2hibernate.cgt.Menu.java

private Object scanSpecific(String fieldName, Scanner sc, Class c) throws NoSuchFieldException {

    Field field = c.getDeclaredField(fieldName);
    boolean valid = false;
    Object value = null;// w  w w  . j  a v a2 s. co  m

    while (!valid) {
        System.out.println(this.messages.get(fieldName.toUpperCase()));
        String type = field.getType().getSimpleName();

        switch (type.toUpperCase()) {
        case "STRING":
            value = sc.nextLine();
            valid = true;
            break;
        case "DATE":
            String date = sc.nextLine();
            valid = this.dateValidator.validate(date);
            if (valid)
                value = convertStringToDate(date);
            break;
        case "INT":
            value = sc.nextInt();
            valid = true;
            break;
        case "FLOAT":
            value = sc.nextFloat();
            valid = true;
            break;
        }
    }

    return value;
}

From source file:com.tesora.dve.tools.CLIBuilder.java

protected Integer scanInteger(Scanner scanner, String exists) throws PEException {
    if (hasRequiredArg(scanner, exists)) {
        try {/*from  ww  w . j  a  v a 2  s .  c  om*/
            return scanner.nextInt();
        } catch (final Exception e) {
            throw new PEException("Failed to parse integer parameter", e);
        }
    }

    return null;
}

From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMClusters.java

/**
 * Load the histogram from the file. Assumes the histogram is [int, float] format and creates a contiguous histogram
 * from zero/*from  w w w  . j a va2s .c o  m*/
 * 
 * @param filename
 * @return
 */
private HistogramData loadHistogram(String filename) {
    BufferedReader input = null;
    try {
        int f = 0;
        double a = 0;
        String u = "";

        FileInputStream fis = new FileInputStream(filename);
        input = new BufferedReader(new UnicodeReader(fis, null));

        String line;
        int count = 0;

        ArrayList<float[]> data = new ArrayList<float[]>();

        // Read the header and store the calibration if present
        while ((line = input.readLine()) != null) {
            count++;
            if (line.length() == 0)
                continue;
            if (Character.isDigit(line.charAt(0)))
                // This is the first record
                break;
            String[] fields = line.split("[\t, ]+");
            if (fields[0].equalsIgnoreCase("frames"))
                f = Integer.parseInt(fields[1]);
            if (fields[0].equalsIgnoreCase("area"))
                a = Double.parseDouble(fields[1]);
            if (fields[0].equalsIgnoreCase("units"))
                u = fields[1];
        }

        final Pattern pattern = Pattern.compile("[\t, ]+");
        while (line != null) {
            if (line.length() == 0)
                continue;
            if (!Character.isDigit(line.charAt(0)))
                continue;

            // Extract the first 2 fields
            Scanner scanner = new Scanner(line);
            scanner.useLocale(Locale.US);
            scanner.useDelimiter(pattern);

            try {
                int molecules = scanner.nextInt();
                float frequency = scanner.nextFloat();

                // Check for duplicates
                for (float[] d : data) {
                    if (d[0] == molecules) {
                        error("Duplicate molecules field on line " + count);
                        return null;
                    }
                }

                data.add(new float[] { molecules, frequency });
            } catch (InputMismatchException e) {
                error("Incorrect fields on line " + count);
                return null;
            } catch (NoSuchElementException e) {
                error("Incorrect fields on line " + count);
                return null;
            } finally {
                scanner.close();
            }

            // Get the next line
            line = input.readLine();
            count++;
        }

        if (data.isEmpty()) {
            error("No data in file " + filename);
            return null;
        }

        // Create a contiguous histogram from zero
        int maxN = 0;
        for (float[] d : data) {
            if (maxN < d[0])
                maxN = (int) d[0];
        }

        float[][] hist = new float[2][maxN + 1];
        for (int n = 0; n <= maxN; n++) {
            hist[0][n] = n;
            for (float[] d : data) {
                if (n == d[0])
                    hist[1][n] = d[1];
            }
        }
        HistogramData histogramData = new HistogramData(hist, f, a, u);
        histogramData.filename = filename;
        return histogramData;
    } catch (IOException e) {
        IJ.error(TITLE, "Unable to read from file " + filename);
    } finally {
        try {
            if (input != null)
                input.close();
        } catch (IOException e) {
            // Ignore
        }
    }
    return null;
}

From source file:br.edu.ifes.bd2dao.cgt.Menu.java

public void load() {
    Scanner menuEntrada = new Scanner(System.in);
    int menu = -1;
    while (menu != 0) {
        System.out.println("1 - Cadastrar Aluno");
        System.out.println("2 - Atualizar Aluno");
        System.out.println("3 - Deletar Aluno");
        System.out.println("4 - Buscar alunos matriculados");
        System.out.println("5 - Listar todos os alunos");
        System.out.println("6 - Cadastrar Disciplina");
        System.out.println("7 - Listar Disciplinas");
        System.out.println("8 - Buscar Disciplina");
        System.out.println("9 - Disciplinas de um aluno");
        System.out.println("10 - Popular Banco");
        System.out.println("0 - Sair");
        menu = menuEntrada.nextInt();
        switch (menu) {
        case 1://from   w ww .  j ava 2s .  c o  m
            new Aluno().inserir(lerAluno());
            imprimeMensagem("Aluno", "inserir");
            break;
        case 2:
            atualizarAluno();
            imprimeMensagem("Aluno", "atualizar");
            break;
        case 3:
            deletarAluno();
            imprimeMensagem("Aluno", "deletar");
            break;
        case 4:
            listarMatriculados();
            break;
        case 5:
            listarAlunos();
            break;
        case 6:
            new Disciplina().inserir(lerDisciplina());
            imprimeMensagem("Disciplina", "inserir");
            break;
        case 7:
            listar(buscarDisciplinas());
            break;
        case 8:
            System.out.println(selecionarDisciplina());
        case 9:
            listarDisciplinasDeUmAluno();
            break;
        case 10:
            popularBanco();
        }
    }
}

From source file:edu.umd.cs.buildServer.BuildServer.java

public boolean alreadyRunning() throws Exception {
    int oldPid = getPidFileContents(false);
    if (oldPid < 0)
        return false;
    ProcessBuilder b = new ProcessBuilder(
            new String[] { "/bin/ps", "xww", "-o", "pid,lstart,user,state,pcpu,cputime,args" });
    String user = System.getProperty("user.name");

    Process p = b.start();//w  w w . java  2  s . c  o  m
    try {
        Scanner s = new Scanner(p.getInputStream());
        String header = s.nextLine();
        // log.trace("ps header: " + header);
        while (s.hasNext()) {
            String txt = s.nextLine();
            if (!txt.contains(user))
                continue;

            int pid = Integer.parseInt(txt.substring(0, 5).trim());
            if (pid == oldPid) {
                if (!isQuiet()) {
                    System.out.println("BuildServer is already running");
                    System.out.println(txt);
                }
                return true;
            }
        }
        s.close();
    } finally {
        p.destroy();
    }
    long pidLastModified = getPidFile().lastModified();
    String msg = "Previous buildserver pid " + oldPid + " died; had started at " + new Date(pidLastModified);

    System.out.println(msg);
    File currentFile = getCurrentFile();
    long currentFileLastModified = currentFile.lastModified();
    if (currentFile.exists() && currentFileLastModified >= pidLastModified) {
        Scanner scanner = new Scanner(currentFile);
        int submissionPK = scanner.nextInt();
        int testSetupPK = scanner.nextInt();
        scanner.nextLine(); // skip EOL
        String kind = scanner.nextLine().trim();
        String load = scanner.nextLine().trim();
        scanner.close();
        reportBuildServerDeath(submissionPK, testSetupPK, currentFileLastModified, kind, load);
    }
    currentFile.delete();
    getPidFile().delete();
    System.out.println("Deleting old pid file");
    return false;

}

From source file:com.joey.software.MoorFLSI.RepeatImageTextReader.java

public void loadTextDataFluxSingle(File file) {
    try {//from  w  ww .ja v a  2  s. c  o  m
        RandomAccessFile in = new RandomAccessFile(file, "r");

        // Skip header
        in.readLine();
        in.readLine();
        in.readLine();

        // Skip Subject Information
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String startTimeInput = in.readLine();
        String commentsInput = in.readLine();

        String data = in.readLine();
        while (!data.startsWith("2) System Configuration")) {
            commentsInput += data;
            data = in.readLine();
        }
        // System configuration

        // in.readLine();
        in.readLine();
        String timeCounstantInput = in.readLine();
        String cameraGainInput = in.readLine();
        String exposureTimeInput = in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String resolutionInput = in.readLine();

        // in.readLine();
        // System.out.println(in.readLine());
        // in.readLine();

        // Parse important Size

        high = (new Scanner(resolutionInput.split(":")[1])).nextInt();
        wide = (new Scanner(resolutionInput.split(",")[1])).nextInt();
        int tot = 1;
        while (!data.startsWith("3) Flux Image Data")) {
            System.out.println(data);
            data = in.readLine();
        }
        in.readLine();
        // Parse Image Data
        /*
         * Close Random access file and switch to scanner first store pos
         * then move to correct point.
         */
        long pos = in.getFilePointer();
        in.close();

        FileInputStream fIn = new FileInputStream(file);
        fIn.skip(pos);

        BufferedInputStream bIn = new BufferedInputStream(fIn);
        Scanner sIn = new Scanner(bIn);

        short[][] holder = new short[wide][high];

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        StatusBarPanel stat = new StatusBarPanel();
        stat.setMaximum(high);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(stat, BorderLayout.CENTER);
        f.setSize(200, 60);
        f.setVisible(true);

        // Skip over the heading values

        sIn.reset();

        for (int y = 0; y < high; y++) {
            System.out.println(sIn.nextInt());
            try {
                for (int x = 0; x < wide; x++) {
                    holder[x][y] = sIn.nextShort();
                }
            } catch (Throwable e) {

            }

        }
        addData(new Date(), holder);

        FrameFactroy.getFrame(new DynamicRangeImage(holder));
        // Start Image Data

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:br.edu.ifes.bd2dao.cgt.Menu.java

private Object scanSpecific(String fieldName, Scanner sc, Class c) throws NoSuchFieldException {

    Field field = c.getDeclaredField(fieldName);
    boolean valid = false;
    Object value = null;//  ww w  .  j  ava2 s.c  o m

    while (!valid) {
        System.out.println(this.messages.get(fieldName.toUpperCase()));
        String type = field.getType().getSimpleName();

        switch (type.toUpperCase()) {
        case "STRING":
            value = sc.nextLine();
            valid = true;
            break;
        case "GENERO":
            String genero = sc.nextLine().toUpperCase();
            valid = Genero.exists(genero);
            if (valid)
                value = Genero.valueOf(genero);
            break;
        case "CALENDAR":
            String date = sc.nextLine();
            valid = this.dateValidator.validate(date);
            if (valid)
                value = convertStringToCalendar(date);
            break;
        case "INT":
            value = sc.nextInt();
            valid = true;
            break;
        }
    }

    return value;
}