csli.util
Class A

java.lang.Object
  extended by csli.util.A

public class A
extends Object

Utilities I use so often that naming the class A makes sense.

Author:
Danilo Mirkovic

Constructor Summary
A()
           
 
Method Summary
static String delimitedList(Collection list)
          Builds a properly delimited string from an array or a collection of objects.
static String delimitedList(Collection list, String separator)
           
static String delimitedList(Object[] list)
           
static String delimitedList(Object[] list, String separator)
           
static String delimitedMap(Map map)
           
static String delimitedMap(Map map, String endOfKey, String endOfEntry)
           
static void ensure(boolean b, String message)
          Throw an IllegalStateException if a condition is false.
static void ensureArg(boolean b, String message)
          Same as ensure/assert, only throwing an IllegalArgumentException
static List<String> extractSlotNames(String slottedString)
          Extract a list of slot names from the string of the form "blah [slot1] blah blah [slot2] blah"
static String indent(String text, String head)
          Indent every line in text with string given by head
static
<T> ArrayList<T>
list(T... objs)
          Create an ArrayList from a series or array of parameters.
static Map map()
          Makes a Map of objects.
static Map map(Object k1, Object v1)
           
static Map map(Object k1, Object v1, Object k2, Object v2)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7)
           
static Map map(Object k1, Object v1, Object k2, Object v2, Object k3, Object v3, Object k4, Object v4, Object k5, Object v5, Object k6, Object v6, Object k7, Object v7, Object k8, Object v8, Object k9, Object v9, Object k10, Object v10)
           
static void notNull(List list)
          Ensure that every element of the list is not null.
static void notNull(Object... objs)
          Ensure that every argument is not null.
static List processList(Collection src, UnaryFn f)
          Returns a new list obtained by applying f to each object in src list
static Set processMap(Map src, BinaryFn f)
          Returns a new set obtained by applying f to each key-value pair in src
static Set processSet(Collection src, UnaryFn f)
          Returns a new set obtained by applying f to each object in src
static String quote(String s)
           
static StackTraceElement stackTraceElement(int i)
          Returns the stack trace element i levels above.
static String stripQuotes(String s)
           
static boolean warn(boolean b, String message)
          Issues a warning and prints the stack trace element
static void warn(String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

A

public A()
Method Detail

ensure

public static void ensure(boolean b,
                          String message)
Throw an IllegalStateException if a condition is false. Better than Java assert, since the exception can be caught.

Parameters:
b - condition - we issue a message if it's false
message - message to display if condition is false

ensureArg

public static void ensureArg(boolean b,
                             String message)
Same as ensure/assert, only throwing an IllegalArgumentException

Parameters:
b - condition - we issue a message if it's false
message - message to display if condition is false

notNull

public static void notNull(Object... objs)
Ensure that every argument is not null. If an argument is found to be null, a null-pointer exception is thrown. Call first in fn, better than throwing an NPE down the stack frame.

Parameters:
objs - A var-arg list of objects to check.

notNull

public static void notNull(List list)
Ensure that every element of the list is not null. If an element is found to be null, a null-pointer exception is thrown. Call first in fn, better than throwing an NPE down the stack frame.

Parameters:
list - A list of elements to check.

warn

public static boolean warn(boolean b,
                           String message)
Issues a warning and prints the stack trace element

Parameters:
b - issue a warning if this is true
message - string to show if b is true
Returns:

warn

public static void warn(String message)

stackTraceElement

public static StackTraceElement stackTraceElement(int i)
Returns the stack trace element i levels above. ste(0) returns current function ste, ste(1) the immediate caller etc. Use only for introspection / debugging.


list

public static <T> ArrayList<T> list(T... objs)
Create an ArrayList from a series or array of parameters. Different from Arrays.asList in that it does not create a fixed-size list backed by the passed array.

Parameters:
objs - A variable-length parameter list of objects to be put into the list.
Returns:
A list containing all of the passed-in arguments.
See Also:
java.util.Arrays.asList()

map

public static Map map()
Makes a Map of objects. Must always pass in key, then value, then next key, then next value, etc.


map

public static Map map(Object k1,
                      Object v1)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3,
                      Object k4,
                      Object v4)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3,
                      Object k4,
                      Object v4,
                      Object k5,
                      Object v5)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3,
                      Object k4,
                      Object v4,
                      Object k5,
                      Object v5,
                      Object k6,
                      Object v6)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3,
                      Object k4,
                      Object v4,
                      Object k5,
                      Object v5,
                      Object k6,
                      Object v6,
                      Object k7,
                      Object v7)

map

public static Map map(Object k1,
                      Object v1,
                      Object k2,
                      Object v2,
                      Object k3,
                      Object v3,
                      Object k4,
                      Object v4,
                      Object k5,
                      Object v5,
                      Object k6,
                      Object v6,
                      Object k7,
                      Object v7,
                      Object k8,
                      Object v8,
                      Object k9,
                      Object v9,
                      Object k10,
                      Object v10)

processList

public static List processList(Collection src,
                               UnaryFn f)
Returns a new list obtained by applying f to each object in src list


processSet

public static Set processSet(Collection src,
                             UnaryFn f)
Returns a new set obtained by applying f to each object in src


processMap

public static Set processMap(Map src,
                             BinaryFn f)
Returns a new set obtained by applying f to each key-value pair in src


stripQuotes

public static String stripQuotes(String s)

quote

public static String quote(String s)

extractSlotNames

public static List<String> extractSlotNames(String slottedString)
Extract a list of slot names from the string of the form "blah [slot1] blah blah [slot2] blah"


delimitedList

public static String delimitedList(Collection list)
Builds a properly delimited string from an array or a collection of objects. You can pass a custom delimiter, or use a comma as default. If an object is null or "", it is skipped, and doesn't get on the list.

Parameters:
list - array or a collection of objects
separator - a list separators, by default ","
Returns:
a properly delimited list, could be empty but not null

delimitedList

public static String delimitedList(Object[] list)

delimitedList

public static String delimitedList(Collection list,
                                   String separator)

delimitedList

public static String delimitedList(Object[] list,
                                   String separator)

delimitedMap

public static String delimitedMap(Map map)
Parameters:
slotMappings -
Returns:

delimitedMap

public static String delimitedMap(Map map,
                                  String endOfKey,
                                  String endOfEntry)

indent

public static String indent(String text,
                            String head)
Indent every line in text with string given by head

Parameters:
text -
head -
Returns:
indented multi line string