Class Util
- java.lang.Object
-
- soot.jimple.spark.ondemand.genericutil.Util
-
public class Util extends Object
Miscellaneous utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static BitSetEMPTY_BITSETThe emptyBitSet.static booleanFULLY_QUALIFIED_NAMESGenerate strings with fully qualified names or not
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidaddIfNotNull(T val, Collection<T> vals)static booleanarrayContains(Object[] arr, Object obj, int size)static intbinaryLogUp(int n_)Binary log: finds the smallest power k such that 2^k>=nstatic intbinaryLogUp(long n_)Binary log: finds the smallest power k such that 2^k>=nstatic voidclear(BitSet bitSet_)Clear aBitSet.static <T> voiddoForAll(Collection<T> c_, ObjectVisitor<T> v_)Perform an action for all elements in a collection.static doublefact(double n_)Factorial on doubles; avoids overflow problems present when using integers.static intfact(int n_)Factorialstatic longfact(long n_)Factorialstatic BigIntegerfact(BigInteger n_)Factorialstatic <T> List<T>filter(Collection<T> src_, Predicate<T> pred_)Filter a collection: generate a new list from an existing collection, consisting of the elements satisfying some predicate.static <T> voidfilter(Collection<T> src_, Predicate<T> pred_, List<T> result_)Filter a collection according to some predicate, placing the result in a Liststatic <T> Tfind(Collection<T> c_, Predicate<T> p_)Test whether some element of the givenCollectionsatisfies the givenPredicate.static <T> Collection<T>findAll(Collection<T> c_, Predicate<T> p_)Test whether some element of the givenCollectionsatisfies the givenPredicate.static <T> booleanforAll(Collection<T> c_, Predicate<T> p_)Test whether all elements of the givenCollectionsatisfy the givenPredicate.static <T> booleanforSome(Collection<T> c_, Predicate<T> p_)Test whether some element of the givenCollectionsatisfies the givenPredicate.static intgetInt(Integer i)static inthashArray(Object[] objs)static <T> booleanintersecting(Set<T> s1, Set<T> s2)checks if two sets have a non-empty intersectionstatic <T,U>
List<U>map(List<T> srcList, Mapper<T,U> mapper_)Map a list: generate a new list with each element mapped.static <T,U>
Set<U>mapToSet(Collection<T> srcSet, Mapper<T,U> mapper_)Map a set: generate a new set with each element mapped.static StringobjArrayToString(Object[] o)static StringobjArrayToString(Object[] o, String start, String end, String sep)static StringobjectFieldsToString(Object obj)Write object fields to stringstatic <T> List<T>pickNAtRandom(List<T> vals, int n, long seed)static int[]realloc(int[] data_, int newSize_)static StringremoveAll(String str_, String sub_)Remove all occurrences of a given substring in a givenStringstatic StringremovePackageName(String fully_qualified_name_)Remove the package name from a fully qualified class namestatic StringreplaceAll(String str_, String sub_, String newSub_)Replace all occurrences of a given substring in a givenString.static Stringstr(int[] ints_)Convert an int[] to aStringfor printingstatic Stringstr(Throwable thrown_)static booleanstringContains(String str, String subStr)static StringtopLevelTypeString(String typeStr)given the name of a class C, returns the name of the top-most enclosing class of class C.static StringtoStringNull(Object o)
-
-
-
Field Detail
-
FULLY_QUALIFIED_NAMES
public static final boolean FULLY_QUALIFIED_NAMES
Generate strings with fully qualified names or not- See Also:
- Constant Field Values
-
-
Method Detail
-
fact
public static long fact(long n_)
Factorial
-
fact
public static BigInteger fact(BigInteger n_)
Factorial
-
fact
public static double fact(double n_)
Factorial on doubles; avoids overflow problems present when using integers.- Parameters:
n_- arg on which to compute factorial- Returns:
- (
doubleapproximation to) factorial of largest positive integer <= (n_ + epsilon)
-
fact
public static int fact(int n_)
Factorial
-
binaryLogUp
public static int binaryLogUp(int n_)
Binary log: finds the smallest power k such that 2^k>=n
-
binaryLogUp
public static int binaryLogUp(long n_)
Binary log: finds the smallest power k such that 2^k>=n
-
objArrayToString
public static String objArrayToString(Object[] o, String start, String end, String sep)
-
forSome
public static <T> boolean forSome(Collection<T> c_, Predicate<T> p_)
Test whether some element of the givenCollectionsatisfies the givenPredicate.
-
find
public static <T> T find(Collection<T> c_, Predicate<T> p_)
Test whether some element of the givenCollectionsatisfies the givenPredicate.- Returns:
- The first element satisfying the predicate; otherwise null.
-
findAll
public static <T> Collection<T> findAll(Collection<T> c_, Predicate<T> p_)
Test whether some element of the givenCollectionsatisfies the givenPredicate.- Returns:
- All the elements satisfying the predicate
-
forAll
public static <T> boolean forAll(Collection<T> c_, Predicate<T> p_)
Test whether all elements of the givenCollectionsatisfy the givenPredicate.
-
doForAll
public static <T> void doForAll(Collection<T> c_, ObjectVisitor<T> v_)
Perform an action for all elements in a collection.- Parameters:
c_- the collectionv_- the visitor defining the action
-
map
public static <T,U> List<U> map(List<T> srcList, Mapper<T,U> mapper_)
Map a list: generate a new list with each element mapped. The new list is always anArrayList; it would have been more precise to usereflectionto create a list of the same type as 'srcList', but reflection works really slowly in some implementations, so it's best to avoid it.
-
filter
public static <T> List<T> filter(Collection<T> src_, Predicate<T> pred_)
Filter a collection: generate a new list from an existing collection, consisting of the elements satisfying some predicate. The new list is always anArrayList; it would have been more precise to usereflectionto create a list of the same type as 'srcList', but reflection works really slowly in some implementations, so it's best to avoid it.
-
filter
public static <T> void filter(Collection<T> src_, Predicate<T> pred_, List<T> result_)
Filter a collection according to some predicate, placing the result in a List- Parameters:
src_- collection to be filteredpred_- the predicateresult_- the list for the result. assumed to be empty
-
mapToSet
public static <T,U> Set<U> mapToSet(Collection<T> srcSet, Mapper<T,U> mapper_)
Map a set: generate a new set with each element mapped. The new set is always aHashSet; it would have been more precise to usereflectionto create a set of the same type as 'srcSet', but reflection works really slowly in some implementations, so it's best to avoid it.
-
realloc
public static int[] realloc(int[] data_, int newSize_)
-
replaceAll
public static String replaceAll(String str_, String sub_, String newSub_)
Replace all occurrences of a given substring in a givenString.
-
removeAll
public static String removeAll(String str_, String sub_)
Remove all occurrences of a given substring in a givenString
-
objectFieldsToString
public static String objectFieldsToString(Object obj)
Write object fields to string
-
removePackageName
public static String removePackageName(String fully_qualified_name_)
Remove the package name from a fully qualified class name
-
hashArray
public static int hashArray(Object[] objs)
- Returns:
-
intersecting
public static <T> boolean intersecting(Set<T> s1, Set<T> s2)
checks if two sets have a non-empty intersection- Parameters:
s1-s2-- Returns:
trueif the sets intersect;falseotherwise
-
getInt
public static int getInt(Integer i)
-
topLevelTypeString
public static String topLevelTypeString(String typeStr)
given the name of a class C, returns the name of the top-most enclosing class of class C. For example, given A$B$C, the method returns A- Parameters:
typeStr-- Returns:
-
addIfNotNull
public static <T> void addIfNotNull(T val, Collection<T> vals)
-
-