Package com.google.template.soy.data

Examples of com.google.template.soy.data.SoyData.numberValue()


    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() * operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() * operand1.numberValue());
    }
  }


  @Override protected SoyData visitDivideByOpNode(DivideByOpNode node) {
View Full Code Here


  @Override protected SoyData visitDivideByOpNode(DivideByOpNode node) {

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    // Note: Soy always performs floating-point division, even on two integers (like JavaScript).
    return convertResult(operand0.numberValue() / operand1.numberValue());
  }


  @Override protected SoyData visitModOpNode(ModOpNode node) {
View Full Code Here

    } else if (operand0 instanceof StringData || operand1 instanceof StringData) {
      // String concatenation. Note we're calling toString() instead of stringValue() in case one
      // of the operands needs to be coerced to a string.
      return convertResult(operand0.toString() + operand1.toString());
    } else {
      return convertResult(operand0.numberValue() + operand1.numberValue());
    }
  }


  @Override protected SoyData visitMinusOpNode(MinusOpNode node) {
View Full Code Here

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() - operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() - operand1.numberValue());
    }
  }


  @Override protected SoyData visitLessThanOpNode(LessThanOpNode node) {
View Full Code Here

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() < operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() < operand1.numberValue());
    }
  }


  @Override protected SoyData visitGreaterThanOpNode(GreaterThanOpNode node) {
View Full Code Here

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() > operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() > operand1.numberValue());
    }
  }


  @Override protected SoyData visitLessThanOrEqualOpNode(LessThanOrEqualOpNode node) {
View Full Code Here

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() <= operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() <= operand1.numberValue());
    }
  }


  @Override protected SoyData visitGreaterThanOrEqualOpNode(GreaterThanOrEqualOpNode node) {
View Full Code Here

    SoyData operand0 = visit(node.getChild(0));
    SoyData operand1 = visit(node.getChild(1));
    if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) {
      return convertResult(operand0.integerValue() >= operand1.integerValue());
    } else {
      return convertResult(operand0.numberValue() >= operand1.numberValue());
    }
  }


  @Override protected SoyData visitEqualOpNode(EqualOpNode node) {
View Full Code Here

    SoyData arg1 = args.get(1);

    if (arg0 instanceof IntegerData && arg1 instanceof IntegerData) {
      return toSoyData(Math.min(arg0.integerValue(), arg1.integerValue()));
    } else {
      return toSoyData(Math.min(arg0.numberValue(), arg1.numberValue()));
    }
  }


  @Override public JsExpr computeForJsSrc(List<JsExpr> args) {
View Full Code Here

    if (numDigitsAfterPt == 0) {
      if (value instanceof IntegerData) {
        return toSoyData(value.integerValue());
      } else {
        return toSoyData((int) Math.round(value.numberValue()));
      }
    } else if (numDigitsAfterPt > 0) {
      double valueDouble = value.numberValue();
      double shift = Math.pow(10, numDigitsAfterPt);
      return toSoyData(Math.round(valueDouble * shift) / shift);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.