示例#1
0
 @Override
 public Value apply(Spreadsheet s, List<Expression> args) {
   SubExpression sx = (SubExpression) args.get(0);
   Value lv = sx.left.evaluate(s);
   Value rv = sx.right.evaluate(s);
   if (lv.getClass() == CellReference.class && rv.getClass() == CellReference.class) {
     return (new RegionReference(
             ((CellReference) lv).colIdx,
             ((CellReference) lv).rowIdx,
             ((CellReference) rv).colIdx,
             ((CellReference) rv).rowIdx))
         .average(s);
   } else {
     return new ErrorValue("Cannot find sum of anything but a cell region");
   }
 }
示例#2
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;
    }