protected void printContent(PrintWriter p) {
   inputKey = String.valueOf(ConsolePrintContext.getInstance().nextChoiceNum());
   p.print("[");
   p.print(inputKey);
   p.print("] ");
   p.print(getText());
 }
Esempio n. 2
0
 public static void main(String... orange) throws IOException {
   Scanner scan = new Scanner(new File("friday.in"));
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("friday.out")));
   int num = scan.nextInt();
   int[] array = new int[7]; // saturday - monday
   int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   int[] days1 = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   int counter = 2;
   for (int i = 1900; i < 1900 + num; i++) {
     if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
       for (int k = 0; k < 12; k++) {
         array[(counter + 12) % 7]++;
         counter = ((counter + days1[k]) % 7);
       }
     } else {
       for (int k = 0; k < 12; k++) {
         array[(counter + 12) % 7]++;
         counter = ((counter + days[k]) % 7);
       }
     }
   }
   out.print(array[0]);
   for (int i = 1; i < 7; i++) out.print(" " + array[i]);
   out.print("\n");
   out.close();
   System.exit(0);
 }
Esempio n. 3
0
 /**
  * It draws the population to a file. A character allele is drawn as 1 o 0. Otherwise, a real
  * allele is drawn in ten points, that represent the interval [0..1] divided in ten fragments. In
  * each fragment, three types of symbol are possible: . --> The fragment is not covered by the
  * classifier. o --> The fragment is partially covered by the classifier. O --> The fragment is
  * totally covered by the classifier.
  *
  * <p>This notation has been obtained from Wilson2000 XCSR
  *
  * @param fout is the file where the population has to be drawn.
  */
 public void draw(PrintWriter fout) {
   double lower = 0, upper = 0;
   if (Config.ternaryRep) {
     fout.print(" " + ((char) rep[0].getAllele()) + " ");
     for (int i = 1; i < rep.length; i++) {
       fout.print("| " + ((char) rep[i].getAllele()) + " ");
     }
   } else {
     if (Config.typeOfAttributes[0].equals("character")) {
       fout.print(" " + ((char) rep[0].getAllele()) + " ");
     } else {
       printInterval(fout, rep[0].getLowerAllele(), rep[0].getUpperAllele());
     }
     for (int i = 1; i < rep.length; i++) {
       if (Config.typeOfAttributes[i].equals("character")) {
         fout.print("| " + ((char) rep[i].getAllele()) + " ");
       } else if (Config.typeOfAttributes[i].equals("integer")) {
         printInterval(i, fout, ((int) rep[i].getLowerAllele()), ((int) rep[i].getUpperAllele()));
       } else {
         printInterval(fout, rep[i].getLowerAllele(), rep[i].getUpperAllele());
       }
     }
   }
   fout.print("\t " + action);
 } // end draw
Esempio n. 4
0
  /**
   * Writes the opening RDF tag (with namespaces) to the print Writer.
   *
   * @param out PrintWriter
   * @throws IOException
   */
  protected void writeRDFHeader(PrintWriter out) throws IOException {

    // validate
    if (out != null) {

      // print opening RDF tag (including namespaces)
      out.print("<rdf:RDF ");

      // print namespaces
      Set<String> keys = namespaces.keySet();

      if (keys != null) {

        for (String currentKey : keys) {
          String currentValue = namespaces.get(currentKey);

          if ((currentKey != null) && (currentValue != null)) {

            // use entities: xmlns:ns="&ns;"
            out.print(NEWLINE + "  xmlns:" + currentKey + "=\"&" + currentKey + ";\"");
          }
        }
      }

      // close the opening tag (add a space for readability)
      out.print(">" + NEWLINE + NEWLINE);
    } else {

      throw new IllegalArgumentException("Cannot write to null Writer.");
    }
  }
  private void sendProcessingError(Throwable t, ServletResponse response) {

    String stackTrace = getStackTrace(t);

    if (stackTrace != null && !stackTrace.equals("")) {

      try {

        response.setContentType("text/html");
        PrintStream ps = new PrintStream(response.getOutputStream());
        PrintWriter pw = new PrintWriter(ps);
        pw.print("<html>\n<head>\n</head>\n<body>\n"); // NOI18N

        // PENDING! Localize this for next official release
        pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
        pw.print(stackTrace);
        pw.print("</pre></body>\n</html>"); // NOI18N
        pw.close();
        ps.close();
        response.getOutputStream().close();
        ;
      } catch (Exception ex) {
      }
    } else {
      try {
        PrintStream ps = new PrintStream(response.getOutputStream());
        t.printStackTrace(ps);
        ps.close();
        response.getOutputStream().close();
        ;
      } catch (Exception ex) {
      }
    }
  }
