com.datumbox.framework.core.common.utilities
Class PHPMethods
- java.lang.Object
-
- com.datumbox.framework.core.common.utilities.PHPMethods
-
public class PHPMethods extends java.lang.ObjectThis class contains a number of convenience methods which have an API similar to PHP functions and their are implemented in Java.
-
-
Constructor Summary
Constructors Constructor and Description PHPMethods()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static <T> voidarrangeByIndex(T[] array, java.lang.Integer[] indexes)Rearranges the array based on the order of the provided indexes.static double[]array_clone(double[] a)Copies the elements of double array.static double[][]array_clone(double[][] a)Copies the elements of double 2D array.static <K,V> java.util.Map<V,K>array_flip(java.util.Map<K,V> map)It flips the key and values of a map.static <T extends java.lang.Comparable<T>>
java.lang.Integer[]arsort(T[] array)Sorts an array in descending order and returns an array with indexes of the original order.static <T extends java.lang.Comparable<T>>
java.lang.Integer[]asort(T[] array)Sorts an array in ascending order and returns an array with indexes of the original order.static doublelog(double d, double base)Returns the logarithm of a number at an arbitrary base.static java.lang.Stringltrim(java.lang.String s)Trims spaces on the left.static intmt_rand()Returns a random positive integerstatic doublemt_rand(double min, double max)Returns a random double between min and maxstatic intmt_rand(int min, int max)Returns a random integer between min and maxstatic intpreg_match(java.util.regex.Pattern pattern, java.lang.String subject)Matches a string with a pattern.static intpreg_match(java.lang.String regex, java.lang.String subject)Matches a string with a regex.static java.lang.Stringpreg_replace(java.util.regex.Pattern pattern, java.lang.String replacement, java.lang.String subject)Matches a string with a pattern and replaces the matched components with a provided string.static java.lang.Stringpreg_replace(java.lang.String regex, java.lang.String replacement, java.lang.String subject)Matches a string with a regex and replaces the matched components with a provided string.static doubleround(double d, int i)Rounds a number to a specified precision.static java.lang.Stringrtrim(java.lang.String s)Trims spaces on the right.static <T> voidshuffle(T[] array)Shuffles the values of any array in place.static <T> voidshuffle(T[] array, java.util.Random rnd)Shuffles the values of any array in place using the provided random generator.static intsubstr_count(java.lang.String string, char character)Count the number of times a character appears in the string.static intsubstr_count(java.lang.String string, java.lang.String substring)Count the number of substring occurrences.
-
-
-
Method Detail
-
ltrim
public static java.lang.String ltrim(java.lang.String s)
Trims spaces on the left.- Parameters:
s-- Returns:
-
rtrim
public static java.lang.String rtrim(java.lang.String s)
Trims spaces on the right.- Parameters:
s-- Returns:
-
substr_count
public static int substr_count(java.lang.String string, java.lang.String substring)Count the number of substring occurrences.- Parameters:
string-substring-- Returns:
-
substr_count
public static int substr_count(java.lang.String string, char character)Count the number of times a character appears in the string.- Parameters:
string-character-- Returns:
-
preg_replace
public static java.lang.String preg_replace(java.lang.String regex, java.lang.String replacement, java.lang.String subject)Matches a string with a regex and replaces the matched components with a provided string.- Parameters:
regex-replacement-subject-- Returns:
-
preg_replace
public static java.lang.String preg_replace(java.util.regex.Pattern pattern, java.lang.String replacement, java.lang.String subject)Matches a string with a pattern and replaces the matched components with a provided string.- Parameters:
pattern-replacement-subject-- Returns:
-
preg_match
public static int preg_match(java.lang.String regex, java.lang.String subject)Matches a string with a regex.- Parameters:
regex-subject-- Returns:
-
preg_match
public static int preg_match(java.util.regex.Pattern pattern, java.lang.String subject)Matches a string with a pattern.- Parameters:
pattern-subject-- Returns:
-
round
public static double round(double d, int i)Rounds a number to a specified precision.- Parameters:
d-i-- Returns:
-
log
public static double log(double d, double base)Returns the logarithm of a number at an arbitrary base.- Parameters:
d-base-- Returns:
-
mt_rand
public static int mt_rand()
Returns a random positive integer- Returns:
-
mt_rand
public static int mt_rand(int min, int max)Returns a random integer between min and max- Parameters:
min-max-- Returns:
-
mt_rand
public static double mt_rand(double min, double max)Returns a random double between min and max- Parameters:
min-max-- Returns:
-
array_flip
public static <K,V> java.util.Map<V,K> array_flip(java.util.Map<K,V> map)
It flips the key and values of a map.- Type Parameters:
K-V-- Parameters:
map-- Returns:
-
shuffle
public static <T> void shuffle(T[] array)
Shuffles the values of any array in place.- Type Parameters:
T-- Parameters:
array-
-
shuffle
public static <T> void shuffle(T[] array, java.util.Random rnd)Shuffles the values of any array in place using the provided random generator.- Type Parameters:
T-- Parameters:
array-rnd-
-
asort
public static <T extends java.lang.Comparable<T>> java.lang.Integer[] asort(T[] array)
Sorts an array in ascending order and returns an array with indexes of the original order.- Type Parameters:
T-- Parameters:
array-- Returns:
-
arsort
public static <T extends java.lang.Comparable<T>> java.lang.Integer[] arsort(T[] array)
Sorts an array in descending order and returns an array with indexes of the original order.- Type Parameters:
T-- Parameters:
array-- Returns:
-
arrangeByIndex
public static <T> void arrangeByIndex(T[] array, java.lang.Integer[] indexes)Rearranges the array based on the order of the provided indexes.- Type Parameters:
T-- Parameters:
array-indexes-
-
array_clone
public static double[] array_clone(double[] a)
Copies the elements of double array.- Parameters:
a-- Returns:
-
array_clone
public static double[][] array_clone(double[][] a)
Copies the elements of double 2D array.- Parameters:
a-- Returns:
-
-
DataMelt 3.0 © DataMelt by jWork.ORG