/** Test Client */
 public static void main(String[] args) {
   Integer N = new Integer(args[0]);
   Integer T = new Integer(args[1]);
   Out out = new Out();
   PercolationStats stats = new PercolationStats(N, T);
   out.println("mean                    = " + stats.mean());
   out.println("stddev                  = " + stats.stddev());
   out.println("95% confidence interval = " + stats.confidenceLo() + ", " + stats.confidenceHi());
   out.close();
 }
  // write the concordance to a file
  private static void serialize(String fileName, ST<String, SET<Integer>> concordance) {
    Out out = new Out(fileName);
    out.println(concordance.size());
    for (String s : concordance.keys()) {
      SET<Integer> set = concordance.get(s);
      if (set == null) set = new SET<Integer>();

      out.println(s);
      out.println(set.size());
      for (int k : set) out.println(k);
    }
    out.close();
  }
Ejemplo n.º 3
0
  // A method for printing out the information
  public static void output(String[] row) {
    // Finds the length of the first element
    int a = row[0].length();

    // Prints out the first element
    out.print(row[0].substring(a - 1, a));
    out.print(",");

    // Finds time length
    a = row[1].length();
    if (a > 17) out.print(row[1].substring(17, a));
    out.print(",");

    // Finds the down
    a = row[2].length();
    if (a > 17) out.print(row[2].substring(17, a));
    out.print(",");

    // Finds the ToGo length
    a = row[3].length();
    if (a > 17) out.print(row[3].substring(17, a));
    out.print(",");

    // Finds the possession
    a = row[4].length();
    if (a > 13) out.print(row[4].substring(13, a));
    out.print(",");

    // Parses the play
    String play = playparse(row[5]);
    out.print(play);
    out.print(",");

    // Finds the current score for first team
    a = row[6].length();
    if (a > 4) out.print(row[6].substring(4, a));
    out.print(",");

    // Finds the current score for the second team
    a = row[7].length();
    if (a > 4) out.print(row[7].substring(4, a));
    out.print(",");

    // Finds the EPB
    a = row[8].length();
    if (a > 4) out.print(row[8].substring(4, a));
    out.print(",");

    // Finds the EPA
    a = row[9].length();
    if (a > 4) out.print(row[9].substring(4, a));
    out.print(",");

    // Outputs the possession
    out.println(possession);
  }
Ejemplo n.º 4
0
  /**
   * Prints one Unicode property value per line, along with its aliases, if any, for the given
   * unicodeVersion.
   *
   * @param unicodeVersion The Unicode version to print property values and aliases for
   * @throws UnicodeProperties.UnsupportedUnicodeVersionException if unicodeVersion is not supported
   */
  private static void printUnicodePropertyValuesAndAliases(String unicodeVersion)
      throws UnicodeProperties.UnsupportedUnicodeVersionException {
    Pattern versionPattern = Pattern.compile("(\\d+)(?:\\.(\\d+))?(?:\\.\\d+)?");
    Matcher matcher = versionPattern.matcher(unicodeVersion);
    if (!matcher.matches()) {
      throw new UnicodeProperties.UnsupportedUnicodeVersionException();
    }
    String underscoreVersion =
        matcher.group(1) + (null == matcher.group(2) ? "_0" : "_" + matcher.group(2));

    String[] propertyValues;
    String[] propertyValueAliases;
    try {
      Class<?> clazz = Class.forName("jflex.unicode.data.Unicode_" + underscoreVersion);
      Field field = clazz.getField("propertyValues");
      propertyValues = (String[]) field.get(null);
      field = clazz.getField("propertyValueAliases");
      propertyValueAliases = (String[]) field.get(null);
    } catch (Exception e) {
      throw new UnicodeProperties.UnsupportedUnicodeVersionException();
    }
    SortedMap<String, SortedSet<String>> propertyValuesToAliases =
        new TreeMap<String, SortedSet<String>>();
    for (String value : propertyValues) {
      propertyValuesToAliases.put(value, new TreeSet<String>());
    }
    for (int i = 0; i < propertyValueAliases.length; i += 2) {
      String alias = propertyValueAliases[i];
      String value = propertyValueAliases[i + 1];
      SortedSet<String> aliases = propertyValuesToAliases.get(value);
      if (null == aliases) {
        aliases = new TreeSet<String>();
        propertyValuesToAliases.put(value, aliases);
      }
      aliases.add(alias);
    }
    for (Map.Entry<String, SortedSet<String>> entry : propertyValuesToAliases.entrySet()) {
      String value = entry.getKey();
      SortedSet<String> aliases = entry.getValue();
      Out.print(value);
      if (aliases.size() > 0) {
        for (String alias : aliases) {
          Out.print(", " + alias);
        }
      }
      Out.println("");
    }
  }
 private static void saveWords(String fileName, String[] words) {
   int MAX_LENGTH = 70;
   Out out = new Out(fileName);
   int length = 0;
   for (String word : words) {
     length += word.length();
     if (length > MAX_LENGTH) {
       out.println();
       length = word.length();
     }
     out.print(word);
     out.print(" ");
     length++;
   }
   out.close();
 }
