private static Budget loadBudget(int index, File[] foundBudgets) {
   FileInputStream newBudget = null;
   ObjectInputStream toLoad = null;
   Object loadedBudget = null;
   try {
     newBudget = new FileInputStream(foundBudgets[index].toString());
   } catch (FileNotFoundException e) {
     Printer.print("wTF");
     System.out.println("Error making the FileInputStream");
   }
   try {
     toLoad = new ObjectInputStream(newBudget);
   } catch (IOException e) {
     Printer.print("wTF");
     System.out.println("Error making the ObjectInputStream");
   }
   try {
     loadedBudget = toLoad.readObject();
   } catch (ClassNotFoundException | IOException e) {
     Printer.print("wTF");
     System.out.println("IO exception, maybe the file is bad?");
   }
   try {
     toLoad.close();
   } catch (IOException e) {
     Printer.print("wTF");
     System.out.println("Couldn't close the Object/File input streams.");
   }
   BudgetBoss.endLoadSavedBudget();
   return (Budget) loadedBudget;
 }
  public static void main(String[] args) {
    ScopeTest test = new ScopeTest();
    Printer lambdaPrinter = test.getLambdaPrinter();
    lambdaPrinter.print("Lambda Expressions");

    Printer anonymousPrinter = test.getAnonymousPrinter();
    anonymousPrinter.print("Anonymous Class");
  }
 private static void searchDirectory(String directoryToSearch) {
   AnsiConsole.out.println(ansi().eraseScreen());
   Printer.print("searchingDirectory");
   File[] foundBudgets = Finder.findBudgets(directoryToSearch);
   if (foundBudgets.length > 0) {
     chooseBudget(foundBudgets);
     BudgetBoss.setDefaultDirectory(directoryToSearch);
   } else Printer.print("noBudgetFound");
 }
 public static void getLoadDirectory() {
   AnsiConsole.out.println(ansi().eraseScreen());
   Printer.print("savedInDefault");
   System.out.println(BudgetBoss.getDefaultDirectory());
   Printer.print("whereSaved");
   String toCheck = Listener.getInput();
   while (InputValidator.pathIsInvalid(toCheck)) toCheck = Listener.getInput();
   if (!(toCheck.equals("exit"))) {
     if (toCheck.equalsIgnoreCase("y")) {
       searchDirectory(BudgetBoss.getDefaultDirectory());
     } else searchDirectory(toCheck);
   }
 }
 @Override
 public void execute() {
   printer.print("Executing output features as csv process: ");
   printer.print("loading segments...");
   List<Segment> trainSet = loadFromJsonAndUpdateSegments(pathManager.getTrainSetPath());
   List<Segment> testSet = loadFromJsonAndUpdateSegments(pathManager.getTestSetPath());
   List<Segment> validationSet = loadFromJsonAndUpdateSegments(pathManager.getValidationSetPath());
   List<Segment> unclassified = getUnclassifiedSegments();
   printer.print("saving output...");
   String csv = segmentsCsvBuilder.buildCsv(trainSet, testSet, validationSet, unclassified);
   saveOutputToFile(csv);
   schemaToJobDirectorySaver.saveSchemaToJobDirectory();
   printer.print("done.\n");
 }
Esempio n. 6
0
  /**
   * Request a old chart request from the history of a ChartMediator.<br>
   * Referring to a given configuration (id), it requests a chart from the history of a
   * ChartMediator. Thereby it requests the one, indicated by the given number. E.g. 1 stands for
   * the newest one, 6 for the 6 latest.
   *
   * @param number number of the latest computed chart, range from 1 (latest) to 10 (oldest)
   * @return the JSON object of the requested chart, referring to the id and the number
   */
  public JSONObject historyChart(int number) {
    // checks whether a request is allowed
    if (!isInitialized()) {
      Printer.pproblem("Configurations & mediators not initalized!");
      Printer.print("-> Chart creation not possible!");
      return null;
    }

    // checks whether the parameters are legal
    if ((number < 0) || (getMaxSizeOfHistory() <= number)) {
      throw new IllegalArgumentException();
    }

    // checks if enough charts are stored yet
    if (number >= getCurrentSizeOfHistory()) {
      Printer.pproblem("Not so many charts stored yet.");
      return null;
    }

    // request the chart
    JSONObject histo = chartMedi.getHistoryChart(number);
    if (histo == null) {
      Printer.perror("No history for " + number + " found!");
      return null;
    }

    return histo;
  }
 public void testWithComplexArg() throws Exception {
   ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContext.xml", getClass());
   Printer printer = (Printer) ctx.getBean("printer");
   CountingPrintable printable = new CountingPrintable();
   printer.print(printable);
   assertEquals(1, printable.count);
 }
