public class Boon extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BOON_SYSTEM_CONF_DIR
Sets where Boon looks for config information.
|
| Constructor and Description |
|---|
Boon() |
| Modifier and Type | Method and Description |
|---|---|
static String |
add(String... args)
Adds a bunch of Strings together.
|
static Object |
atIndex(Object value,
String path)
Does path lookupWithDefault.
|
static Object |
call(Object value,
String method)
Facade method over Boon invoker system.
|
static String |
className(Object object)
Gets class name from object.
|
static Class<?> |
cls(Object object)
Gets class name from object.
|
static void |
config(Object... messages)
Like puts but for config logging.
|
static void |
config(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static Logger |
configurableLogger(Class<?> clazz)
Returns a configurable logger.
|
static Logger |
configurableLogger(String name)
Returns a configurable logger.
|
static void |
debug(Object... messages)
Like puts but for debug logging.
|
static void |
debug(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static boolean |
debugOn()
Checks to see if debugging is turned on.
|
static void |
each(Iterable<?> objects,
Object function)
Each is really in Functional.
|
static String |
endSliceOf(String string,
int end) |
static boolean |
equals(Object a,
Object b)
Checks to see if two objects are equal.
|
static boolean |
equalsOrDie(Object expected,
Object got) |
static boolean |
equalsOrDie(String message,
Object expected,
Object got) |
static void |
error(Object... messages)
Like puts but for error logging.
|
static void |
error(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static void |
fatal(Object... messages)
Like puts but for fatal logging.
|
static void |
fatal(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static Object |
fromJson(String value)
Helper method to quickly convert JSON into a Java object.
|
static <T> T |
fromJson(String value,
Class<T> clazz)
Helper method to quickly convert JSON into a Java object.
|
static <T> List<T> |
fromJsonArray(String value,
Class<T> clazz)
converts JSON into strongly typed list
|
static String |
gets()
Gets input from console.
|
static String |
handlebars(String template,
Object context)
Creates Handlebars style template results from string template and context
|
static boolean |
hasSysProp(String propertyName) |
static void |
info(Object... messages)
Like puts but for info logging.
|
static void |
info(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static boolean |
isArray(Object obj) |
static boolean |
isEmpty(Object object) |
static boolean |
isStringArray(Object obj) |
static Iterator |
iterator(Object o) |
static String |
joinBy(char delim,
Collection<?> collection)
Join by for collection.
|
static String |
joinBy(char delim,
Iterable<?> iterable)
Join by for iterable.
|
static String |
joinBy(char delim,
Object... args)
Join by for array.
|
static Object |
jsonResource(java.nio.file.Path path)
Load JSON object as resource
Looks in file system.
|
static Object |
jsonResource(String path)
Load JSON object as resource
Looks in file system first and then classpath.
|
static Object |
jsonResourceFromTemplate(java.nio.file.Path path,
Object context)
Load JSON object as resource but first applies the template to the JSON file.
|
static Object |
jsonResourceFromTemplate(String path,
Object context)
Load JSON object as resource but first applies the template to the JSON file.
|
static String |
jstl(String template,
Object context)
Creates JSTL/JSP style template results from string template and context
Facade over boon template system.
|
static int |
len(Object obj) |
static boolean |
logDebugOn()
Is logging debug on?
|
static Logger |
logger(Class<?> clazz)
Returns a logger.
|
static Logger |
logger(String name)
Returns a logger.
|
static boolean |
logInfoOn()
Is logging info on?
|
static boolean |
logTraceOn()
Is logging info on?
|
static List<?> |
mapBy(Iterable<?> objects,
Object function)
Map by which is really contained in Lists
|
static void |
pressEnterKey()
Used by console apps.
|
static void |
pressEnterKey(String pressEnterKeyMessage)
Press enter to continue.
|
static void |
print(Object message)
Print a single object to the console.
|
static void |
print(String message)
Prints to console.
|
static void |
println()
Adds a newline to the console.
|
static void |
println(Object message)
Prints an object to the console.
|
static void |
println(String message)
Prints a simple message to the console.
|
static void |
putc(Object context,
Object... messages)
Like puts, but prints out a whole slew of objects on the same
line using the template if the message is a character sequence.
|
static void |
puth(Object context,
Object... messages)
Like puts, but prints out a whole slew of objects on the same
line using the template if the message is a character sequence.
|
static void |
putl(Object... messages)
Like puts but prints out each object on its own line.
|
static void |
puts(Object... messages)
Like print, but prints out a whole slew of objects on the same line.
|
static void |
putSysProp(String propertyName,
Object value) |
static Context |
readConfig()
Searches a set of well known directories (explained below)
and classpath for resources denoted by the path.
|
static Context |
readConfig(String namespace,
String path)
Searches a set of well known directories (explained below)
and classpath for resources denoted by the path.
|
static Context |
readConfig(String namespace,
String path,
String... roots)
Reads a configuration context from many possible roots.
|
static String |
resource(java.nio.file.Path path)
Loads a resource from the file system or classpath if not found.
|
static String |
resource(String path)
Loads a resource from the file system or classpath if not found.
|
static String |
resourceFromHandleBarsTemplate(java.nio.file.Path path,
Object context)
Load a resource and apply the given template against it.
|
static String |
resourceFromHandleBarsTemplate(String path,
Object context)
Load a resource and apply the given template against it.
|
static String |
resourceFromTemplate(java.nio.file.Path path,
Object context)
Load a resource and apply the given template against it.
|
static String |
resourceFromTemplate(String path,
Object context)
Load a resource and apply the given template against it.
|
static List<?> |
resourceList(java.nio.file.Path path)
Load JSON list as resource .
|
static <T> List<T> |
resourceList(java.nio.file.Path path,
Class<T> listOf)
Load JSON list as resource .
|
static List<?> |
resourceList(String path)
Load JSON list as resource .
|
static <T> List<T> |
resourceList(String path,
Class<T> listOf)
Load JSON list as resource .
|
static <T> List<T> |
resourceListFromTemplate(java.nio.file.Path path,
Class<T> listOf,
Object context)
Load JSON list as resource .
|
static List<?> |
resourceListFromTemplate(java.nio.file.Path path,
Object context)
Load JSON list as resource.
|
static <T> List<T> |
resourceListFromTemplate(String path,
Class<T> listOf,
Object context)
Load JSON list as resource .
|
static List<?> |
resourceListFromTemplate(String path,
Object context)
Load JSON list as resource.
|
static Map<String,Object> |
resourceMap(java.nio.file.Path path)
Load JSON object as resource but first applies the template to the JSON file.
|
static Map<String,Object> |
resourceMap(String path)
Load JSON Map as resource but first applies the template to the JSON file.
|
static Map<String,Object> |
resourceMapFromTemplate(java.nio.file.Path path,
Object context)
Load JSON map as resource but first applies the template to the JSON file.
|
static Map<String,Object> |
resourceMapFromTemplate(String path,
Object context)
Load JSON object as resource but first applies the template to the JSON file.
|
static <T> T |
resourceObject(java.nio.file.Path path,
Class<T> type)
Load JSON object as resource.
|
static <T> T |
resourceObject(String path,
Class<T> type)
Load JSON list as resource.
|
static <T> T |
resourceObjectFromTemplate(java.nio.file.Path path,
Class<T> type,
Object context)
Load JSON object as resource but first applies the template to the JSON file.
|
static <T> T |
resourceObjectFromTemplate(String path,
Class<T> type,
Object context)
Load JSON list as resource but first applies the template to the JSON file.
|
static boolean |
respondsTo(Object object,
String method)
Checks to see if an object responds to a method.
|
static String |
simpleName(Object object)
Gets simple class name from object.
|
static String |
sliceOf(String string,
int start) |
static String |
sliceOf(String string,
int start,
int stop)
Common helper method for string slice.
|
static CharBuf |
sputl(CharBuf buf,
Object... messages)
Writes to a char buf.
|
static String |
sputl(Object... messages)
like putl but writes to a string.
|
static CharBuf |
sputs(CharBuf buf,
Object... messages)
Like puts but writes to a CharBuf.
|
static String |
sputs(Object... messages)
Like puts but writes to a String.
|
static StringBuilder |
sputs(StringBuilder buf,
Object... messages) |
static String |
stringAtIndex(Object value,
String path)
Gets the string value of an object path.
|
static String |
sysProp(String propertyName,
Object defaultValue)
Quickly grab a system property.
|
static String |
toJson(Object value)
Helper method to quickly convert a Java object into JSON.
|
static String |
toPrettyJson(Object object) |
static String |
toPrettyJsonWithTypes(Object object) |
static void |
trace(Object... messages)
Like puts but for trace logging.
|
static void |
trace(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
static void |
turnDebugOff()
Turns debugging off.
|
static void |
turnDebugOn()
Turns debugging on.
|
static void |
warn(Object... messages)
Like puts but for warn logging.
|
static void |
warn(Throwable t,
Object... messages)
Like puts but for warn exception logging.
|
public static final String BOON_SYSTEM_CONF_DIR
public static boolean equals(Object a, Object b)
a - b - public static void println(String message)
message - string to print.public static void println()
public static void println(Object message)
message - object to print.public static void print(String message)
message - public static void print(Object message)
message - the object that you wish to print.public static void puts(Object... messages)
messages - objects you want to print on the same line.public static void putc(Object context, Object... messages)
messages - objects you want to print on the same line.public static void puth(Object context, Object... messages)
messages - objects you want to print on the same line.public static void putl(Object... messages)
Like puts but prints out each object on its own line. If the object is a list or array, then each item in the list gets printed out on its own line.
messages - the stuff you want to print out.public static String sputl(Object... messages)
messages - the stuff you want to print out.public static String sputs(Object... messages)
messages - the stuff you want to print out.public static CharBuf sputl(CharBuf buf, Object... messages)
buf - char bufmessages - messagespublic static CharBuf sputs(CharBuf buf, Object... messages)
buf - char bufmessages - messages to write.public static StringBuilder sputs(StringBuilder buf, Object... messages)
public static boolean isArray(Object obj)
public static boolean isStringArray(Object obj)
public static int len(Object obj)
public static String joinBy(char delim, Collection<?> collection)
public static List<?> mapBy(Iterable<?> objects, Object function)
objects - objects to mapfunction - function to use for mappingpublic static void each(Iterable<?> objects, Object function)
objects - function - public static String toJson(Object value)
value - Java objectpublic static Object fromJson(String value)
value - JSON contentpublic static <T> T fromJson(String value, Class<T> clazz)
value - JSON contentclazz - type you want to convert the JSON topublic static <T> List<T> fromJsonArray(String value, Class<T> clazz)
T - Tvalue - valueclazz - classpublic static Object atIndex(Object value, String path)
value - value to readpath - property path to read from valuepublic static String gets()
public static String jstl(String template, Object context)
template - templatecontext - context that the template usespublic static String handlebars(String template, Object context)
template - templatecontext - context that the template usespublic static String stringAtIndex(Object value, String path)
value - object valuepath - property path to read from valuepublic static Object call(Object value, String method)
value - object valuemethod - method you want to invoke on the object valuepublic static String sliceOf(String string, int start, int stop)
string - string you want to slicestart - start locationstop - end locationpublic static Context readConfig(String namespace, String path)
Searches a set of well known directories (explained below) and classpath for resources denoted by the path.
If the namespace is foo.bar.dev and the path is /myapp/conf/ Then by defaults this searches for json files with matching namespaces in:
/etc/myapp/conf/*.json
~./fooBarDev/myapp/conf/*.json
classpath://myapp/conf/*.json
The path can refer to a single JSON file or a directory of JSON files for configuration.
/etc/ is called the SYSTEM CONFIG DIR. You can change this by setting the system property
In order for the JSON file to be read, its META map namespace must match this namespace.
namespace - namespace to load.path - path to find config files.public static Context readConfig(String namespace, String path, String... roots)
namespace - namespace to load.path - path to find config files.roots - roots to find paths.public static String sysProp(String propertyName, Object defaultValue)
propertyName - property valuedefaultValue - default value if not found.public static boolean hasSysProp(String propertyName)
public static Context readConfig()
Searches a set of well known directories (explained below) and classpath for resources denoted by the path.
If the namespace is foo.bar.dev and the path is /myapp/conf/ Then by defaults this searches for json files with matching namespaces in:
/etc/myapp/conf/*.json
~./fooBarDev/myapp/conf/*.json
classpath://myapp/conf/*.json
The path can refer to a single JSON file or a directory of JSON files for configuration.
/etc/ is called the SYSTEM CONFIG DIR. You can change this by setting the system property
In order for the JSON file to be read, its META map namespace must match this namespace.
The name space and search path is specified by BOON.APP.NAMESPACE and BOON.APP.CONFIG.PATH
This allows you to configure the namespace and path as a command JVM argument.public static void pressEnterKey(String pressEnterKeyMessage)
pressEnterKeyMessage - public static void pressEnterKey()
public static boolean respondsTo(Object object, String method)
object - object in questionmethod - method name in question.public static String resource(String path)
path - path to resourcepublic static String resource(java.nio.file.Path path)
path - path to resourcepublic static String resourceFromHandleBarsTemplate(String path, Object context)
path - path to resourcecontext - context that the template usespublic static String resourceFromHandleBarsTemplate(java.nio.file.Path path, Object context)
path - path to resourcecontext - context that the template usespublic static String resourceFromTemplate(String path, Object context)
path - path to resourcecontext - context that the template usespublic static String resourceFromTemplate(java.nio.file.Path path, Object context)
path - path to resourcecontext - context that the template usespublic static Object jsonResource(String path)
path - path to resourcepublic static Object jsonResource(java.nio.file.Path path)
path - path to resourcepublic static Object jsonResourceFromTemplate(String path, Object context)
Load JSON object as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first and then classpath.path - path to resourcepublic static Object jsonResourceFromTemplate(java.nio.file.Path path, Object context)
Load JSON object as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system.path - path to resourcepublic static Map<String,Object> resourceMap(String path)
Load JSON Map as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first and then classpath.path - path to resourcepublic static Map<String,Object> resourceMap(java.nio.file.Path path)
Load JSON object as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first.path - path to resourcepublic static Map<String,Object> resourceMapFromTemplate(String path, Object context)
Load JSON object as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first.path - path to resourcepublic static Map<String,Object> resourceMapFromTemplate(java.nio.file.Path path, Object context)
Load JSON map as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first and then classpath.path - path to resourcepublic static <T> T resourceObject(String path, Class<T> type)
Load JSON list as resource.
Looks in file system first and then classpath.path - path to resourcepublic static <T> T resourceObject(java.nio.file.Path path, Class<T> type)
Load JSON object as resource.
Looks in file system.path - path to resourcepublic static <T> T resourceObjectFromTemplate(String path, Class<T> type, Object context)
Load JSON list as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first and then classpath.path - path to resourcepublic static <T> T resourceObjectFromTemplate(java.nio.file.Path path, Class<T> type, Object context)
Load JSON object as resource but first applies the template to the JSON file. LOAD STRING -> RUN TEMPLATE -> JSON PARSE.
Looks in file system first and then classpath.path - path to resourcepublic static List<?> resourceList(String path)
Load JSON list as resource .
Looks in file system first and then classpath.path - path to resourcepublic static List<?> resourceList(java.nio.file.Path path)
Load JSON list as resource .
Looks in file system first.path - path to resourcepublic static <T> List<T> resourceListFromTemplate(String path, Class<T> listOf, Object context)
Load JSON list as resource .
Looks in file system first and then classpath.path - path to resourcepublic static <T> List<T> resourceListFromTemplate(java.nio.file.Path path, Class<T> listOf, Object context)
Load JSON list as resource .
Looks in file system first.path - path to resourcepublic static <T> List<T> resourceList(String path, Class<T> listOf)
Load JSON list as resource .
Looks in file system first and then classpath.path - path to resourcepublic static <T> List<T> resourceList(java.nio.file.Path path, Class<T> listOf)
Load JSON list as resource .
Looks in file system.path - path to resourcepublic static List<?> resourceListFromTemplate(String path, Object context)
Load JSON list as resource.
Looks in file system first and then classpath.path - path to resourcepublic static List<?> resourceListFromTemplate(java.nio.file.Path path, Object context)
Load JSON list as resource.
Looks in file system first and then classpath.path - path to resourcepublic static String className(Object object)
object - class namepublic static Class<?> cls(Object object)
object - class namepublic static String simpleName(Object object)
object - object to get class name frompublic static Logger logger(Class<?> clazz)
clazz - name of logger based on classname.public static Logger logger(String name)
name - name of logger based.public static Logger configurableLogger(String name)
name - name of logger based.public static Logger configurableLogger(Class<?> clazz)
clazz - name of logger based on classname.public static boolean debugOn()
public static void turnDebugOn()
public static void turnDebugOff()
public static boolean logInfoOn()
public static boolean logTraceOn()
public static boolean logDebugOn()
public static void fatal(Object... messages)
messages - messages to write.public static void error(Object... messages)
messages - messages to write.public static void warn(Object... messages)
messages - messages to write.public static void info(Object... messages)
messages - messages to write.public static void debug(Object... messages)
messages - messages to write.public static void trace(Object... messages)
messages - messages to write.public static void config(Object... messages)
messages - messages to write.public static void fatal(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void error(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void warn(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void info(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void config(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void debug(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static void trace(Throwable t, Object... messages)
t - throwablemessages - messages to write.public static boolean isEmpty(Object object)
Copyright © 2015. All Rights Reserved.