org.openl.codegen.template.RulesUtils-functions.vm Maven / Gradle / Ivy
Show all versions of org.openl.rules.gen Show documentation
// MAX
#foreach ($type in $allTypes)
/**
* REturns max $tool.getTypeName($type)[] value
*
* @param values $tool.getTypeName($type)[] array
* @return max $tool.getTypeName($type)[]
*/
public static $tool.getTypeName($type) max($tool.getTypeName($type)[] values) {
return ($tool.getTypeName($type)) MathUtils.max(values);
}
#end
// MIN
#foreach ($type in $allTypes)
/**
*
* Returns the minimum value in an array.
*
*
* @param array an array, must not be null or empty
* @return the minimum value in the array
*/
public static $tool.getTypeName($type) min($tool.getTypeName($type)[] values) {
return ($tool.getTypeName($type)) MathUtils.min(values);
}
#end
// SUM
#foreach ($type in $allTypes)
/**
*
* Returns the sum of the elements in the array.
*
*
* @param values an array, must not be null or empty
* @return the sum of the elements in the array
*/
public static $tool.getTypeName($type) sum($tool.getTypeName($type)[] values) {
return ($tool.getTypeName($type)) MathUtils.sum(values);
}
#end
// AVERAGE
#foreach ($type in $allTypes)
public static $tool.getTypeName($type) avg($tool.getTypeName($type)[] values) {
return MathUtils.avg(values);
}
#end
// SMALL
#foreach ($type in $allTypes)
/**
*
* Removes null values from array, sorts an array in ascending order and
* returns the value at position 'position'
*
*
* @param values an array, must not be null or empty
* @param position array index whose value we wand to get
* @return value from array at position 'position'
*/
public static $tool.getTypeName($type) small($tool.getTypeName($type)[] values, int position) {
return MathUtils.small(values, position);
}
#end
// BIG
#foreach ($type in $allTypes)
/**
*
* Removes null values from array, sorts an array in descending order and
* returns the value at position 'position'
*
*
* @param values an array, must not be null or empty
* @param position array index whose value we wand to get
* @return value from array at position 'position'
*/
public static $tool.getTypeName($type) big($tool.getTypeName($type)[] values, int position) {
return MathUtils.big(values, position);
}
#end
// MEDIAN
#foreach ($type in $allTypes)
/**
* "Method median is not implemented yet"
*
* @param values
* @return
*/
public static $tool.getTypeName($type) median($tool.getTypeName($type)[] values) {
return MathUtils.median(values);
}
#end
// QUAOTIENT
#foreach ($type in $allTypes)
public static long quotient($tool.getTypeName($type) number, $tool.getTypeName($type) divisor) {
return MathUtils.quotient(number, divisor);
}
#end
//MOD as in Excel
#foreach ($type in $allTypes)
public static $tool.getTypeName($type) mod($tool.getTypeName($type) number, $tool.getTypeName($type) divisor) {
return MathUtils.mod(number, divisor);
}
#end
// SLICE
#foreach ($type in $allTypes)
/**
* Produces a new $tool.getTypeName($type)
array containing the elements
* between the start and end indices.
*
* The start index is inclusive, the end index exclusive.
* Null array input produces null output.
*
* @param array the array
* @param startIndexInclusive the starting index. Undervalue (<0)
* is promoted to 0, overvalue (>array.length) results
* in an empty array.
* @param endIndexExclusive elements up to endIndex-1 are present in the
* returned subarray. Undervalue (< startIndex) produces
* empty array, overvalue (>array.length) is demoted to
* array length.
* @return a new array containing the elements between
* the start and end indices.
*/
public static $tool.getTypeName($type)[] slice($tool.getTypeName($type)[] values, int startIndexInclusive) {
return MathUtils.slice(values, startIndexInclusive);
}
/**
* Produces a new $tool.getTypeName($type)
array containing the elements
* between the start and end indices.
*
* The start index is inclusive, the end index exclusive.
* Null array input produces null output.
*
* @param array the array
* @param startIndexInclusive the starting index. Undervalue (<0)
* is promoted to 0, overvalue (>array.length) results
* in an empty array.
* @param endIndexExclusive elements up to endIndex-1 are present in the
* returned subarray. Undervalue (< startIndex) produces
* empty array, overvalue (>array.length) is demoted to
* array length.
* @return a new array containing the elements between
* the start and end indices.
*/
public static $tool.getTypeName($type)[] slice($tool.getTypeName($type)[] values, int startIndexInclusive, int endIndexExclusive) {
return MathUtils.slice(values, startIndexInclusive, endIndexExclusive);
}
#end
// SORT
#foreach ($type in $allTypes)
/**
* Sorts the specified array of objects into ascending order, according
* to the {@linkplain Comparable natural ordering} of its elements.
* All elements in the array must implement the {@link Comparable}
* interface. Furthermore, all elements in the array must be
* mutually comparable (that is, {@code e1.compareTo(e2)} must
* not throw a {@code ClassCastException} for any elements {@code e1}
* and {@code e2} in the array).
*
* This sort is guaranteed to be stable: equal elements will
* not be reordered as a result of the sort.
*
*
Implementation note: This implementation is a stable, adaptive,
* iterative mergesort that requires far fewer than n lg(n) comparisons
* when the input array is partially sorted, while offering the
* performance of a traditional mergesort when the input array is
* randomly ordered. If the input array is nearly sorted, the
* implementation requires approximately n comparisons. Temporary
* storage requirements vary from a small constant for nearly sorted
* input arrays to n/2 object references for randomly ordered input
* arrays.
*
*
The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
*
The implementation was adapted from Tim Peters's list sort for Python
* (
* TimSort). It uses techiques from Peter McIlroy's "Optimistic
* Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.
*
* @param a the array to be sorted
*/
public static $tool.getTypeName($type)[] sort($tool.getTypeName($type)[] values) {
return MathUtils.sort(values);
}
#end
// ISEMTY
#foreach ($type in $allTypes)
public static boolean isEmpty($tool.getTypeName($type)[] array) {
return ArrayUtils.isEmpty(array);
}
#end