Class Util


  • public class Util
    extends Object
    Miscellaneous utility functions.
    • Field Detail

      • EMPTY_BITSET

        public static final BitSet EMPTY_BITSET
        The empty BitSet.
      • FULLY_QUALIFIED_NAMES

        public static final boolean FULLY_QUALIFIED_NAMES
        Generate strings with fully qualified names or not
        See Also:
        Constant Field Values
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • fact

        public static long fact​(long 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:
        (double approximation 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
      • str

        public static String str​(int[] ints_)
        Convert an int[] to a String for printing
      • objArrayToString

        public static String objArrayToString​(Object[] o)
      • find

        public static <T> T find​(Collection<T> c_,
                                 Predicate<T> p_)
        Test whether some element of the given Collection satisfies the given Predicate.
        Returns:
        The first element satisfying the predicate; otherwise null.
      • doForAll

        public static <T> void doForAll​(Collection<T> c_,
                                        ObjectVisitor<T> v_)
        Perform an action for all elements in a collection.
        Parameters:
        c_ - the collection
        v_ - 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 an 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.
      • 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 an 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.
      • 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 filtered
        pred_ - the predicate
        result_ - 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 a 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.
      • realloc

        public static int[] realloc​(int[] data_,
                                    int newSize_)
      • clear

        public static void clear​(BitSet bitSet_)
        Clear a BitSet.
      • replaceAll

        public static String replaceAll​(String str_,
                                        String sub_,
                                        String newSub_)
        Replace all occurrences of a given substring in a given String.
      • removeAll

        public static String removeAll​(String str_,
                                       String sub_)
        Remove all occurrences of a given substring in a given String
      • 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:
      • arrayContains

        public static boolean arrayContains​(Object[] arr,
                                            Object obj,
                                            int size)
      • toStringNull

        public static String toStringNull​(Object o)
      • 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:
        true if the sets intersect; false otherwise
      • stringContains

        public static boolean stringContains​(String str,
                                             String subStr)
      • 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)
      • pickNAtRandom

        public static <T> List<T> pickNAtRandom​(List<T> vals,
                                                int n,
                                                long seed)