Esempio n. 8
0
  public static void printDiskUsage(
      AccumuloConfiguration acuConf,
      Collection<String> tables,
      VolumeManager fs,
      Connector conn,
      Printer printer,
      boolean humanReadable)
      throws TableNotFoundException, IOException {

    HashSet<String> tableIds = new HashSet<String>();

    // Get table IDs for all tables requested to be 'du'
    for (String tableName : tables) {
      String tableId = conn.tableOperations().tableIdMap().get(tableName);
      if (tableId == null)
        throw new TableNotFoundException(null, tableName, "Table " + tableName + " not found");

      tableIds.add(tableId);
    }

    Map<TreeSet<String>, Long> usage = getDiskUsage(acuConf, tableIds, fs, conn);

    String valueFormat = humanReadable ? "%9s" : "%,24d";
    for (Entry<TreeSet<String>, Long> entry : usage.entrySet()) {
      Object value = humanReadable ? NumUtil.bigNumberForSize(entry.getValue()) : entry.getValue();
      printer.print(String.format(valueFormat + " %s", value, entry.getKey()));
    }
  }
Esempio n. 9
0
  /**
   * Directs a chart request to a ChartMediator.<br>
   * Referring to a given configuration (id), it directs a request for a chart to a ChartMediator
   * and returns the result.
   *
   * @param json String path to a .json file where request information are stored
   * @return a json-object which contains all information about the requested chart
   * @see ChartMediator
   */
  public JSONObject computeChart(JSONObject json) {
    if (json == null) {
      throw new IllegalArgumentException();
    }

    // checks whether a request is allowed
    if (!isInitialized()) {
      Printer.pproblem("Configurations & mediators not initalized!");
      Printer.print("-> Chart creation not possible!");
      return null;
    }

    if (!(tablesAreCreated())) {
      Printer.pproblem("Tables not created. Request not possible");
      return null;
    }

    // direct request and hopefully receive a JSON object
    JSONObject chart = chartMedi.computeChart(json);

    if (chart == null) {
      Printer.pfail("Computing chart.");
      return null;
    } else {
      Printer.psuccess("Computing chart.");
    }

    return chart;
  }
Esempio n. 10
0
 private void invitations() {
   int count = 0;
   printer.println("Stored Invitation codes:");
   Collection<Invitation> invitations = core.getInvitaitonManager().allInvitations();
   for (Invitation i : invitations.toArray(new Invitation[invitations.size()])) {
     count++;
     printer.print(i.getCompleteInvitaitonString());
     if (core.getInvitaitonManager()
         .getInvitation(i.getInvitationPassKey())
         .isForwardedInvitation()) {
       printer.println(
           " (Forwarded)  -  Valid next: "
               + Long.toString(
                   (InvitaitonManager.INVITATION_TIMEOUT_FORWARDED
                           - (System.currentTimeMillis() - i.getCreatedAt()))
                       / (1000 * 60))
               + " minutes.");
     } else {
       printer.println(
           " (Manual)  -  Valid next: "
               + Long.toString(
                   (InvitaitonManager.INVITATION_TIMEOUT
                           - (System.currentTimeMillis() - i.getCreatedAt()))
                       / (1000 * 60 * 60))
               + " hours.");
     }
   }
   printer.println("Found " + count + " Invitations.");
 }
