Esempio n. 1
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;
  }
Esempio n. 2
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. 3
0
 /**
  * Sets the size for the history.
  *
  * @param size_history Size for the history length; must be between 1 and 100
  */
 public void setMaxSizeForHistory(int size_history) {
   chartMedi.setMaxSizeForHistory(size_history);
 }
Esempio n. 4
0
 /**
  * Returns the current number of charts stored in the history.
  *
  * @return the current number of charts stored in the history
  */
 public int getCurrentSizeOfHistory() {
   return chartMedi.getCurrentSizeOfHistory();
 }
Esempio n. 5
0
 /**
  * Returns the maximal number of charts possible to store in the history.
  *
  * @return the maximal number of charts possible to store in the history
  */
 public int getMaxSizeOfHistory() {
   return chartMedi.getMaxSizeOfHistory();
 }