Class C

java.lang.Object
fc.util.C

public final class C extends Object
Misc collection related utility methods. Inspired by similar on the web.
  • Constructor Details

    • C

      public C()
  • Method Details

    • list

      public static List list(Object... args)
      Create an return a list from the specified args.
    • set

      public static Set set(Object... args)
      Create an return a Set from the specified args.
    • map

      public static Map map(Object... objects)
      Create an return a Map from the specified args, which are treated as key, value pairs in sequence. Example: Map map = map("a", "hello", "b", 123, "c", new int[] {4,5,6});
    • map

      public static Map map(fc.util.C.Entry... entries)
      Create an return a Map from the specified args. Example: Map map = map(e("a", "hello"), e("b", 123));
    • entry

      public static fc.util.C.Entry entry(Object key, Object val)
      Alias for the e method
    • e

      public static fc.util.C.Entry e(Object key, Object val)
      Create a map entry to pass to the map method. values can be null. The key, value pairs are accessed directly after they are put in the map.
    • randomNNoDuplicates

      public static Set randomNNoDuplicates(List list, int count) throws IllegalArgumentException
      Pick NON-duplicate N random items from a list. If N invalid input: '<' number of unique items in the list, throws a IllegalArgumentException. Also throws a IllegalArgumentException if not able to get unique items after 16 tries (per item). To specify a different retry count (per item), use the variant of this method that takes the retry parameter.
      Parameters:
      count - number (N) items to choose.
      Throws:
      IllegalArgumentException
    • randomNNoDups

      public static Set randomNNoDups(List list, int count) throws IllegalArgumentException
      alias for the randomNNoDuplicates(List, int) method
      Throws:
      IllegalArgumentException
    • randomNNoDuplicates

      public static Set randomNNoDuplicates(List list, int count, int retries) throws IllegalArgumentException
      Pick NON-duplicate N random items from a list. If N invalid input: '<' number of unique items in the list, throws a IllegalArgumentException. Also throws a IllegalArgumentException if not able to get unique items after the specified (per item).
      Parameters:
      count - number (N) items to choose.
      retries - number of retries to get a unique random item before bailing/throwing an Exception
      Throws:
      IllegalArgumentException
    • unbox

      public static short unbox(Short s)
      unbox and return 0 if null
    • unboxShort

      public static short unboxShort(Object s)
      unbox and return 0 if null
    • unbox

      public static int unbox(Integer i)
      unbox and return 0 if null
    • unboxInt

      public static int unboxInt(Object i)
      unbox and return 0 if null
    • unbox

      public static long unbox(Long l)
      unbox and return 0 if null
    • unboxLong

      public static long unboxLong(Object i)
      unbox and return 0 if null
    • unbox

      public static double unbox(Double d)
      unbox and return 0 if null
    • unboxDouble

      public static double unboxDouble(Object d)
      unbox and return 0 if null
    • unbox

      public static char unbox(Character c)
      unbox and return '0' if null
    • unboxChar

      public static char unboxChar(Object c)
      unbox and return '0' if null
    • unbox

      public static boolean unbox(Boolean b)
      unbox and return false if null
    • unboxBool

      public static boolean unboxBool(Object b)
      unbox and return false if null
    • unboxBoolean

      public static boolean unboxBoolean(Object b)
      unbox and return false if null
    • nullOrEmpty

      public static boolean nullOrEmpty(Collection c)
      Returns true if the specified collection is null or empty.
    • main

      public static void main(String[] args)