fc.util
Class C

java.lang.Object
  extended by fc.util.C

public final class C
extends java.lang.Object

Misc collection related utility methods. Inspired by similar on the web.


Constructor Summary
C()
           
 
Method Summary
static fc.util.C.Entry e(java.lang.Object key, java.lang.Object val)
          Create a map entry to pass to the map method.
static fc.util.C.Entry entry(java.lang.Object key, java.lang.Object val)
          Alias for the e method
static java.util.List list(java.lang.Object... args)
          Create an return a list from the specified args.
static void main(java.lang.String[] args)
           
static java.util.Map map(fc.util.C.Entry... entries)
          Create an return a Map from the specified args.
static java.util.Map map(java.lang.Object... objects)
          Create an return a Map from the specified args, which are treated as key, value pairs in sequence.
static java.util.Set randomNNoDuplicates(java.util.List list, int count)
          Pick NON-duplicate N random items from a list.
static java.util.Set randomNNoDuplicates(java.util.List list, int count, int retries)
          Pick NON-duplicate N random items from a list.
static java.util.Set randomNNoDups(java.util.List list, int count)
          alias for the randomNNoDuplicates(List, int) method
static java.util.Set set(java.lang.Object... args)
          Create an return a Set from the specified args.
static boolean unbox(java.lang.Boolean b)
          unbox and return false if null
static char unbox(java.lang.Character c)
          unbox and return '0' if null
static double unbox(java.lang.Double d)
          unbox and return 0 if null
static int unbox(java.lang.Integer i)
          unbox and return 0 if null
static long unbox(java.lang.Long l)
          unbox and return 0 if null
static short unbox(java.lang.Short s)
          unbox and return 0 if null
static boolean unboxBool(java.lang.Object b)
          unbox and return false if null
static boolean unboxBoolean(java.lang.Object b)
          unbox and return false if null
static char unboxChar(java.lang.Object c)
          unbox and return '0' if null
static double unboxDouble(java.lang.Object d)
          unbox and return 0 if null
static int unboxInt(java.lang.Object i)
          unbox and return 0 if null
static long unboxLong(java.lang.Object i)
          unbox and return 0 if null
static short unboxShort(java.lang.Object s)
          unbox and return 0 if null
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

C

public C()
Method Detail

list

public static java.util.List list(java.lang.Object... args)
Create an return a list from the specified args.


set

public static java.util.Set set(java.lang.Object... args)
Create an return a Set from the specified args.


map

public static java.util.Map map(java.lang.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 java.util.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(java.lang.Object key,
                                    java.lang.Object val)
Alias for the e method


e

public static fc.util.C.Entry e(java.lang.Object key,
                                java.lang.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 java.util.Set randomNNoDuplicates(java.util.List list,
                                                int count)
                                         throws java.lang.IllegalArgumentException
Pick NON-duplicate N random items from a list. If N < 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:
java.lang.IllegalArgumentException

randomNNoDups

public static java.util.Set randomNNoDups(java.util.List list,
                                          int count)
                                   throws java.lang.IllegalArgumentException
alias for the randomNNoDuplicates(List, int) method

Throws:
java.lang.IllegalArgumentException

randomNNoDuplicates

public static java.util.Set randomNNoDuplicates(java.util.List list,
                                                int count,
                                                int retries)
                                         throws java.lang.IllegalArgumentException
Pick NON-duplicate N random items from a list. If N < 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:
java.lang.IllegalArgumentException

unbox

public static short unbox(java.lang.Short s)
unbox and return 0 if null


unboxShort

public static short unboxShort(java.lang.Object s)
unbox and return 0 if null


unbox

public static int unbox(java.lang.Integer i)
unbox and return 0 if null


unboxInt

public static int unboxInt(java.lang.Object i)
unbox and return 0 if null


unbox

public static long unbox(java.lang.Long l)
unbox and return 0 if null


unboxLong

public static long unboxLong(java.lang.Object i)
unbox and return 0 if null


unbox

public static double unbox(java.lang.Double d)
unbox and return 0 if null


unboxDouble

public static double unboxDouble(java.lang.Object d)
unbox and return 0 if null


unbox

public static char unbox(java.lang.Character c)
unbox and return '0' if null


unboxChar

public static char unboxChar(java.lang.Object c)
unbox and return '0' if null


unbox

public static boolean unbox(java.lang.Boolean b)
unbox and return false if null


unboxBool

public static boolean unboxBool(java.lang.Object b)
unbox and return false if null


unboxBoolean

public static boolean unboxBoolean(java.lang.Object b)
unbox and return false if null


main

public static void main(java.lang.String[] args)