Search in sources :

Example 1 with IDataMap

use of permafrost.tundra.data.IDataMap in project Tundra by Permafrost.

the class object method equal.

/**
	 * Returns whether the given arrays are considered equal.
	 * 
	 * @param pipeline The pipeline containing the arrays to be compared.
	 * @param klass    The component class of the arrays.
	 * @param <T>      The component class of the arrays.
	 */
public static <T> void equal(IData pipeline, Class<T> klass) {
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData operands = IDataHelper.get(cursor, "$operands", IData.class);
        // support $list.x and $list.y inputs for backwards-compatibility
        if (operands == null) {
            Object[] listX = IDataHelper.get(cursor, "$list.x", Object[].class);
            Object[] listY = IDataHelper.get(cursor, "$list.y", Object[].class);
            IDataMap map = new IDataMap();
            if (listX != null)
                map.put("$list.x", listX);
            if (listY != null)
                map.put("$list.y", listY);
            operands = map;
        }
        IDataHelper.put(cursor, "$equal?", ArrayHelper.equal(operands, klass), String.class);
    } finally {
        cursor.destroy();
    }
}
Also used : IDataMap(permafrost.tundra.data.IDataMap)

Example 2 with IDataMap

use of permafrost.tundra.data.IDataMap in project Tundra by Permafrost.

the class object method concatenate.

/**
	 * Returns a new array that is the concatenation of the given arrays.
	 * 
	 * @param pipeline The pipeline containing the arrays to be concatenated.
	 * @param klass    The component class of the arrays.
	 * @param <T>      The component class of the arrays.
	 */
public static <T> void concatenate(IData pipeline, Class<T> klass) {
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData operands = IDataHelper.get(cursor, "$operands", IData.class);
        // support $list.x and $list.y inputs for backwards-compatibility
        if (operands == null) {
            Object[] listX = IDataHelper.get(cursor, "$list.x", Object[].class);
            Object[] listY = IDataHelper.get(cursor, "$list.y", Object[].class);
            IDataMap map = new IDataMap();
            if (listX != null)
                map.put("$list.x", listX);
            if (listY != null)
                map.put("$list.y", listY);
            operands = map;
        }
        if (IDataHelper.size(operands) > 0)
            IDataHelper.put(cursor, "$list", ArrayHelper.concatenate(operands, klass));
    } finally {
        cursor.destroy();
    }
}
Also used : IDataMap(permafrost.tundra.data.IDataMap)

Example 3 with IDataMap

use of permafrost.tundra.data.IDataMap in project Tundra by Permafrost.

the class decimal method multiply.