Esempio n. 6
0
  /**
   * Writes the XML Entities (used for namespaces) to the print Writer.
   *
   * @param out PrintWriter
   * @throws IOException
   */
  protected void writeXMLEntities(PrintWriter out) throws IOException {

    // validate
    if (out != null) {

      // print opening DOCTYPE DECLARATION tag
      out.print(NEWLINE + "<!DOCTYPE rdf:RDF [");

      // print namespaces
      Set<String> keys = namespaces.keySet();

      if (keys != null) {

        for (String currentKey : keys) {
          String currentValue = namespaces.get(currentKey);

          if ((currentKey != null) && (currentValue != null)) {

            // write as: <!ENTITY ns 'http://example.org/abc#'>
            out.print(NEWLINE + "  <!ENTITY " + currentKey + " '" + currentValue + "'>");
          }
        }
      }

      // close the opening tag (add a space for readability)
      out.print("]>" + NEWLINE + NEWLINE);
    } else {

      throw new IllegalArgumentException("Cannot write to null Writer.");
    }
  }
Esempio n. 7
0
 public void print(PrintWriter out) {
   int x, y, z;
   for (z = size - 1; z >= 0; z--) {
     // print borders
     for (y = size - 1; y >= 0; y--) {
       out.print("    +");
       for (x = 0; x < size; x++) {
         out.print("---+");
       }
       out.println();
       // numbers
       out.format("%2d: |", y);
       // x's and o's
       for (x = 0; x < size; x++) {
         out.format(" %s |", isEmpty(x, y, z) ? " " : grid[x][y][z]);
       }
       out.println();
     }
     // bottom border
     out.print("    +");
     for (x = 0; x < size; x++) {
       out.print("---+");
     }
     out.println();
     // numbers on bottom
     out.print("     ");
     for (x = 0; x < size; x++) {
       out.format("%2d  ", x);
     }
     out.println();
   }
 }
  public static void main(String[] args) throws IOException {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(new OutputStreamWriter(System.out));
    // br = new BufferedReader(new FileReader("in.txt"));
    // out = new PrintWriter(new FileWriter("out.txt"));

    TreeMap<Character, TreeSet<Integer>> tm = new TreeMap<Character, TreeSet<Integer>>();

    N = readInt();
    HashSet<Character> open = new HashSet<Character>();

    for (int i = 0; i < N; i++) {
      String next = readLine();
      if (next.charAt(0) == '^') {
        open.add(next.charAt(1));
        if (tm.get(next.charAt(1)) == null) tm.put(next.charAt(1), new TreeSet<Integer>());
      } else if (next.charAt(0) == '/') {
        open.remove(next.charAt(1));
      } else {
        int val = Integer.parseInt(next);
        for (Character c : open) {
          tm.get(c).add(val);
        }
      }
    }

    for (Map.Entry<Character, TreeSet<Integer>> e : tm.entrySet()) {
      out.print(e.getKey() + " ");
      for (Integer i : e.getValue()) out.print(i + " ");
      out.println();
    }
    out.close();
  }
 public void save(File target) {
   try {
     target.createNewFile(); // Creates a new file, if one doesn't exist already
     PrintWriter writer = new PrintWriter(target);
     // Prints some game info
     writer.println(sideLength_);
     writer.println(currentPlayer_);
     // Printing the state of the board
     for (int y = 0; y < sideLength_; y++) {
       for (int x = 0; x < sideLength_; x++) {
         writer.print(board_[x][y]);
         if (x != sideLength_ - 1) {
           writer.print(valueSeparator_);
         }
       }
       if (y != sideLength_ - 1) // Not yet the last line
       {
         writer.println();
       }
     }
     writer.close();
   } catch (Exception e) {
     System.out.println(e);
   }
 }