Esempio n. 11
0
 /**
  * Same as {@code printToString()}, except that non-ASCII characters
  * in string type fields are not escaped in backslash+octals.
  */
 public static String printToUnicodeString(final MessageOrBuilder message) {
   try {
     final StringBuilder text = new StringBuilder();
     UNICODE_PRINTER.print(message, new TextGenerator(text));
     return text.toString();
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
Esempio n. 12
0
 /**
  * Generates a human readable form of this message, useful for debugging and
  * other purposes, with no newline characters.
  */
 public static String shortDebugString(final MessageOrBuilder message) {
   try {
     final StringBuilder sb = new StringBuilder();
     SINGLE_LINE_PRINTER.print(message, new TextGenerator(sb));
     // Single line mode currently might have an extra space at the end.
     return sb.toString().trim();
   } catch (IOException e) {
     throw new IllegalStateException(e);
   }
 }
Esempio n. 13
0
  /**
   * Returns the dimensions and rows.
   *
   * @return the dimensions and rows
   */
  public ArrayList<DimRow> getDimensions() {
    // checks whether a request against configuration is allowed
    if (!isInitialized()) {
      Printer.pproblem("Configurations not initalized!");
      Printer.print("-> Request on it possible!");
      return null;
    }

    return currentConfig.getDims();
  }
  @Test
  public void testPrintEmptyContent() {
    printer.print("");
    replayAll();

    document.setContent("");
    document.print();

    verifyAll(); // make sure Printer.print was called
  }
 private static void chooseBudget(File[] foundBudgets) {
   Printer.printFoundBudgets(foundBudgets);
   Printer.print("openBudget");
   int index = getChoiceNumber(foundBudgets);
   if (!(index == -5)) {
     System.out.println("Opening " + foundBudgets[index].getName() + "...\n");
     BudgetBoss.setCurrentBudget(loadBudget(index, foundBudgets));
     BudgetBoss.endNeedNewBudget();
   }
 }
Esempio n. 16
0
 /**
  * Method that calls print() methods on each printer
  *
  * @param message message to log
  * @throws PrinterManagerException
  */
 public void print(String message) throws PrinterManagerException {
   PrinterManagerException printerManagerException = new PrinterManagerException();
   for (Printer printer : printers) {
     try {
       printer.print(message);
     } catch (PrinterException e) {
       printerManagerException.addPrinterException(e);
     }
   }
   if (!printerManagerException.getPrinterExceptions().isEmpty()) {
     throw printerManagerException;
   }
 }
  @Override
  public String translate(String input) throws Exception {
    input = input.trim();
    String lcInput = input.toLowerCase();
    String addition = "select doc.fullName from Document as doc ";
    if (lcInput.startsWith("where") || lcInput.startsWith("order") || lcInput.length() == 0) {
      input = addition + input;
    } else if (lcInput.startsWith("from")) {
      input = addition + "," + input.substring(4);
    }
    JPQLParser parser = new JPQLParser();
    Start tree = parser.parse(input);
    QueryContext context = new QueryContext(tree, getDocumentAccessBridge());
    // analize query and store info in context
    tree.apply(new QueryAnalyzer(context));

    Printer printer = getPrinter(context);
    return printer.print();
  }
Esempio n. 18
0
 public boolean doPrint() {
   boolean success = true;
   boolean printed = false;
   try {
     if (!beforePrint()) {
       return false;
     }
     if (Printer.print(printObject)) {
       printed = true;
     }
   } catch (Exception e) {
     success = false;
     logger.error(e.getMessage(), e);
     JOptionPane.showMessageDialog(
         this, "打印出错!\n" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
   }
   if (success && printed) {
     afterSuccessPrint();
   }
   return printed;
 }
Esempio n. 19
0
  /**
   * Directs a parsing request to a ParserMediator.<br>
   * Referring to the given configuration (id), it directs the request of parsing a given log-file
   * (path) to a ParserMediator.
   *
   * @param path path of the log file, which has to be parsed
   * @return whether parsing this log file was successful, to a certain point; therefore {@linkplain
   *     ParserMediator}
   * @see ParserMediator
   */
  public boolean parseLogFile(String path) {
    if (path == null) {
      throw new IllegalArgumentException();
    }

    // Printer.ptest("creating tables: " + createDBTables());

    // testing
    // Printer.ptest("Start parsing task.");
    // long start = System.currentTimeMillis();

    // checks whether a request is allowed
    if (!isInitialized()) {
      Printer.pproblem("Configurations & mediators not initalized!");
      Printer.print("-> Parsing not possible!");
      return false;
    }

    if (!(tablesAreCreated())) {
      Printer.pproblem("Tables not created. Request not possible");
      return false;
    }

    // directs the request
    if (!parsMedi.parseLogFile(path)) {
      Printer.pfail("Parsing.");
      return false;
    } else {
      Printer.psuccess("Parsing.");
    }

    // testing
    // Printer.ptest("Completed parsing task. Time needed: " + (System.currentTimeMillis() -
    // start));

    // precompute strings for the web page selection boxes after parsinng
    computeDimensionData();

    return true;
  }
Esempio n. 20
0
  /**
   * Initializes this facade with a ConfigWrap, what is necessary to post requests to it.
   *
   * @param path of the configuration file (.json)
   * @return whether initialization was successful
   */
  public boolean init(final String path) {
    if (path == null) {
      throw new IllegalArgumentException();
    }

    // tries to build a new ConfigWrap
    ConfigWrap config = ConfigWrap.buildConfig(path);
    if (config == null) {
      Printer.pfail("Building ConfigWrap with the given path failed");
      return false;
    } else {
      Printer.psuccess("Building ConfigWrap for: " + config.getNameOfDB());
    }

    // set all the attributes
    currentConfig = config;
    dataMedi = new DataMediator(config);
    chartMedi = new ChartMediator(config, dataMedi);
    parsMedi = new ParserMediator(config, dataMedi);

    // testing
    // Printer.ptest(config.toString());

    // create tables for the configuration if necessary
    if (!(tablesAreCreated())) {
      Printer.print("Tables not created for this configuration. Will happen now.");
      if (!(createDBTables())) {
        Printer.pfail("Creating tables for this configuration");
        return false;
      } else {
        Printer.psuccess("Creating tables for this configuration");
      }
    }

    // pre-compute strings for the web page selection boxes
    computeDimensionData();

    Printer.psuccess("Initialize facade.");
    return true;
  }
Esempio n. 21
0
 public static void main(String[] args) {
   Printer p = new Printer();
   p.print("Hello world!");
 }
 /** Prints the stack table map. */
 public void println(PrintWriter w) {
   Printer.print(this, w);
 }
 public void displayMenu() {
   AnsiConsole.out.println(ansi().eraseScreen());
   Printer.print("mainMenuHeader");
   System.out.println("Budget in use: " + currentBudget.getName() + "\n");
   Printer.printMenuOptions(menuOptions);
 }
 public void print() {
   printer.print(content);
 }
Esempio n. 25
0
 public String print(byte[] bytes) {
   return printer.print(bytes);
 }
 protected void print(Printer... printers) throws Exception {
   for (Printer printer : printers) {
     printer.print(report);
   }
 }
 /**
  * Prints the stack table map.
  *
  * @param ps a print stream such as <code>System.out</code>.
  */
 public void println(java.io.PrintStream ps) {
   Printer.print(this, new java.io.PrintWriter(ps, true));
 }
Esempio n. 28
0
 /**
  * Same as {@code print()}, except that non-ASCII characters are not
  * escaped.
  */
 public static void printUnicode(
     final MessageOrBuilder message, final Appendable output)
     throws IOException {
   UNICODE_PRINTER.print(message, new TextGenerator(output));
 }
Esempio n. 29
0
 public static void main(String[] args) {
   Printer printer = new Printer();
   printer.setName("Hey");
   printer.print();
 }