示例#1
0
  @Override
  public TLValue evaluate() {

    TLValue a = lhs.evaluate();
    TLValue b = rhs.evaluate();

    // number + number
    if (a.isNumber() && b.isNumber()) {
      return new TLValue(a.asDouble() + b.asDouble());
    }

    // list + any
    if (a.isList()) {
      List<TLValue> list = a.asList();
      list.add(b);
      return new TLValue(list);
    }

    // string + any
    if (a.isString()) {
      return new TLValue(a.asString() + "" + b.toString());
    }

    // any + string
    if (b.isString()) {
      return new TLValue(a.toString() + "" + b.asString());
    }

    throw new RuntimeException("illegal expression: " + this);
  }
示例#2
0
  @Override
  public TLValue evaluate() {

    TLValue a = lhs.evaluate();
    TLValue b = rhs.evaluate();

    if (a.isNumber() && b.isNumber()) {
      return new TLValue(a.asDouble() < b.asDouble());
    }

    if (a.isString() && b.isString()) {
      return new TLValue(a.asString().compareTo(b.asString()) < -1);
    }

    throw new RuntimeException("illegal expression: " + this);
  }