Package java.util

Examples of java.util.Scanner


  {
    System.out.println("\n" + message);
    System.out.println("Press ENTER to continue");
    try
    {
      Scanner in = new Scanner(System.in);
      in.nextLine();
    }
    catch(Exception e)
    {}
  }
View Full Code Here


  /**
   * Tests for name.
   */
  @Test
  public void testname() throws Exception {
    Scanner sc = new Scanner("forging;123").useDelimiter(";");
    assertFalse(sc.hasNextInt());
    assertThat(sc.next(), is("forging"));
    assertTrue(sc.hasNextInt());
    assertThat(sc.next(), is("123"));
   
  }
View Full Code Here

  protected boolean executeBatch(final String commandLine) {
    final File commandFile = new File(commandLine);
    if (commandFile.exists()) {
      try {
        return executeCommands(new Scanner(commandFile).useDelimiter(";"));
      } catch (FileNotFoundException fnfe) {
        return false;
      }
    } else {
      return executeCommands(commandLine);
View Full Code Here

   *            the input URI sting
   * @return a list of file
   */
  public static List<File> textURIListToFileList(String data) {
    List<File> retVal = new java.util.ArrayList<File>(1);
    Scanner scanner = new Scanner(data);
    scanner.useDelimiter(URI_DELIMITER);
    while (scanner.hasNext()) {
      String token = scanner.next();
      if (token != null && !token.startsWith("#")) {
        try {
          File currentFile = new File(new URI(token));
          if (currentFile.exists()) {
            retVal.add(currentFile);
View Full Code Here

    public static List <NameValuePair> parse (final URI uri, final String encoding) {
        List <NameValuePair> result = Collections.emptyList();
        final String query = uri.getRawQuery();
        if (query != null && query.length() > 0) {
            result = new ArrayList <NameValuePair>();
            parse(result, new Scanner(query), encoding);
        }
        return result;
    }
View Full Code Here

        if (isEncoded(entity)) {
            final String content = EntityUtils.toString(entity);
            final Header encoding = entity.getContentEncoding();
            if (content != null && content.length() > 0) {
                result = new ArrayList <NameValuePair>();
                parse(result, new Scanner(content),
                        encoding != null ? encoding.getValue() : null);
            }
        }
        return result;
    }
View Full Code Here

  /* File format has a funny header, then first entry index per column, then the
row for each entry, then the value for each entry.  Indices count from 1.
Assumes A is initialized. */
  SMat svdLoadSparseTextHBFile(File file) throws FileNotFoundException {
    int i, x, rows, cols, vals, num_mat;
    Scanner scanner = new Scanner(file);
    SMat S;
    /* Skip the header line: */
    scanner.nextLine();
    /* Skip the line giving the number of lines in this file: */
    scanner.nextLine();
    /* Read the line with useful dimensions: */
    scanner.next();
    rows = scanner.nextInt();
    cols = scanner.nextInt();
    vals = scanner.nextInt();
    num_mat = scanner.nextInt();
    scanner.nextLine();
    if (num_mat != 0) {
      throw new Error("svdLoadSparseTextHBFile: I don't know how to handle a file "
          + "with elemental matrices (last entry on header line 3)");
    }
    /* Skip the line giving the formats: */
    scanner.nextLine();

    S = new SMat(rows, cols, vals);

    /* Read column pointers. */
    for (i = 0; i <= S.cols; i++) {
      x = scanner.nextInt();
      S.pointr[i] = x - 1;
    }
    S.pointr[S.cols] = S.vals;

    /* Read row indices. */
    for (i = 0; i < S.vals; i++) {
      x = scanner.nextInt();
      S.rowind[i] = x - 1;
    }
    for (i = 0; i < S.vals; i++) {
      S.value[i] = scanner.nextDouble();
    }
    return S;
  }
View Full Code Here

    /* File format has a funny header, then first entry index per column, then the
row for each entry, then the value for each entry.  Indices count from 1.
Assumes A is initialized. */
    static SMat svdLoadSparseTextHBFile(File file) throws FileNotFoundException {
        int i, x, rows, cols, vals, num_mat;
        Scanner scanner = new Scanner(file);
        SMat S;
        /* Skip the header line: */
        scanner.nextLine();
        /* Skip the line giving the number of lines in this file: */
        scanner.nextLine();
        /* Read the line with useful dimensions: */
        scanner.next();
        rows = scanner.nextInt();
        cols = scanner.nextInt();
        vals = scanner.nextInt();
        num_mat = scanner.nextInt();
        scanner.nextLine();
        if (num_mat != 0) {
            throw new Error("svdLoadSparseTextHBFile: I don't know how to handle a file "
                    + "with elemental matrices (last entry on header line 3)");
        }
        /* Skip the line giving the formats: */
        scanner.nextLine();

        S = new SMat(rows, cols, vals);

        /* Read column pointers. */
        for (i = 0; i <= S.cols; i++) {
            x = scanner.nextInt();
            S.pointr[i] = x - 1;
        }
        S.pointr[S.cols] = S.vals;

        /* Read row indices. */
        for (i = 0; i < S.vals; i++) {
            x = scanner.nextInt();
            S.rowind[i] = x - 1;
        }
        for (i = 0; i < S.vals; i++) {
            S.value[i] = scanner.nextDouble();
        }
        return S;
    }
View Full Code Here

    private static Map<String, UnifracSample> readSampleMap(String sampleFile) throws IOException {
        Map<String, UnifracSample> ret = new HashMap();
        Map<String, MCSample> sampleMap = new HashMap();

        int lineno = 1;
        Scanner s = new Scanner(new File(sampleFile)).useDelimiter("\n");
        while (s.hasNext()) {
            String line = s.next().trim();
            if (line.equals("")) {
                continue;
            }

            String[] tokens = line.split("\\s+");
            if (tokens.length < 2) {
                throw new IOException("Failed to parse sample mapping file (lineno=" + lineno + ")");
            }

            String sampleName = tokens[1];
            String seqName = tokens[0];
            int sampleCount = 1;

            try {
                sampleCount = Integer.parseInt(tokens[2]);
            } catch (Exception e) {
            }

            if(!sampleMap.containsKey(sampleName))
                sampleMap.put(sampleName, new MCSample(sampleName));

            UnifracSample unifracSample = new UnifracSample();
            unifracSample.sample = sampleMap.get(sampleName);
            unifracSample.count = sampleCount;

            ret.put(seqName, unifracSample);

            lineno++;
        }
        s.close();

        return ret;
    }
View Full Code Here

public class Graph {

  public static final int NIL = Integer.MAX_VALUE;

  public static Graph parse(String s) {
    Scanner in = new Scanner(s);
    int N = in.nextInt();
    int M = in.nextInt();
    Graph g = new Graph(N);
    for (int m = 0; m < M; m++) {
      int a = in.nextInt() - 1;
      int b = in.nextInt() - 1;
      int c = in.nextInt();
      g.cost[a][b] = c;
      g.cost[b][a] = c;
    }
    return g;
  }
View Full Code Here

TOP

Related Classes of java.util.Scanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.