Package com.ibm.wala.util.collections
Class Util
- java.lang.Object
-
- com.ibm.wala.util.collections.Util
-
public class Util extends java.lang.Object
Miscellaneous utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.BitSet
EMPTY_BITSET
The emptyBitSet
.static boolean
FULLY_QUALIFIED_NAMES
Generate 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> void
addIfNotNull(T val, java.util.Collection<T> vals)
static <T> void
doForAll(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 ofc
that are assignable toklass
.static <T> T
find(java.util.Collection<T> c, java.util.function.Predicate<T> p)
Test whether some element of the givenCollection
satisfies the givenPredicate
.static <T> boolean
forAll(java.util.Collection<T> c, java.util.function.Predicate<T> p)
Test whether all elements of the givenCollection
satisfy the givenPredicate
.static <T> boolean
forSome(java.util.Collection<T> c, java.util.function.Predicate<T> p)
Test whether some element of the givenCollection
satisfies the givenPredicate
.static long
getUsedMemory()
static <T> boolean
intersecting(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.String
objectFieldsToString(java.lang.Object obj)
Write object fields to stringstatic int[]
realloc(int[] data, int newSize)
static java.lang.String
removePackageName(java.lang.String fully_qualified_name_)
Remove the package name from a fully qualified class namestatic java.lang.String
str(java.lang.Throwable thrown)
Get aString
representation of aThrowable
.static java.lang.String
topLevelTypeString(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.IllegalArgumentException
Get aString
representation 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 ofc
that are assignable toklass
.
-
forSome
public static <T> boolean forSome(java.util.Collection<T> c, java.util.function.Predicate<T> p) throws java.lang.IllegalArgumentException
Test whether some element of the givenCollection
satisfies 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.IllegalArgumentException
Test whether some element of the givenCollection
satisfies 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.NullPointerException
Test whether all elements of the givenCollection
satisfy 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.IllegalArgumentException
Perform 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.IllegalArgumentException
Map a list: generate a new list with each element mapped. The new list is always anArrayList
; it would have been more precise to usereflection
to 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.IllegalArgumentException
Map a set: generate a new set with each element mapped. The new set is always aHashSet
; it would have been more precise to usereflection
to 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.IllegalArgumentException
Write 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:
true
if the sets intersect;false
otherwise
-
topLevelTypeString
public static java.lang.String topLevelTypeString(java.lang.String typeStr) throws java.lang.IllegalArgumentException
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- 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.
-
-