Package com.ibm.wala.util.collections
Class Util
- java.lang.Object
-
- com.ibm.wala.util.collections.Util
-
public class Util extends java.lang.ObjectMiscellaneous utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.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, java.util.Collection<T> vals)static <T> voiddoForAll(java.util.Collection<T> c, ObjectVisitor<T> v)Perform an action for all elements in a collection.static <S,T>
java.util.Set<T>filterByType(java.lang.Iterable<S> c, java.lang.Class<T> klass)Return those elements ofcthat are assignable toklass.static <T> Tfind(java.util.Collection<T> c, java.util.function.Predicate<T> p)Test whether some element of the givenCollectionsatisfies the givenPredicate.static <T> booleanforAll(java.util.Collection<T> c, java.util.function.Predicate<T> p)Test whether all elements of the givenCollectionsatisfy the givenPredicate.static <T> booleanforSome(java.util.Collection<T> c, java.util.function.Predicate<T> p)Test whether some element of the givenCollectionsatisfies the givenPredicate.static longgetUsedMemory()static <T> booleanintersecting(java.util.Set<T> s1, java.util.Set<T> s2)checks if two sets have a non-empty intersectionstatic <T,U>
java.util.List<U>map(java.util.List<T> srcList, java.util.function.Function<T,U> f)Map a list: generate a new list with each element mapped.static <T,U>
java.util.Set<U>mapToSet(java.util.Collection<T> srcSet, java.util.function.Function<T,U> f)Map a set: generate a new set with each element mapped.static java.lang.StringobjectFieldsToString(java.lang.Object obj)Write object fields to stringstatic int[]realloc(int[] data, int newSize)static java.lang.StringremovePackageName(java.lang.String fully_qualified_name_)Remove the package name from a fully qualified class namestatic java.lang.Stringstr(java.lang.Throwable thrown)Get aStringrepresentation of aThrowable.static java.lang.StringtopLevelTypeString(java.lang.String typeStr)given the name of a class C, returns the name of the top-most enclosing class of class C.
-
-
-
Field Detail
-
EMPTY_BITSET
public static final java.util.BitSet EMPTY_BITSET
The emptyBitSet.
-
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
-
str
public static java.lang.String str(java.lang.Throwable thrown) throws java.lang.IllegalArgumentExceptionGet aStringrepresentation of aThrowable.- Throws:
java.lang.IllegalArgumentException- if thrown == null
-
filterByType
public static <S,T> java.util.Set<T> filterByType(java.lang.Iterable<S> c, java.lang.Class<T> klass)Return those elements ofcthat are assignable toklass.
-
forSome
public static <T> boolean forSome(java.util.Collection<T> c, java.util.function.Predicate<T> p) throws java.lang.IllegalArgumentExceptionTest whether some element of the givenCollectionsatisfies the givenPredicate.- Throws:
java.lang.IllegalArgumentException- if c == null
-
find
public static <T> T find(java.util.Collection<T> c, java.util.function.Predicate<T> p) throws java.lang.IllegalArgumentExceptionTest whether some element of the givenCollectionsatisfies the givenPredicate.- Returns:
- The first element satisfying the predicate; otherwise null.
- Throws:
java.lang.IllegalArgumentException- if c == null
-
forAll
public static <T> boolean forAll(java.util.Collection<T> c, java.util.function.Predicate<T> p) throws java.lang.NullPointerExceptionTest whether all elements of the givenCollectionsatisfy the givenPredicate.- Throws:
java.lang.NullPointerException- if c == null
-
doForAll
public static <T> void doForAll(java.util.Collection<T> c, ObjectVisitor<T> v) throws java.lang.IllegalArgumentExceptionPerform an action for all elements in a collection.- Parameters:
c- the collectionv- the visitor defining the action- Throws:
java.lang.IllegalArgumentException- if c == null
-
map
public static <T,U> java.util.List<U> map(java.util.List<T> srcList, java.util.function.Function<T,U> f) throws java.lang.IllegalArgumentExceptionMap 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.- Throws:
java.lang.IllegalArgumentException- if srcList == null
-
mapToSet
public static <T,U> java.util.Set<U> mapToSet(java.util.Collection<T> srcSet, java.util.function.Function<T,U> f) throws java.lang.IllegalArgumentExceptionMap 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.- Throws:
java.lang.IllegalArgumentException- if srcSet == null
-
realloc
public static int[] realloc(int[] data, int newSize) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
objectFieldsToString
public static java.lang.String objectFieldsToString(java.lang.Object obj) throws java.lang.IllegalArgumentExceptionWrite object fields to string- Throws:
java.lang.IllegalArgumentException- if obj == null
-
removePackageName
public static java.lang.String removePackageName(java.lang.String fully_qualified_name_)
Remove the package name from a fully qualified class name
-
intersecting
public static <T> boolean intersecting(java.util.Set<T> s1, java.util.Set<T> s2)checks if two sets have a non-empty intersection- Returns:
trueif the sets intersect;falseotherwise
-
topLevelTypeString
public static java.lang.String topLevelTypeString(java.lang.String typeStr) throws java.lang.IllegalArgumentExceptiongiven 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- Returns:
- String name of top-most enclosing class
- Throws:
java.lang.IllegalArgumentException- if typeStr == null
-
addIfNotNull
public static <T> void addIfNotNull(T val, java.util.Collection<T> vals)
-
getUsedMemory
public static long getUsedMemory()
- Returns:
- the amount of memory currently being used, in bytes. Often inaccurate, but there's no better thing to do from within the JVM.
-
-