Ejemplo n.º 6
0
  /**
   * Generates a scanner for the specified input file.
   *
   * @param inputFile a file containing a lexical specification to generate a scanner for.
   */
  public static void generate(File inputFile) {

    Out.resetCounters();

    Timer totalTime = new Timer();
    Timer time = new Timer();

    LexScan scanner = null;
    LexParse parser = null;
    FileReader inputReader = null;

    totalTime.start();

    try {
      Out.println(ErrorMessages.READING, inputFile.toString());
      inputReader = new FileReader(inputFile);
      scanner = new LexScan(inputReader);
      scanner.setFile(inputFile);
      parser = new LexParse(scanner);
    } catch (FileNotFoundException e) {
      Out.error(ErrorMessages.CANNOT_OPEN, inputFile.toString());
      throw new GeneratorException();
    }

    try {
      NFA nfa = (NFA) parser.parse().value;

      Out.checkErrors();

      if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.NFA_IS) + Out.NL + nfa + Out.NL);

      if (Options.dot) nfa.writeDot(Emitter.normalize("nfa.dot", null)); // $NON-NLS-1$

      Out.println(ErrorMessages.NFA_STATES, nfa.numStates);

      time.start();
      DFA dfa = nfa.getDFA();
      time.stop();
      Out.time(ErrorMessages.DFA_TOOK, time);

      dfa.checkActions(scanner, parser);

      nfa = null;

      if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.DFA_IS) + Out.NL + dfa + Out.NL);

      if (Options.dot) dfa.writeDot(Emitter.normalize("dfa-big.dot", null)); // $NON-NLS-1$

      Out.checkErrors();

      time.start();
      dfa.minimize();
      time.stop();

      Out.time(ErrorMessages.MIN_TOOK, time);

      if (Options.dump) Out.dump(ErrorMessages.get(ErrorMessages.MIN_DFA_IS) + Out.NL + dfa);

      if (Options.dot) dfa.writeDot(Emitter.normalize("dfa-min.dot", null)); // $NON-NLS-1$

      time.start();

      Emitter e = new Emitter(inputFile, parser, dfa);
      e.emit();

      time.stop();

      Out.time(ErrorMessages.WRITE_TOOK, time);

      totalTime.stop();

      Out.time(ErrorMessages.TOTAL_TIME, totalTime);
    } catch (ScannerException e) {
      Out.error(e.file, e.message, e.line, e.column);
      throw new GeneratorException();
    } catch (MacroException e) {
      Out.error(e.getMessage());
      throw new GeneratorException();
    } catch (IOException e) {
      Out.error(ErrorMessages.IO_ERROR, e.toString());
      throw new GeneratorException();
    } catch (OutOfMemoryError e) {
      Out.error(ErrorMessages.OUT_OF_MEMORY);
      throw new GeneratorException();
    } catch (GeneratorException e) {
      throw new GeneratorException();
    } catch (Exception e) {
      e.printStackTrace();
      throw new GeneratorException();
    }
  }
Ejemplo n.º 7
0
 public static void printUsage() {
   Out.println(""); // $NON-NLS-1$
   Out.println("Usage: jflex <options> <input-files>");
   Out.println("");
   Out.println("Where <options> can be one or more of");
   Out.println("-d <directory>    write generated file to <directory>");
   Out.println("--skel <file>     use external skeleton <file>");
   Out.println("--switch             (DEPRECATED - will be removed in JFlex 1.6)");
   Out.println("--table              (DEPRECATED - will be removed in JFlex 1.6)");
   Out.println("--pack            set default code generation method (default)");
   Out.println("--jlex            strict JLex compatibility");
   Out.println("--legacydot       dot (.) metachar matches [^\\n] instead of");
   Out.println("                  [^\\n\\r\\u000B\\u000C\\u0085\\u2028\\u2029]");
   Out.println("--inputstreamctor    include a scanner constructor taking InputStream (default)");
   Out.println("--noinputstreamctor  don't include a scanner constructor taking InputStream");
   Out.println("--nomin           skip minimization step");
   Out.println("--nobak           don't create backup files");
   Out.println("--dump            display transition tables");
   Out.println("--dot             write graphviz .dot files for the generated automata (alpha)");
   Out.println("--verbose");
   Out.println("-v                display generation progress messages (default)");
   Out.println("--quiet");
   Out.println("-q                display errors only");
   Out.println("--time            display generation time statistics");
   Out.println("--version         print the version number of this copy of jflex");
   Out.println("--info            print system + JDK information");
   Out.println("--uniprops <ver>  print all supported properties for Unicode version <ver>");
   Out.println("--help");
   Out.println("-h                print this message");
   Out.println("");
   Out.println(ErrorMessages.THIS_IS_JFLEX, version);
   Out.println("Have a nice day!");
 }
