private DownloadItem convertSpreadsheetToDownloadItem(Spreadsheet spreadsheet) {
   DownloadItem di = new DownloadItem();
   di.setTitle(spreadsheet.getTitle());
   di.setType(DownloadItem.ItemType.Spreadsheet);
   di.setAddress(spreadsheet.getId());
   return di;
 }
 private Spreadsheet convertDownloadItemToSpreadsheet(DownloadItem di) {
   Spreadsheet sp = new Spreadsheet();
   sp.setTitle(di.getTitle());
   sp.setId(di.getAddress());
   sp.setUpdateDate(new Date());
   return sp;
 }
  public int getColumnIndex(String name) {

    String[] names = spreadsheet.getColumnNames();

    for (int i = 0; i < names.length; i++) {
      if (name.equals(names[i])) return i;
    }

    throw new OpenLRuntimeException(
        "Column name <" + name + "> not found", spreadsheet.getBoundNode());
  }
  public SpreadsheetResultCalculator(
      Spreadsheet spreadsheet,
      IDynamicObject targetModule,
      Object[] params,
      IRuntimeEnv env,
      SpreadsheetTraceObject spreadsheetTraceObject) {
    super();

    this.spreadsheet = spreadsheet;
    this.targetModule = targetModule;
    this.params = params;
    this.env = env;
    this.results = new Object[spreadsheet.getHeight()][spreadsheet.getWidth()];
    this.spreadsheetTraceObject = spreadsheetTraceObject;
  }
Example #5
0
 public static void parse(String command, Spreadsheet spreadsheet) { // method to parse user input
   if (command.length() == 2 || command.length() == 3) {
     System.out.println(command + " = " + spreadsheet.getValue(command) + "\n");
   } else if (command.substring(0, 4).equals("exit")) { // allows user to terminate program
     System.out.println("\nFarewell!");
     running = false;
   } else if (command.substring(0, 5).equals("print")) { // prints spreadsheet
     System.out.println();
     spreadsheet.drawSpreadsheet();
   } else if (command.contains(" = ")) { // set cell values
     spreadsheet.setValue(
         command.substring(0, command.indexOf(" = ")),
         command.substring(command.indexOf(" = ") + 3));
   } else if (command.substring(0, 5).equals("clear")) { // clears cells or spreadsheet
     if (command.length() > 5) { // clear specific cell
       spreadsheet.clearCell(command.substring(6));
     } else { // clears entire spreadsheet
       spreadsheet.clear();
     }
   } else if (command.subSequence(0, 4).equals("save")) { // saves spreadsheet to file
     try {
       PersistenceHelper.save(command.substring(5), spreadsheet);
     } catch (Exception e) { // catches file error
       System.out.println("Unable to save to path '" + command.substring(5) + "'\n");
     }
   } else if (command.subSequence(0, 4).equals("load")) { // loads spreadsheet from file
     try {
       PersistenceHelper.load(command.substring(5), spreadsheet);
     } catch (Exception e) { // catches file error
       System.out.println("Unable to load from path '" + command.substring(5) + "'\n");
     }
   } else if (command.substring(0, 5).equals("clash")) {
     try {
       spreadsheet.clash(command.substring(6));
     } catch (IOException | ClashException e) {
       System.out.println(
           "'" + command.substring(6) + "' is not recognized as a valid clan tag.\n");
     }
   } else if (command.substring(0, 7).equals("quizlet")) {
     try {
       spreadsheet.quizlet(command.substring(8));
     } catch (IOException e) {
       System.out.println(
           "Something went wrong when reading Quizlet set #" + command.substring(8) + "\n");
     }
   } else if (command.substring(0, 4).equals("sort")) {
     spreadsheet.sort(command);
   } else if (command.substring(0, 6).equals("resize")) {
     spreadsheet.resize(command.substring(7));
   } else { // notifies user of invalid command
     System.out.println("'" + command + "' is not recognized as a valid command.\n");
   }
 }
  public Object getValueTraced(int row, int column) {
    SpreadsheetCell spreadsheetCell = spreadsheet.getCells()[row][column];

    SpreadsheetTracerLeaf spreadsheetTraceLeaf =
        new SpreadsheetTracerLeaf(spreadsheetTraceObject, spreadsheetCell);
    Object result = null;

    try {
      Tracer.begin(spreadsheetTraceLeaf);
      if (cacheResult) {

        result = results[row][column];

        if (result != null) {
          spreadsheetTraceLeaf.setValue(result);
          return result;
        }
      }

      result = spreadsheetCell.calculate(this, targetModule, params, env);
      results[row][column] = result;

      spreadsheetTraceLeaf.setValue(result);
      return result;
    } finally {
      Tracer.end();
    }
  }
  public SpreadsheetResultCalculator(
      Spreadsheet spreadsheet,
      IDynamicObject targetModule,
      Object[] params,
      IRuntimeEnv env,
      Object[][] preCalculatedResult) {
    super();

    this.spreadsheet = spreadsheet;
    this.targetModule = targetModule;
    this.params = params;
    this.env = env;
    if (preCalculatedResult == null)
      this.results = new Object[spreadsheet.getHeight()][spreadsheet.getWidth()];
    else this.results = clonePrecalculatedResults(preCalculatedResult);
  }
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   if (args.size() > 0) {
     LValue v = (LValue) (args.get(0).evaluate(s));
     v.assign(s, null);
   } else s.clear();
   return null;
 }
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   try {
     s.print();
   } catch (StackOverflowError e) {
     System.out.println("Error: Stack Overflow; Self-referencing formulas?");
   }
   return null;
 }
