public class Util extends Object
Modifier and Type | Field and Description |
---|---|
static BitSet |
EMPTY_BITSET
The empty
BitSet . |
static boolean |
FULLY_QUALIFIED_NAMES
Generate strings with fully qualified names or not
|
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
addIfNotNull(T val,
Collection<T> vals) |
static boolean |
arrayContains(Object[] arr,
Object obj,
int size) |
static int |
binaryLogUp(int n_)
Binary log: finds the smallest power k such that 2^k>=n
|
static int |
binaryLogUp(long n_)
Binary log: finds the smallest power k such that 2^k>=n
|
static void |
clear(BitSet bitSet_)
Clear a
BitSet . |
static <T> void |
doForAll(Collection<T> c_,
ObjectVisitor<T> v_)
Perform an action for all elements in a collection.
|
static BigInteger |
fact(BigInteger n_)
Factorial
|
static double |
fact(double n_)
Factorial on doubles; avoids overflow problems present when using integers.
|
static int |
fact(int n_)
Factorial
|
static long |
fact(long n_)
Factorial
|
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.
|
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
|
static <T> T |
find(Collection<T> c_,
Predicate<T> p_)
Test whether some element of the given
Collection
satisfies the given Predicate . |
static <T> Collection<T> |
findAll(Collection<T> c_,
Predicate<T> p_)
Test whether some element of the given
Collection
satisfies the given Predicate . |
static <T> boolean |
forAll(Collection<T> c_,
Predicate<T> p_)
Test whether all elements of the given
Collection
satisfy the given Predicate . |
static <T> boolean |
forSome(Collection<T> c_,
Predicate<T> p_)
Test whether some element of the given
Collection
satisfies the given Predicate . |
static int |
getInt(Integer i) |
static int |
hashArray(Object[] objs) |
static <T> boolean |
intersecting(Set<T> s1,
Set<T> s2)
checks if two sets have a non-empty intersection
|
static <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 String |
objArrayToString(Object[] o) |
static String |
objArrayToString(Object[] o,
String start,
String end,
String sep) |
static String |
objectFieldsToString(Object obj)
Write object fields to string
|
static <T> List<T> |
pickNAtRandom(List<T> vals,
int n,
long seed) |
static int[] |
realloc(int[] data_,
int newSize_) |
static String |
removeAll(String str_,
String sub_)
Remove all occurrences of a given substring in a given
String |
static String |
removePackageName(String fully_qualified_name_)
Remove the package name from a fully qualified class name
|
static String |
replaceAll(String str_,
String sub_,
String newSub_)
Replace all occurrences of a given substring in a given
String . |
static String |
str(int[] ints_)
Convert an int[] to a
String for printing |
static String |
str(Throwable thrown_)
|
static boolean |
stringContains(String str,
String subStr) |
static String |
topLevelTypeString(String typeStr)
given the name of a class C, returns the name of the top-most enclosing
class of class C.
|
static String |
toStringNull(Object o) |
public static final boolean FULLY_QUALIFIED_NAMES
public static long fact(long n_)
public static BigInteger fact(BigInteger n_)
public static double fact(double n_)
n_
- arg on which to compute factorialdouble
approximation to) factorial of largest
positive integer <= (n_ + epsilon)public static int fact(int n_)
public static int binaryLogUp(int n_)
public static int binaryLogUp(long n_)
public static String objArrayToString(Object[] o, String start, String end, String sep)
public static <T> boolean forSome(Collection<T> c_, Predicate<T> p_)
Collection
satisfies the given Predicate
.public static <T> T find(Collection<T> c_, Predicate<T> p_)
Collection
satisfies the given Predicate
.public static <T> Collection<T> findAll(Collection<T> c_, Predicate<T> p_)
Collection
satisfies the given Predicate
.public static <T> boolean forAll(Collection<T> c_, Predicate<T> p_)
Collection
satisfy the given Predicate
.public static <T> void doForAll(Collection<T> c_, ObjectVisitor<T> v_)
c_
- the collectionv_
- the visitor defining the actionpublic static <T,U> List<U> map(List<T> srcList, Mapper<T,U> mapper_)
ArrayList
; it would have been more precise to use
reflection
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.public static <T> List<T> filter(Collection<T> src_, Predicate<T> pred_)
ArrayList
; it would have been more precise to use
reflection
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.public static <T> void filter(Collection<T> src_, Predicate<T> pred_, List<T> result_)
src_
- collection to be filteredpred_
- the predicateresult_
- the list for the result. assumed to be emptypublic static <T,U> Set<U> mapToSet(Collection<T> srcSet, Mapper<T,U> mapper_)
HashSet
; it would have been more precise to use
reflection
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.public static int[] realloc(int[] data_, int newSize_)
public static String replaceAll(String str_, String sub_, String newSub_)
String
.public static String removeAll(String str_, String sub_)
String
public static String objectFieldsToString(Object obj)
public static String removePackageName(String fully_qualified_name_)
public static int hashArray(Object[] objs)
public static <T> boolean intersecting(Set<T> s1, Set<T> s2)
s1
- s2
- true
if the sets intersect; false
otherwisepublic static int getInt(Integer i)
public static String topLevelTypeString(String typeStr)
typeStr
- public static <T> void addIfNotNull(T val, Collection<T> vals)