Ejemplo n.º 8
0
  public static List<File> parseOptions(String argv[]) throws SilentExit {
    List<File> files = new ArrayList<File>();

    for (int i = 0; i < argv.length; i++) {

      if (argv[i].equals("-d") || argv[i].equals("--outdir")) { // $NON-NLS-1$ //$NON-NLS-2$
        if (++i >= argv.length) {
          Out.error(ErrorMessages.NO_DIRECTORY);
          throw new GeneratorException();
        }
        Options.setDir(argv[i]);
        continue;
      }

      if (argv[i].equals("--skel") || argv[i].equals("-skel")) { // $NON-NLS-1$ //$NON-NLS-2$
        if (++i >= argv.length) {
          Out.error(ErrorMessages.NO_SKEL_FILE);
          throw new GeneratorException();
        }

        Options.setSkeleton(new File(argv[i]));
        continue;
      }

      if (argv[i].equals("-jlex") || argv[i].equals("--jlex")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.jlex = true;
        continue;
      }

      if (argv[i].equals("-v")
          || argv[i].equals("--verbose")
          || argv[i].equals("-verbose")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Options.verbose = true;
        Options.progress = true;
        continue;
      }

      if (argv[i].equals("-q")
          || argv[i].equals("--quiet")
          || argv[i].equals("-quiet")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Options.verbose = false;
        Options.progress = false;
        continue;
      }

      if (argv[i].equals("--dump") || argv[i].equals("-dump")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.dump = true;
        continue;
      }

      if (argv[i].equals("--time") || argv[i].equals("-time")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.time = true;
        continue;
      }

      if (argv[i].equals("--version") || argv[i].equals("-version")) { // $NON-NLS-1$ //$NON-NLS-2$
        Out.println(ErrorMessages.THIS_IS_JFLEX, version);
        throw new SilentExit();
      }

      if (argv[i].equals("--dot") || argv[i].equals("-dot")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.dot = true;
        continue;
      }

      if (argv[i].equals("--help")
          || argv[i].equals("-h")
          || argv[i].equals("/h")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        printUsage();
        throw new SilentExit();
      }

      if (argv[i].equals("--info") || argv[i].equals("-info")) { // $NON-NLS-1$ //$NON-NLS-2$
        Out.printSystemInfo();
        throw new SilentExit();
      }

      if (argv[i].equals("--nomin") || argv[i].equals("-nomin")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.no_minimize = true;
        continue;
      }

      if (argv[i].equals("--pack") || argv[i].equals("-pack")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.PACK;
        continue;
      }

      if (argv[i].equals("--table") || argv[i].equals("-table")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.TABLE;
        continue;
      }

      if (argv[i].equals("--switch") || argv[i].equals("-switch")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.SWITCH;
        continue;
      }

      if (argv[i].equals("--nobak") || argv[i].equals("-nobak")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.no_backup = true;
        continue;
      }

      if (argv[i].equals("--legacydot")
          || argv[i].equals("-legacydot")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.legacy_dot = true;
        continue;
      }

      // TODO: In the JFlex version after 1.6, --inputstreamctor will be removed.
      if (argv[i].equals("--inputstreamctor")
          || argv[i].equals("-inputstreamctor")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.emitInputStreamCtor = true;
        continue;
      }

      // TODO: In the JFlex version after 1.6, --noinputstreamctor will be removed.
      if (argv[i].equals("--noinputstreamctor")
          || argv[i].equals("-noinputstreamctor")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.emitInputStreamCtor = false;
        continue;
      }

      if (argv[i].equals("--uniprops")
          || argv[i].equals("-uniprops")) { // $NON-NLS-1$ //$NON-NLS-2$
        if (++i >= argv.length) {
          Out.error(
              ErrorMessages.PROPS_ARG_REQUIRES_UNICODE_VERSION, UnicodeProperties.UNICODE_VERSIONS);
          throw new GeneratorException();
        }
        String unicodeVersion = argv[i];
        try {
          printUnicodePropertyValuesAndAliases(unicodeVersion);
        } catch (UnicodeProperties.UnsupportedUnicodeVersionException e) {
          Out.error(
              ErrorMessages.UNSUPPORTED_UNICODE_VERSION_SUPPORTED_ARE,
              UnicodeProperties.UNICODE_VERSIONS);
          throw new GeneratorException();
        }
        throw new SilentExit();
      }

      if (argv[i].startsWith("-")) { // $NON-NLS-1$
        Out.error(ErrorMessages.UNKNOWN_COMMANDLINE, argv[i]);
        printUsage();
        throw new SilentExit();
      }

      // if argv[i] is not an option, try to read it as file
      File f = new File(argv[i]);
      if (f.isFile() && f.canRead()) files.add(f);
      else {
        Out.error("Sorry, couldn't open \"" + f + "\""); // $NON-NLS-2$
        throw new GeneratorException();
      }
    }

    return files;
  }