Example #10
0
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   try {
     s.newSize(
         (int) (((Number) args.get(0).evaluate(s).resolve(s)).v),
         (int) (((Number) args.get(1).evaluate(s).resolve(s)).v));
   } catch (IndexOutOfBoundsException e) {
     System.out.println("<Please Type Two Numebers After New>");
   }
   return null;
 }
Example #11
0
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   try {
     s.delete(((StringValue) args.get(0).evaluate(s).resolve(s)).v);
   } catch (ClassCastException e) {
     System.out.println("<Please Put Name In Quotes>");
   } catch (NullPointerException e) {
     System.out.println("<Please Put Name In Quotes");
   }
   return null;
 }
Example #12
0
    @Override
    public Value apply(Spreadsheet s, List<Expression> args) {
      try {
        if (args.get(0).getClass() == Identifier.class) {
          Identifier id = (Identifier) args.get(0);
          s.sort(id.nm.toUpperCase().charAt(0));
          return null;
        }
        Value temp = args.get(0).evaluate(s).resolve(s);
        if (temp.getClass() == Number.class) {
          s.sort((int) (((Number) temp).v));
        }
      } catch (ClassCastException e) {
        System.out.println(
            "Error: "
                + e.getMessage()
                + "\nEnsure that the row/column only contains numbers or strings\n");
      }

      return null;
    }
  public Object getFieldValue(String name) {

    IOpenField field = spreadsheet.getSpreadsheetType().getField(name);

    if (field == null) {
      return targetModule.getFieldValue(name);
    }

    SpreadsheetCellField cellField = (SpreadsheetCellField) field;

    int row = cellField.getCell().getRowIndex();
    int column = cellField.getCell().getColumnIndex();

    return getValue(row, column);
  }
  public Object getValue(int row, int column) {
    SpreadsheetCell spreadsheetCell = spreadsheet.getCells()[row][column];
    if (isTraceOn() && spreadsheetCell.getKind() != SpreadsheetCellType.EMPTY) {
      getValueTraced(row, column);
    } else {
      Object result = null;

      if (cacheResult) {

        result = results[row][column];

        if (result != NEED_TO_CALCULATE_VALUE) {
          return result;
        }
      }

      result = spreadsheetCell.calculate(this, targetModule, params, env);
      results[row][column] = result;
    }
    return results[row][column];
  }
 public IOpenClass getType() {
   return spreadsheet.getSpreadsheetType();
 }
Example #16
0
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   Spreadsheet.deleteFolder();
   return null;
 }
 public String getColumnName(int column) {
   return spreadsheet.getColumnNames()[column];
 }
Example #18
0
 public static void apply(Spreadsheet s) {
   s.setValue("print", new PrintFunc());
   s.setValue("clear", new ClearFunc());
   s.setValue("esc", new EscFunc());
   s.setValue("<", new CompFunc(CompFunc.ComparisonOp.less));
   s.setValue("<eq", new CompFunc(CompFunc.ComparisonOp.lesseq));
   s.setValue("eq", new CompFunc(CompFunc.ComparisonOp.eq));
   s.setValue(">", new CompFunc(CompFunc.ComparisonOp.grtr));
   s.setValue(">eq", new CompFunc(CompFunc.ComparisonOp.grtreq));
   s.setValue("!eq", new CompFunc(CompFunc.ComparisonOp.noteq));
   s.setValue("!", new BoolNotFunc());
   s.setValue("sum", new sumReg());
   s.setValue("avg", new avgReg());
   s.setValue("new", new newSheet());
   s.setValue("save", new saveSheet());
   s.setValue("load", new loadSheet());
   s.setValue("kill", new deleteFolder());
   s.setValue("delete", new deleteSheet());
   s.setValue("sort", new sortLine());
   s.setValue("help", new helpFunc());
 }
 public final int width() {
   return spreadsheet.getWidth();
 }
 public final int height() {
   return spreadsheet.getHeight();
 }
Example #21
0
 @Override
 public boolean equals(Object object) {
   Spreadsheet spreadsheet = (Spreadsheet) object;
   return spreadsheet.getName().equals(getName());
 }
 public String getRowName(int row) {
   return spreadsheet.getRowNames()[row];
 }