temmental
Class TemplateUtils

java.lang.Object
  extended by temmental.TemplateUtils

public class TemplateUtils
extends java.lang.Object

Utilities to create models.


Method Summary
static
<T> java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
convert(java.lang.Iterable<T> items, ConvertFunction<T> function)
          Convert a collection of items to a list of models using the given function.
static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> createList(java.lang.Object... map)
          Creates a list with the given models.
static java.util.Map<java.lang.String,java.lang.Object> createModel(java.lang.Object... map)
          Creates a model: it is an association of key/value pairs.
static
<T> java.util.List<T>
filter(java.lang.Iterable<T> items, ConditionalFunction<T> function)
          Returns a list of items for which the given function is true.
static
<T> java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
filterAndConvert(java.lang.Iterable<T> items, ConditionalConvertFunction<T> function)
          Filter and convert a collection of items to a list of models using the given function.
static java.util.Properties readProperties(java.lang.String propertiesFilePath)
          Reads a properties file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

filter

public static <T> java.util.List<T> filter(java.lang.Iterable<T> items,
                                           ConditionalFunction<T> function)
Returns a list of items for which the given function is true.

Type Parameters:
T - The type of items
Parameters:
items - The collection of items
function - The function to apply on an item. If the result is true, the item is added to the result.
Returns:
a list of items

convert

public static <T> java.util.List<java.util.Map<java.lang.String,java.lang.Object>> convert(java.lang.Iterable<T> items,
                                                                                           ConvertFunction<T> function)
Convert a collection of items to a list of models using the given function.

Type Parameters:
T - The type of items
Parameters:
items - The collection of items
function - The function to use to convert items to models
Returns:
a list of Models

filterAndConvert

public static <T> java.util.List<java.util.Map<java.lang.String,java.lang.Object>> filterAndConvert(java.lang.Iterable<T> items,
                                                                                                    ConditionalConvertFunction<T> function)
Filter and convert a collection of items to a list of models using the given function.

Type Parameters:
T - The type of items
Parameters:
items - The collection of items
function - The function to apply on an item. If the result is true, the item is converted to a model and the model is added to the result.
Returns:
the list of Models

createList

public static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> createList(java.lang.Object... map)
Creates a list with the given models.

Parameters:
map - the collection of models
Returns:
a list of Models

createModel

public static java.util.Map<java.lang.String,java.lang.Object> createModel(java.lang.Object... map)
                                                                    throws TemplateException
Creates a model: it is an association of key/value pairs.

Parameters:
map - a key followed by a value. It is an enumeration, so this implies an even size.
Returns:
the model
Throws:
TemplateException - if there is not an even size of parameters

readProperties

public static java.util.Properties readProperties(java.lang.String propertiesFilePath)
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
Reads a properties file

Parameters:
propertiesFilePath - the path of the properties file
Returns:
a Properties object
Throws:
java.io.FileNotFoundException - if the file is not found
java.io.IOException - if the file can not be read