Ejemplo n.º 9
0
 public void badRequest() {
   out.println("bad request");
 }
Ejemplo n.º 10
0
 /**
  * Formats JSON Object and sends it through the connection
  *
  * @param json Instance of net.sf.json.JSONObject;
  */
 public void send(JSONObject json) {
   System.err.println("Sending Message: " + json.toString());
   out.println(json.toString());
 }
Ejemplo n.º 11
0
 public static void printUsage() {
   Out.println(""); // $NON-NLS-1$
   Out.println("Usage: jflex <options> <input-files>");
   Out.println("");
   Out.println("Where <options> can be one or more of");
   Out.println("-d <directory>   write generated file to <directory>");
   Out.println("--skel <file>    use external skeleton <file>");
   Out.println("--switch");
   Out.println("--table");
   Out.println("--pack           set default code generation method");
   Out.println("--jlex           strict JLex compatibility");
   Out.println("--nomin          skip minimization step");
   Out.println("--nobak          don't create backup files");
   Out.println("--dump           display transition tables");
   Out.println("--dot            write graphviz .dot files for the generated automata (alpha)");
   Out.println("--verbose");
   Out.println("-v               display generation progress messages (default)");
   Out.println("--quiet");
   Out.println("-q               display errors only");
   Out.println("--time           display generation time statistics");
   Out.println("--version        print the version number of this copy of jflex");
   Out.println("--info           print system + JDK information");
   Out.println("--help");
   Out.println("-h               print this message");
   Out.println("");
   Out.println(ErrorMessages.THIS_IS_JFLEX, version);
   Out.println("Have a nice day!");
 }
Ejemplo n.º 12
0
  public static Vector parseOptions(String argv[]) throws SilentExit {
    Vector files = new Vector();

    for (int i = 0; i < argv.length; i++) {

      if (argv[i].equals("-d") || argv[i].equals("--outdir")) { // $NON-NLS-1$ //$NON-NLS-2$
        if (++i >= argv.length) {
          Out.error(ErrorMessages.NO_DIRECTORY);
          throw new GeneratorException();
        }
        Options.setDir(argv[i]);
        continue;
      }

      if (argv[i].equals("--skel") || argv[i].equals("-skel")) { // $NON-NLS-1$ //$NON-NLS-2$
        if (++i >= argv.length) {
          Out.error(ErrorMessages.NO_SKEL_FILE);
          throw new GeneratorException();
        }

        Options.setSkeleton(new File(argv[i]));
        continue;
      }

      if (argv[i].equals("-jlex") || argv[i].equals("--jlex")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.jlex = true;
        continue;
      }

      if (argv[i].equals("-v")
          || argv[i].equals("--verbose")
          || argv[i].equals("-verbose")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Options.verbose = true;
        Options.progress = true;
        continue;
      }

      if (argv[i].equals("-q")
          || argv[i].equals("--quiet")
          || argv[i].equals("-quiet")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Options.verbose = false;
        Options.progress = false;
        continue;
      }

      if (argv[i].equals("--dump") || argv[i].equals("-dump")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.dump = true;
        continue;
      }

      if (argv[i].equals("--time") || argv[i].equals("-time")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.time = true;
        continue;
      }

      if (argv[i].equals("--version") || argv[i].equals("-version")) { // $NON-NLS-1$ //$NON-NLS-2$
        Out.println(ErrorMessages.THIS_IS_JFLEX, version);
        throw new SilentExit();
      }

      if (argv[i].equals("--dot") || argv[i].equals("-dot")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.dot = true;
        continue;
      }

      if (argv[i].equals("--help")
          || argv[i].equals("-h")
          || argv[i].equals("/h")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        printUsage();
        throw new SilentExit();
      }

      if (argv[i].equals("--info") || argv[i].equals("-info")) { // $NON-NLS-1$ //$NON-NLS-2$
        Out.printSystemInfo();
        throw new SilentExit();
      }

      if (argv[i].equals("--nomin") || argv[i].equals("-nomin")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.no_minimize = true;
        continue;
      }

      if (argv[i].equals("--pack") || argv[i].equals("-pack")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.PACK;
        continue;
      }

      if (argv[i].equals("--table") || argv[i].equals("-table")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.TABLE;
        continue;
      }

      if (argv[i].equals("--switch") || argv[i].equals("-switch")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.gen_method = Options.SWITCH;
        continue;
      }

      if (argv[i].equals("--nobak") || argv[i].equals("-nobak")) { // $NON-NLS-1$ //$NON-NLS-2$
        Options.no_backup = true;
        continue;
      }

      if (argv[i].startsWith("-")) { // $NON-NLS-1$
        Out.error(ErrorMessages.UNKNOWN_COMMANDLINE, argv[i]);
        printUsage();
        throw new SilentExit();
      }

      // if argv[i] is not an option, try to read it as file
      File f = new File(argv[i]);
      if (f.isFile() && f.canRead()) files.addElement(f);
      else {
        Out.error("Sorry, couldn't open \"" + f + "\""); // $NON-NLS-2$
        throw new GeneratorException();
      }
    }

    return files;
  }
