/** * Private helper to convert an integer result. * @param i The integer to convert. */ private SoyData convertResult(int i) { return IntegerData.forValue(i); }
/** * Private helper to convert an integer result. * * @param i The integer to convert. */ private SoyValue convertResult(long i) { return IntegerData.forValue(i); }
@Override public SoyValue apply(Integer input) { return IntegerData.forValue(input.longValue()); } });
@Override public SoyValue apply(Integer input) { return IntegerData.forValue(input.longValue()); } });
/** * Sets a data value at a given index. * * @param index The index. * @param value The data to set. */ public void set(int index, int value) { set(index, IntegerData.forValue(value)); }
@Override public SoyValue apply(ProtocolMessageEnum input) { // Proto enum that was directly passed into the template return IntegerData.forValue(input.getNumber()); } });
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, int value) { put(keyStr, IntegerData.forValue(value)); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, long value) { put(keyStr, IntegerData.forValue(value)); }
@Override public SoyValue soyFromProto(Object field) { return IntegerData.forValue(UnsignedInts.toLong(((Number) field).intValue())); }
/** * Adds a data value. * * @param value The data to add. */ public void add(int value) { add(IntegerData.forValue(value)); }
/** * Adds a data value. * * @param value The data to add. */ public void add(long value) { add(IntegerData.forValue(value)); }
@Override @Nonnull public Iterable<? extends SoyValue> getItemKeys() { ImmutableList.Builder<IntegerData> indexesBuilder = ImmutableList.builder(); for (int i = 0, n = length(); i < n; i++) { indexesBuilder.add(IntegerData.forValue(i)); } return indexesBuilder.build(); }
@Override @Nonnull public final Iterable<IntegerData> getItemKeys() { ImmutableList.Builder<IntegerData> indicesBuilder = ImmutableList.builder(); for (int i = 0, n = length(); i < n; i++) { indicesBuilder.add(IntegerData.forValue(i)); } return indicesBuilder.build(); }
@Override public SoyValue apply(EnumValueDescriptor input) { // / Proto enum that was obtained via reflection (e.g. from SoyProtoValue) return IntegerData.forValue(input.getNumber()); } });
public static NumberData $$max(NumberData arg0, NumberData arg1) { if (arg0 instanceof IntegerData && arg1 instanceof IntegerData) { return IntegerData.forValue(Math.max(arg0.integerValue(), arg1.integerValue())); } else { return FloatData.forValue(Math.max(arg0.numberValue(), arg1.numberValue())); } } }
/** 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())); } }
public static NumberData $$times(NumberData operand0, NumberData operand1) { if (operand0 instanceof IntegerData && operand1 instanceof IntegerData) { return IntegerData.forValue(operand0.integerValue() * operand1.integerValue()); } else { return FloatData.forValue(operand0.numberValue() * operand1.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 {@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()); } }