Esempio n. 10
0
 //
 // f0 -> "switch"
 // f1 -> "("
 // f2 -> Expression()
 // f3 -> ")"
 // f4 -> "{"
 // f5 -> ( SwitchLabel() ( BlockStatement() )* )*
 // f6 -> "}"
 //
 public void visit(SwitchStatement n) {
   out.print(n.f0 + " " + n.f1);
   n.f2.accept(this);
   out.println(n.f3);
   out.println(spc.spc + n.f4);
   spc.updateSpc(+1);
   for (Enumeration e = n.f5.elements(); e.hasMoreElements(); ) {
     NodeSequence seq = (NodeSequence) e.nextElement();
     out.print(spc.spc);
     seq.elementAt(0).accept(this);
     spc.updateSpc(+1);
     if (((NodeListOptional) seq.elementAt(1)).present()) {
       if (((NodeListOptional) seq.elementAt(1)).size() == 1) out.print(" ");
       else {
         out.println();
         out.print(spc.spc);
       }
       visit((NodeListOptional) seq.elementAt(1), "\n" + spc.spc);
     }
     out.println();
     spc.updateSpc(-1);
   }
   spc.updateSpc(-1);
   out.println(spc.spc + n.f6);
 }
Esempio n. 11
0
 public void cutPlaylist() throws Exception {
   if (logger.isDebugEnabled()) logger.debug("Cut Playlist.");
   String st;
   PrintWriter pw =
       new PrintWriter(new BufferedWriter(new FileWriter(new File(this.NAME + ".dec"))));
   BufferedReader br = new BufferedReader(new FileReader(new File(this.NAME)));
   if ((st = br.readLine()) != null) {
     String st2[];
     st = new File(st).toURL().toString();
     st2 = st.split("/");
     StringBuffer stb = new StringBuffer(st2[st2.length - 1]);
     StringBuffer stb2 = stb.reverse();
     String st3 = new String(stb2);
     int i = 0;
     while (st3.charAt(i) != '.') i++;
     String a = st3.substring(i + 1, st3.length());
     pw.print(new StringBuffer(a).reverse());
   }
   while ((st = br.readLine()) != null) {
     pw.println();
     String st2[];
     st = new File(st).toURL().toString();
     st2 = st.split("/");
     StringBuffer stb = new StringBuffer(st2[st2.length - 1]);
     StringBuffer stb2 = stb.reverse();
     String st3 = new String(stb2);
     int i = 0;
     while (st3.charAt(i) != '.') i++;
     String a = st3.substring(i + 1, st3.length());
     pw.print(new StringBuffer(a).reverse());
   }
   pw.close();
   br.close();
 }
Esempio n. 12
0
 private void writeOption(String optionName, int argument) {
   if (argument != 1) {
     writer.print(optionName);
     writer.print(' ');
     writer.println(argument);
   }
 }
  public static void main(String args[]) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("important.in"));
    PrintWriter out = new PrintWriter("important.out");

    int n = rInt(in.readLine(), 1, MaxN);

    boolean[] t = new boolean[26];

    for (int i = 0; i < n; i++) {
      String s = in.readLine();
      if (s.length() > MaxL) throw new Exception("String is too long");
      char f = checkFormula(s.trim());
      t[f - 'A'] = true;
    }
    ;

    out.println("Yes");

    boolean flag = false;
    for (int i = 0; i < 26; i++)
      if (t[i]) {
        if (flag) out.print(" | ");
        String let = "" + (char) (i + 'A');
        out.print(let + " | ~" + let);
        flag = true;
      }
    ;

    out.close();
  };
 public void process() {
   for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) {
     ExtractInterface annot = typeDecl.getAnnotation(ExtractInterface.class);
     if (annot == null) break;
     for (MethodDeclaration m : typeDecl.getMethods())
       if (m.getModifiers().contains(Modifier.PUBLIC)
           && !(m.getModifiers().contains(Modifier.STATIC))) interfaceMethods.add(m);
     if (interfaceMethods.size() > 0) {
       try {
         PrintWriter writer = env.getFiler().createSourceFile(annot.value());
         writer.println("package " + typeDecl.getPackage().getQualifiedName() + ";");
         writer.println("public interface " + annot.value() + " {");
         for (MethodDeclaration m : interfaceMethods) {
           writer.print("  public ");
           writer.print(m.getReturnType() + " ");
           writer.print(m.getSimpleName() + " (");
           int i = 0;
           for (ParameterDeclaration parm : m.getParameters()) {
             writer.print(parm.getType() + " " + parm.getSimpleName());
             if (++i < m.getParameters().size()) writer.print(", ");
           }
           writer.println(");");
         }
         writer.println("}");
         writer.close();
       } catch (IOException ioe) {
         throw new RuntimeException(ioe);
       }
     }
   }
 }