Ejemplo n.º 13
0
  // Takes in the array of team game links. Can be called from another method
  // links should be an array of strings in the form:
  // /boxscores/201201010min.htm
  // /boxscores/201112250gnb.htm
  // Such as the first part of the link should not be included
  public static void decode(String[] links) {
    // Finds the array length
    int length = links.length;

    // Creates a new array for full links
    String[] fixed = new String[length];

    // Creates the game links
    for (int i = 0; i < length; i++) {
      String temp = "http://widgets.sports-reference.com/wg.fcgi?css=1&site=pfr&url=";
      temp = temp.concat(links[i]);
      temp = temp.concat("&div=div_pbp_data");
      fixed[i] = temp;
    }

    // Starts parsing the data
    for (int i = 0; i < length; i++) {
      String game = fixed[i];

      // Creates a new input stream from the website and reads it
      In in = new In(game);
      String f = in.readAll();

      // Splits the top off
      String[] break1 = f.split("</style>\\\\");

      // Splits the bottom off
      break1 = break1[1].split("</table>");

      // Splits it into single rows
      break1 = break1[0].split("</tr>");

      // Begins a loop where it takes each line and splits it into
      // individual segments, then runs some checks to make sure
      // what it read is a play. Also checks for penalties.
      int length2 = break1.length;

      for (int j = 0; j < length2; j++) {
        // Splits the row into individual elements
        String[] break2 = break1[j].split("</td>");

        // Finds the length of the elements
        int length3 = break2.length;

        // Checks for initial assignment of a possession
        if (possession == -1 && length3 == 10) {
          // Gets the yardage at the beginning
          int plength = break2[4].length();

          // Checks that there was a possession assigned
          if (plength > 13) {
            String pplay = break2[4].substring(13, 15);

            // Assigns possession
            if (pplay.equals(teamorig)) {
              possession = 0;
              initpos = 0;
            } else {
              possession = 1;
              initpos = 1;
            }
          }
        }

        // If it is less than 10, it is not a play
        if (length3 == 10) {

          // Checks for the penalty
          int pen = break2[0].lastIndexOf("has_penalty");
          if (pen != -1) {

            // Checks for include or exclude pentalty
            if (penalty == 1) {

              // Checks for change of possession
              int chpos = break2[0].lastIndexOf("pos_change");
              if (chpos != -1) {
                // Reassigns possession
                if (possession == 1) possession = 0;
                else if (possession == 0) possession = 1;
              }

              // Prints out the info
              output(break2);
            }

            if (penalty == 0) {
              // Checks for change of possession
              int chpos = break2[0].lastIndexOf("pos_change");
              if (chpos != -1) {
                // Reassigns possession
                if (possession == 1) possession = 0;
                else if (possession == 0) possession = 1;
              }
            }

          } else {
            // Checks for change of possession
            int chpos = break2[0].lastIndexOf("pos_change");
            if (chpos != -1) {
              // Reassigns possession
              if (possession == 1) possession = 0;
              else if (possession == 0) possession = 1;
            }

            output(break2);
          }
        }
      }
      out.println("");
      possession = -1;
    }
  }