|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.doolin.util.Utils
public class Utils
Set of utility methods.
| Field Summary | |
|---|---|
static String |
ISO_DATE_FORMAT
ISO format |
static PropertyResolver |
propertyResolver
Property resolver |
| Method Summary | ||
|---|---|---|
static
|
asList(Collection<T> set)
Get a collection has a list. |
|
static String |
asPropertyPath(String... propertyName)
Gets a property path from a list of properties |
|
static Object |
callMethod(Object target,
String methodName,
Object... parameters)
Calls a method using introspection. |
|
static
|
clone(T o)
Duplicates an object using serialization. |
|
static
|
convert(Collection<? extends S> sourceCollection,
Collection<T> targetCollection,
com.google.common.base.Function<S,T> converter)
Converts a collection into another using a converter. |
|
static
|
convert(Collection<? extends S> sourceCollection,
Collection<T> targetCollection,
ItemConverter<S,T> converter)
Deprecated. Use convert(Collection, Collection, Function)
instead |
|
static
|
convertToList(Collection<? extends S> sourceCollection,
com.google.common.base.Function<S,T> function)
Converts a collection to a list using a function. |
|
static
|
convertToList(Collection<? extends S> sourceCollection,
ItemConverter<S,T> converter)
Deprecated. Use Lists.transform(List, com.google.common.base.Function)
instead. |
|
static
|
convertToList(Collection<? extends S> sourceCollection,
String property)
Converts a collection to a list using a PropertyItemConverter. |
|
static
|
convertToSet(Collection<? extends S> sourceCollection,
com.google.common.base.Function<S,T> function)
Converts a collection to a set using a function. |
|
static
|
convertToSet(Collection<? extends S> sourceCollection,
ItemConverter<S,T> converter)
Deprecated. Use convertToSet(Collection, Function) instead |
|
static void |
copyProperties(Object destination,
Object origin)
Copy properties from one bean to the other |
|
static Class<?> |
forClass(String className)
Protected call to Class.forName |
|
static Date |
fromISOFormat(String value)
Parses a date as ISO 8601 |
|
static
|
getAnnotation(Class<?> oClass,
Class<A> aClass)
Get an annotation from the class or from its parent classes |
|
static
|
getAnnotation(Class<A> annotationClass,
Object bean)
Gets an annotation for a type. |
|
static Object |
getConstant(Class<?> type,
String name)
Gets the value for a constant. |
|
static List<Object> |
getProperties(Collection<?> items,
String property)
List of properties for a set of objects |
|
static Object |
getProperty(Object bean,
String property)
Gets a property from a bean |
|
static
|
getPropertyAnnotation(Class<A> annotationClass,
Object bean,
String propertyName)
Gets an annotation for a property. |
|
static PropertyResolver |
getPropertyResolver()
|
|
static URL |
getResource(Class<?> referenceClass,
String path)
Gets a resource URL from a reference class and a resource path. |
|
static
|
newInstance(Class<T> clazz)
Creates a new instance |
|
static
|
newInstance(Class<T> clazz,
Object parameter)
Creates a new instance with a unique parameter in the constructor |
|
static Object |
newInstance(String className)
Creates a new instance of a class given its name. |
|
static Object |
newInstance(String className,
ParameterSet params)
Creates a new instance of a class given its name and a set of properties |
|
static Map<String,String> |
parseQuery(String query)
Parses a query |
|
static Map<String,String> |
parseQuery(URL url)
Parses a URL query |
|
static String |
readTextResource(Class<?> referenceClass,
String path,
String encoding)
Reads a text resource from a reference class and a resource path. |
|
static void |
setProperties(Object o,
ParameterSet params)
Set the properties of an object |
|
static void |
setProperty(Object bean,
String property,
Object value)
Sets a property on a bean |
|
static void |
setPropertyResolver(PropertyResolver propertyResolver)
|
|
static String |
simpleToString(Object o,
String nullString)
|
|
static String |
toISOFormat(Date date)
Formats a date as ISO 8601 format |
|
static Map<String,String> |
toMap(String[] strings)
Converts a sequence of strings to a map. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String ISO_DATE_FORMAT
public static PropertyResolver propertyResolver
| Method Detail |
|---|
public static <T> List<T> asList(Collection<T> set)
set is null,
returns an empty list.
T - Type of items in the setset - Incoming collection
public static String asPropertyPath(String... propertyName)
propertyName - List of properties
public static Object callMethod(Object target,
String methodName,
Object... parameters)
target - Object that holds the method to callmethodName - Method nameparameters - Parameters for the call
public static <T extends Serializable> T clone(T o)
T - Type of the objecto - Object to close
SerializationUtils.clone(Serializable)
public static <S,T> void convert(Collection<? extends S> sourceCollection,
Collection<T> targetCollection,
com.google.common.base.Function<S,T> converter)
S - Types in the source collectionT - Types in the target listsourceCollection - Source collectiontargetCollection - Target collectionconverter - Converter
@Deprecated
public static <S,T> void convert(Collection<? extends S> sourceCollection,
Collection<T> targetCollection,
ItemConverter<S,T> converter)
convert(Collection, Collection, Function)
instead
S - Types in the source collectionT - Types in the target listsourceCollection - Source collectiontargetCollection - Target collectionconverter - Converter
public static <S,T> List<T> convertToList(Collection<? extends S> sourceCollection,
com.google.common.base.Function<S,T> function)
S - Types in the source collectionT - Types in the target listsourceCollection - Source collectionfunction - Transformation function
@Deprecated
public static <S,T> List<T> convertToList(Collection<? extends S> sourceCollection,
ItemConverter<S,T> converter)
Lists.transform(List, com.google.common.base.Function)
instead.
S - Types in the source collectionT - Types in the target listsourceCollection - Source collectionconverter - Converter
public static <S,T> List<T> convertToList(Collection<? extends S> sourceCollection,
String property)
PropertyItemConverter.
S - Types in the source collectionT - Types in the target listsourceCollection - Source collectionproperty - Property to extract from each source item
public static <S,T> Set<T> convertToSet(Collection<? extends S> sourceCollection,
com.google.common.base.Function<S,T> function)
S - Types in the source collectionT - Types in the target setsourceCollection - Source collectionfunction - Transformation function
@Deprecated
public static <S,T> Set<T> convertToSet(Collection<? extends S> sourceCollection,
ItemConverter<S,T> converter)
convertToSet(Collection, Function) instead
S - Types in the source collectionT - Types in the target setsourceCollection - Source collectionconverter - Converter
public static void copyProperties(Object destination,
Object origin)
destination - Destination beanorigin - Origin beanpublic static Class<?> forClass(String className)
Class.forName
className - Class name to get the Class instance from
public static Date fromISOFormat(String value)
throws ParseException
value - ISO8601 date
ParseException - If the value cannot be parsed
public static <A extends Annotation> A getAnnotation(Class<?> oClass,
Class<A> aClass)
A - Annotation typeoClass - Class to search annotation in.aClass - Annotation to search
null if not found.
public static <A extends Annotation> A getAnnotation(Class<A> annotationClass,
Object bean)
A - Type of annotation to look forannotationClass - Annotation classbean - Bean that contains the annotation
null if not defined
public static Object getConstant(Class<?> type,
String name)
type - Type that contains the constantname - Name of the constant
public static List<Object> getProperties(Collection<?> items,
String property)
items - List of objects to loop onproperty - Property to get for each object
public static Object getProperty(Object bean,
String property)
bean - Beanproperty - Property name
public static <A extends Annotation> A getPropertyAnnotation(Class<A> annotationClass,
Object bean,
String propertyName)
A - Type of annotation to look forannotationClass - Annotation classbean - Bean that contains the propertypropertyName - Property name
null if not definedpublic static PropertyResolver getPropertyResolver()
public static URL getResource(Class<?> referenceClass,
String path)
throws net.sf.jstring.LocalizableException
null, the path is computed using
the current class (i.e. the Utils class).
If the URL cannot be accessed, a LocalizableException with code
StringCodes.STRING_ERROR_RESOURCE_NOT_FOUND is thrown.
referenceClass - Reference for the resource pathpath - Resource path from the reference class
net.sf.jstring.LocalizableException - If the URL cannot be foundpublic static <T> T newInstance(Class<T> clazz)
T - Type of the classclazz - Type of the instance to create
public static <T> T newInstance(Class<T> clazz,
Object parameter)
T - Type of the classclazz - Type of the instance to createparameter - Parameter for the constructor
public static Object newInstance(String className)
className - Type name of the instance to create
public static Object newInstance(String className,
ParameterSet params)
className - Type name of the instance to createparams - Parameters to set in the newly created instance
setProperties(Object, ParameterSet),
newInstance(String)public static Map<String,String> parseQuery(String query)
query - Query to parse
null.public static Map<String,String> parseQuery(URL url)
url - URL to parse
null.
public static String readTextResource(Class<?> referenceClass,
String path,
String encoding)
throws net.sf.jstring.LocalizableException
null, the path is computed using
the current class (i.e. the IOUtils class).
If the resource cannot be accessed, a LocalizableException with code
StringCodes.STRING_ERROR_RESOURCE_NOT_FOUND is thrown.
referenceClass - Reference for the resource pathpath - Resource path from the reference classencoding - Encoding of the target resource
net.sf.jstring.LocalizableException - If the resource cannot be found
public static void setProperties(Object o,
ParameterSet params)
o - Object to setparams - Parameters to set in the given object
public static void setProperty(Object bean,
String property,
Object value)
bean - Beanproperty - Property namevalue - Property valuepublic static void setPropertyResolver(PropertyResolver propertyResolver)
public static String simpleToString(Object o,
String nullString)
public static String toISOFormat(Date date)
date - Date to format
public static Map<String,String> toMap(String[] strings)
strings - List of strings
null)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||