Esempio n. 15
0
  private void writeJarOptions(
      String inputEntryOptionName, String outputEntryOptionName, ClassPath classPath) {
    if (classPath != null) {
      for (int index = 0; index < classPath.size(); index++) {
        ClassPathEntry entry = classPath.get(index);
        String optionName = entry.isOutput() ? outputEntryOptionName : inputEntryOptionName;

        writer.print(optionName);
        writer.print(' ');
        writer.print(relativeFileName(entry.getFile()));

        // Append the filters, if any.
        boolean filtered = false;

        // For backward compatibility, the aar and apk filters come
        // first.
        filtered = writeFilter(filtered, entry.getAarFilter());
        filtered = writeFilter(filtered, entry.getApkFilter());
        filtered = writeFilter(filtered, entry.getZipFilter());
        filtered = writeFilter(filtered, entry.getEarFilter());
        filtered = writeFilter(filtered, entry.getWarFilter());
        filtered = writeFilter(filtered, entry.getJarFilter());
        filtered = writeFilter(filtered, entry.getFilter());

        if (filtered) {
          writer.print(ConfigurationConstants.CLOSE_ARGUMENTS_KEYWORD);
        }

        writer.println();
      }
    }
  }
  public void write(File cf) {

    OutputStream outs = null;
    try {
      outs = new BufferedOutputStream(new FileOutputStream(cf));
      PrintWriter pw = new PrintWriter(new OutputStreamWriter(outs, "utf8"), true);
      pw.println(title);
      pw.println(offlineCitation);

      if (generateSubsetCriteriaLine().equals("")) {
        pw.println("\n\n");
      } else {
        pw.println("\n");
        pw.println(generateSubsetCriteriaLine() + "\n");
      }
      pw.println(subsetTitle);
      pw.print(offlineCitation + " ");
      pw.print(variableList);
      pw.println(" [VarGrp/@var(DDI)];");
      pw.println(subsetUNF);
      outs.close();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  public void write(
      String citationFilename,
      List<String> variableNameSet,
      String subsetUNF,
      String subsettingCriteria) {
    OutputStream outs = null;
    if (subsetUNF == null) {
      subsetUNF = "";
    }
    if (subsettingCriteria == null) {
      subsettingCriteria = "";
    }
    try {
      File cf = new File(citationFilename);
      outs = new BufferedOutputStream(new FileOutputStream(cf));
      PrintWriter pw = new PrintWriter(new OutputStreamWriter(outs, "utf8"), true);
      pw.println(title);
      pw.println(offlineCitation);

      if (generateSubsetCriteriaLine().equals("")) {
        pw.println("\n\n");
      } else {
        pw.println("\n");
        pw.println(generateSubsetCriteriaLine() + "\n");
      }
      pw.println(subsetTitle);
      pw.print(offlineCitation + " ");
      pw.print(DvnDSButil.joinNelementsPerLine(variableNameSet, 5));
      pw.println(" [VarGrp/@var(DDI)];");
      pw.println(subsetUNF);
      outs.close();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
Esempio n. 18
0
  //
  // f0 -> "try"
  // f1 -> Block()
  // f2 -> ( "catch" "(" FormalParameter() ")" Block() )*
  // f3 -> [ "finally" Block() ]
  //
  public void visit(TryStatement n) {
    out.println(n.f0);
    out.print(spc.spc);
    n.f1.accept(this);
    for (Enumeration e = n.f2.elements(); e.hasMoreElements(); ) {
      NodeSequence seq = (NodeSequence) e.nextElement();
      out.println();
      out.print(spc.spc);
      seq.elementAt(0).accept(this);
      out.print(" ");
      seq.elementAt(1).accept(this);
      seq.elementAt(2).accept(this);
      seq.elementAt(3).accept(this);
      out.println();
      out.print(spc.spc);
      seq.elementAt(4).accept(this);
    }

    if (n.f3.present()) {
      NodeSequence seq = (NodeSequence) n.f3.node;
      out.println();
      seq.elementAt(0).accept(this);
      out.println();
      out.print(spc.spc);
      seq.elementAt(1).accept(this);
    }
  }
Esempio n. 19
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Reading All Request Parameters";
    out.println(
        ServletUtilities.headWithTitle(title)
            + "<BODY BGCOLOR=\"#FDF5E6\">\n"
            + "<H1 ALIGN=CENTER>"
            + title
            + "</H1>\n"
            + "<TABLE BORDER=1 ALIGN=CENTER>\n"
            + "<TR BGCOLOR=\"#FFAD00\">\n"
            + "<TH>Parameter Name<TH>Parameter Value(s)");
    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String paramName = (String) paramNames.nextElement();
      out.println("<TR><TD>" + paramName + "\n<TD>");
      String[] paramValues = request.getParameterValues(paramName);
      if (paramValues.length == 1) {
        String paramValue = paramValues[0];
        if (paramValue.length() == 0) out.print("<I>No Value</I>");
        else out.print(paramValue);
      } else {
        out.println("<UL>");
        for (int i = 0; i < paramValues.length; i++) {
          out.println("<LI>" + paramValues[i]);
        }
        out.println("</UL>");
      }
    }
    out.println("</TABLE>\n</BODY></HTML>");
  }
Esempio n. 20
0
 //
 // f0 -> PrimaryExpression()
 // f1 -> AssignmentOperator()
 // f2 -> Expression()
 //
 public void visit(Assignment n) {
   n.f0.accept(this);
   out.print(" ");
   n.f1.accept(this);
   out.print(" ");
   n.f2.accept(this);
 }
 public static void pn(Object... l1) {
   for (int i = 0; i < l1.length; i++) {
     if (i != 0) out.print(' ');
     out.print(l1[i].toString());
   }
   out.println();
 }
Esempio n. 22
0
  public static void main(String args[]) {

    wmatrix wmatrix = new wmatrix();
    wmatrix.start();
    try {
      PrintWriter profilefout =
          new PrintWriter(
              new BufferedWriter(
                  new FileWriter(
                      "profile_"
                          + Data.kinease
                          + "_"
                          + Data.code
                          + "_"
                          + Data.windows_size
                          + ".csv")));

      profilefout.print("Position=");
      for (int j = 0; j < Data.windows_size; j++) {
        profilefout.print("," + (j - Data.windows_size / 2));
      }
      profilefout.println();

      for (int i = 0; i < 20; i++) {
        for (int j = 0; j < Data.windows_size; j++) {
          profilefout.print("," + wm[i][j]);
        }
        profilefout.println();
      }
      profilefout.close();

    } catch (IOException ex) {

    }
  }
Esempio n. 23
0
  /** Metodo que escreve os clientes num ficheiro */
  public void escreveLocalidades(String fileLocalidades, String fileLigacoes, int nrlocalidades)
      throws FileNotFoundException, IOException {
    PrintWriter printloc = new PrintWriter(fileLocalidades);
    PrintWriter printlig = new PrintWriter(fileLigacoes);

    Collection<Localidade> coll = this.localidades.values();

    for (Localidade l : coll) {
      printloc.print(l.get_Codigopostal() + "|" + l.get_Nome());

      Map<String, Ligacao> ligacoes = l.get_Ligacoes();
      int nrligacoes = ligacoes.size();

      Collection<Ligacao> colllig = ligacoes.values();

      for (Ligacao lig : colllig) {
        printloc.print("|1");
        printlig.println(
            l.get_Codigopostal()
                + "|"
                + lig.get_Localidaded()
                + "|"
                + lig.get_Distancia()
                + "|"
                + lig.get_Taxas());
      }
      printloc.print("\n");

      nrlocalidades--;
      if (nrlocalidades == 0) break;
    }

    printloc.close();
    printlig.close();
  }
Esempio n. 24
0
  public void run() throws IOException {
    Scanner in = new Scanner(new File("partitions.in"));
    PrintWriter out = new PrintWriter(new File("partitions.out"));

    int sum = 0;
    while (true) {
      int n = in.nextInt();
      sum += n;
      int k = in.nextInt();
      if (n == 0 && k == 0) {
        break;
      }
      in.nextLine();
      ArrayList<Integer>[] set = new ArrayList[k];
      for (int i = 0; i < k; i++) {
        set[i] = new ArrayList<Integer>();
        String t = in.nextLine();
        Scanner sc = new Scanner(t);
        while (sc.hasNextInt()) {
          int q = 0;
          set[i].add(q = sc.nextInt() - 1);
        }
      }
      ArrayList<Integer> free = new ArrayList<Integer>();
      int keep = 0;
      for (int i = k - 1; i >= 0; i--) {
        ArrayList<Integer> nxt = next(set[i], free);
        if (nxt != null) {
          set[i] = nxt;
          keep = i + 1;
          break;
        } else {
          free.addAll(set[i]);
          Collections.sort(free);
        }
      }
      int newk = keep + free.size();
      out.println(n + " " + newk);
      for (int i = 0; i < keep; i++) {
        for (int j = 0; j < set[i].size(); j++) {
          if (j > 0) {
            out.print(" ");
          }
          out.print(set[i].get(j) + 1);
        }
        out.println();
      }
      Collections.sort(free);
      for (int i = 0; i < free.size(); i++) {
        out.println(free.get(i) + 1);
      }
      out.println();
    }

    assert sum <= 2000;

    in.close();
    out.close();
  }
Esempio n. 25
0
  private void writeRef(Storable storable) {
    int ref = fMap.indexOf(storable);

    fStream.print("REF");
    space();
    fStream.print(ref);
    space();
  }
 public void genJavaRead(PrintWriter writer, int depth, String readLabel) {
   genJavaDebugRead(writer, depth, readLabel, "\"\"");
   indent(writer, depth);
   writer.print(readLabel);
   writer.print(" = new ");
   writer.print(name());
   writer.println("(vm, ps);");
 }
Esempio n. 27
0
 /** Writes an int to the output stream. */
 public void writeBoolean(boolean b) {
   if (b) {
     fStream.print(1);
   } else {
     fStream.print(0);
   }
   space();
 }
Esempio n. 28
0
 /**
  * Prints the classifier to the specified file.
  *
  * @param fout is the file output where the classifier has to be printed.
  */
 public void print(PrintWriter fout) {
   fout.print(" ");
   for (int i = 0; i < rep.length; i++) {
     rep[i].print(fout);
   }
   fout.print("  " + action + "  ");
   if (parameters != null) parameters.print(fout);
 }
Esempio n. 29
0
 //
 // f0 -> "return"
 // f1 -> [ Expression() ]
 // f2 -> ";"
 //
 public void visit(ReturnStatement n) {
   out.print(n.f0);
   if (n.f1.present()) {
     out.print(" ");
     n.f1.accept(this);
   }
   n.f2.accept(this);
 }
Esempio n. 30
0
 public void unparse(PrintWriter p, int indent) {
   doIndent(p, indent);
   p.print("return ");
   if (myExp != null) {
     myExp.unparse(p, indent);
   }
   p.print(";\n");
 }