public static final void multiply(IData pipeline) throws ServiceException {
    // --- <<IS-START(multiply)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $operands
    // [i] field:0:optional $precision
    // [i] field:0:optional $rounding {"HALF_UP","CEILING","DOWN","FLOOR","HALF_DOWN","HALF_EVEN","UNNECESSARY","UP"}
    // [o] field:0:optional $result
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData operands = IDataHelper.get(cursor, "$operands", IData.class);
        int precision = IDataHelper.getOrDefault(cursor, "$precision", Integer.class, -1);
        RoundingMode rounding = IDataHelper.get(cursor, "$rounding", RoundingMode.class);
        // support $decimals and $decimal input for backwards-compatibility
        boolean backwardsCompatiblityRequired = false;
        if (operands == null) {
            String[] list = IDataHelper.get(cursor, "$decimals", String[].class);
            String decimal = IDataHelper.get(cursor, "$decimal", String.class);
            IDataMap map = new IDataMap();
            if (list != null)
                map.put("$decimals", list);
            if (decimal != null)
                map.put("$decimal", decimal);
            operands = map;
            backwardsCompatiblityRequired = true;
        }
        BigDecimal[] decimals = BigDecimalHelper.normalize(IDataHelper.getLeafValues(operands));
        BigDecimal result = BigDecimalHelper.round(BigDecimalHelper.multiply(decimals), precision, rounding);
        if (backwardsCompatiblityRequired) {
            IDataHelper.put(cursor, "$decimal", result, String.class, false);
        } else {
            IDataHelper.put(cursor, "$result", result, String.class, false);
        }
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : RoundingMode(java.math.RoundingMode) IDataMap(permafrost.tundra.data.IDataMap) BigDecimal(java.math.BigDecimal)

Example 4 with IDataMap

use of permafrost.tundra.data.IDataMap in project Tundra by Permafrost.

the class decimal method minimum.

public static final void minimum(IData pipeline) throws ServiceException {
    // --- <<IS-START(minimum)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $operands
    // [i] field:0:optional $precision
    // [i] field:0:optional $rounding {"HALF_UP","CEILING","DOWN","FLOOR","HALF_DOWN","HALF_EVEN","UNNECESSARY","UP"}
    // [o] field:0:optional $minimum
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData operands = IDataHelper.get(cursor, "$operands", IData.class);
        int precision = IDataHelper.getOrDefault(cursor, "$precision", Integer.class, -1);
        RoundingMode rounding = IDataHelper.get(cursor, "$rounding", RoundingMode.class);
        // support $decimals input for backwards-compatibility
        boolean backwardsCompatiblityRequired = false;
        if (operands == null) {
            String[] list = IDataHelper.get(cursor, "$decimals", String[].class);
            IDataMap map = new IDataMap();
            if (list != null)
                map.put("$decimals", list);
            operands = map;
            backwardsCompatiblityRequired = true;
        }
        BigDecimal[] decimals = BigDecimalHelper.normalize(IDataHelper.getLeafValues(operands));
        BigDecimal result = BigDecimalHelper.round(BigDecimalHelper.minimum(decimals), precision, rounding);
        if (backwardsCompatiblityRequired) {
            IDataHelper.put(cursor, "$decimal", result, String.class, false);
        } else {
            IDataHelper.put(cursor, "$minimum", result, String.class, false);
        }
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : RoundingMode(java.math.RoundingMode) IDataMap(permafrost.tundra.data.IDataMap) BigDecimal(java.math.BigDecimal)

Example 5 with IDataMap

use of permafrost.tundra.data.IDataMap in project Tundra by Permafrost.

the class decimal method maximum.

public static final void maximum(IData pipeline) throws ServiceException {
    // --- <<IS-START(maximum)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $operands
    // [i] field:0:optional $precision
    // [i] field:0:optional $rounding {"HALF_UP","CEILING","DOWN","FLOOR","HALF_DOWN","HALF_EVEN","UNNECESSARY","UP"}
    // [o] field:0:optional $maximum
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData operands = IDataHelper.get(cursor, "$operands", IData.class);
        int precision = IDataHelper.getOrDefault(cursor, "$precision", Integer.class, -1);
        RoundingMode rounding = IDataHelper.get(cursor, "$rounding", RoundingMode.class);
        // support $decimals input for backwards-compatibility
        boolean backwardsCompatiblityRequired = false;
        if (operands == null) {
            String[] list = IDataHelper.get(cursor, "$decimals", String[].class);
            IDataMap map = new IDataMap();
            if (list != null)
                map.put("$decimals", list);
            operands = map;
            backwardsCompatiblityRequired = true;
        }
        BigDecimal[] decimals = BigDecimalHelper.normalize(IDataHelper.getLeafValues(operands));
        BigDecimal result = BigDecimalHelper.round(BigDecimalHelper.maximum(decimals), precision, rounding);
        if (backwardsCompatiblityRequired) {
            IDataHelper.put(cursor, "$decimal", result, String.class, false);
        } else {
            IDataHelper.put(cursor, "$maximum", result, String.class, false);
        }
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : RoundingMode(java.math.RoundingMode) IDataMap(permafrost.tundra.data.IDataMap) BigDecimal(java.math.BigDecimal)

Aggregations

IDataMap (permafrost.tundra.data.IDataMap)15 BigDecimal (java.math.BigDecimal)5 BigInteger (java.math.BigInteger)5 RoundingMode (java.math.RoundingMode)5 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 ObjectConvertMode (permafrost.tundra.lang.ObjectConvertMode)1