Package com.ibm.wala.util.collections
Class Util
- java.lang.Object
-
- com.ibm.wala.util.collections.Util
-
public class Util extends Object
Miscellaneous utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static 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, Collection<T> vals)
static <T> void
doForAll(Collection<T> c, ObjectVisitor<T> v)
Perform an action for all elements in a collection.static <S,T>
Set<T>filterByType(Iterable<S> c, Class<T> klass)
Return those elements ofc
that are assignable toklass
.static <T> T
find(Collection<T> c, Predicate<T> p)
Test whether some element of the givenCollection
satisfies the givenPredicate
.static <T> boolean
forAll(Collection<T> c, Predicate<T> p)
Test whether all elements of the givenCollection
satisfy the givenPredicate
.static <T> boolean
forSome(Collection<T> c, Predicate<T> p)
Test whether some element of the givenCollection
satisfies the givenPredicate
.static long
getUsedMemory()
static <T> boolean
intersecting(Set<T> s1, Set<T> s2)
checks if two sets have a non-empty intersectionstatic <T,U>
List<U>map(List<T> srcList, Function<T,U> f)
Map a list: generate a new list with each element mapped.static <T,U>
Set<U>mapToSet(Collection<T> srcSet, Function<T,U> f)
Map a set: generate a new set with each element mapped.static String
objectFieldsToString(Object obj)
Write object fields to stringstatic int[]
realloc(int[] data, int newSize)
static String
removePackageName(String fully_qualified_name_)
Remove the package name from a fully qualified class namestatic String
str(Throwable thrown)
static String
topLevelTypeString(String typeStr)
given the name of a class C, returns the name of the top-most enclosing class of class C.
-
-
-
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
-
str
public static String str(Throwable thrown) throws IllegalArgumentException
- Throws:
IllegalArgumentException
- if thrown == null
-
filterByType
public static <S,T> Set<T> filterByType(Iterable<S> c, Class<T> klass)
Return those elements ofc
that are assignable toklass
.
-
forSome
public static <T> boolean forSome(Collection<T> c, Predicate<T> p) throws IllegalArgumentException
Test whether some element of the givenCollection
satisfies the givenPredicate
.- Throws:
IllegalArgumentException
- if c == null
-
find
public static <T> T find(Collection<T> c, Predicate<T> p) throws IllegalArgumentException
Test whether some element of the givenCollection
satisfies the givenPredicate
.- Returns:
- The first element satisfying the predicate; otherwise null.
- Throws:
IllegalArgumentException
- if c == null
-
forAll
public static <T> boolean forAll(Collection<T> c, Predicate<T> p) throws NullPointerException
Test whether all elements of the givenCollection
satisfy the givenPredicate
.- Throws:
NullPointerException
- if c == null
-
doForAll
public static <T> void doForAll(Collection<T> c, ObjectVisitor<T> v) throws IllegalArgumentException
Perform an action for all elements in a collection.- Parameters:
c
- the collectionv
- the visitor defining the action- Throws:
IllegalArgumentException
- if c == null
-
map
public static <T,U> List<U> map(List<T> srcList, Function<T,U> f) throws 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:
IllegalArgumentException
- if srcList == null
-
mapToSet
public static <T,U> Set<U> mapToSet(Collection<T> srcSet, Function<T,U> f) throws 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:
IllegalArgumentException
- if srcSet == null
-
realloc
public static int[] realloc(int[] data, int newSize) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
objectFieldsToString
public static String objectFieldsToString(Object obj) throws IllegalArgumentException
Write object fields to string- Throws:
IllegalArgumentException
- if obj == null
-
removePackageName
public static String removePackageName(String fully_qualified_name_)
Remove the package name from a fully qualified class name
-
intersecting
public static <T> boolean intersecting(Set<T> s1, Set<T> s2)
checks if two sets have a non-empty intersection- Returns:
true
if the sets intersect;false
otherwise
-
topLevelTypeString
public static String topLevelTypeString(String typeStr) throws 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:
IllegalArgumentException
- if typeStr == null
-
addIfNotNull
public static <T> void addIfNotNull(T val, 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.
-
-