@Override Object protoFromSoy(SoyValue field) { return field.longValue(); } };
@Override Object protoFromSoy(SoyValue field) { return field.longValue(); } };
/** Rounds the given value to the closest integer. */ public static long round(SoyValue value) { if (value instanceof IntegerData) { return value.longValue(); } else { return Math.round(value.numberValue()); } }
@Override Object protoFromSoy(SoyValue field) { return UnsignedInts.saturatedCast(field.longValue()); } };
@Override Object protoFromSoy(SoyValue field) { return Ints.saturatedCast(field.longValue()); } };
@Override Object protoFromSoy(SoyValue field) { return Ints.saturatedCast(field.longValue()); } };
@Override Object protoFromSoy(SoyValue field) { return UnsignedInts.saturatedCast(field.longValue()); } };
/** Returns the numeric maximum of the two arguments. */ public static NumberData max(SoyValue arg0, SoyValue arg1) { if (arg0 instanceof IntegerData && arg1 instanceof IntegerData) { return IntegerData.forValue(Math.max(arg0.longValue(), arg1.longValue())); } else { return FloatData.forValue(Math.max(arg0.numberValue(), arg1.numberValue())); } } /** Returns the numeric minimum of the two arguments. */
@Override public SoyValue computeForJava(List<SoyValue> args) { SoyValue arg = args.get(0); long longValue = arg.longValue(); return IntegerData.forValue(BasicFunctionsRuntime.randomInt(longValue)); }
/** Returns the numeric minimum of the two arguments. */ public static NumberData min(SoyValue arg0, SoyValue arg1) { if (arg0 instanceof IntegerData && arg1 instanceof IntegerData) { return IntegerData.forValue(Math.min(arg0.longValue(), arg1.longValue())); } else { return FloatData.forValue(Math.min(arg0.numberValue(), arg1.numberValue())); } }
/** Performs the {@code <} operator on the two values. */ public static boolean lessThan(SoyValue left, SoyValue right) { if (left instanceof SoyString && right instanceof SoyString) { return left.stringValue().compareTo(right.stringValue()) < 0; } else if (left instanceof IntegerData && right instanceof IntegerData) { return left.longValue() < right.longValue(); } else { return left.numberValue() < right.numberValue(); } }
/** Performs the {@code <=} operator on the two values. */ public static boolean lessThanOrEqual(SoyValue left, SoyValue right) { if (left instanceof SoyString && right instanceof SoyString) { return left.stringValue().compareTo(right.stringValue()) <= 0; } else if (left instanceof IntegerData && right instanceof IntegerData) { return left.longValue() <= right.longValue(); } else { return left.numberValue() <= right.numberValue(); } }
/** Performs the {@code <} operator on the two values. */ public static boolean lessThan(SoyValue left, SoyValue right) { if (left instanceof SoyString && right instanceof SoyString) { return left.stringValue().compareTo(right.stringValue()) < 0; } else if (left instanceof IntegerData && right instanceof IntegerData) { return left.longValue() < right.longValue(); } else { return left.numberValue() < right.numberValue(); } }
/** Performs the {@code -} operator on the two values. */ public static SoyValue minus(SoyValue operand0, SoyValue operand1) { if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) { return IntegerData.forValue(operand0.longValue() - operand1.longValue()); } else { return FloatData.forValue(operand0.numberValue() - operand1.numberValue()); } }
/** Performs the {@code *} operator on the two values. */ public static NumberData times(SoyValue operand0, SoyValue operand1) { if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) { return IntegerData.forValue(operand0.longValue() * operand1.longValue()); } else { return FloatData.forValue(operand0.numberValue() * operand1.numberValue()); } }
/** Performs the unary negation {@code -} operator on the value. */ public static NumberData negative(SoyValue node) { if (node instanceof IntegerData) { return IntegerData.forValue(-node.longValue()); } else { return FloatData.forValue(-node.floatValue()); } }
/** Performs the unary negation {@code -} operator on the value. */ public static NumberData negative(SoyValue node) { if (node instanceof IntegerData) { return IntegerData.forValue(-node.longValue()); } else { return FloatData.forValue(-node.floatValue()); } }
/** Performs the {@code +} operator on the two values. */ public static SoyValue plus(SoyValue operand0, SoyValue operand1) { if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) { return IntegerData.forValue(operand0.longValue() + operand1.longValue()); } else if (operand0 instanceof NumberData && operand1 instanceof NumberData) { return FloatData.forValue(operand0.numberValue() + operand1.numberValue()); } else { // String concatenation is the fallback for other types (like in JS). Use the implemented // coerceToString() for the type. return StringData.forValue(operand0.coerceToString() + operand1.coerceToString()); } }