com.univocity.parsers.annotations.helpers
Class AnnotationHelper

java.lang.Object
  extended by com.univocity.parsers.annotations.helpers.AnnotationHelper

public class AnnotationHelper
extends Object

Helper class to process fields annotated with Parsed

Author:
uniVocity Software Pty Ltd - parsers@univocity.com

Method Summary
static boolean allFieldsIndexBased(Class<?> beanClass)
          Runs through all annotations of a given class to identify whether all annotated fields (with the Parsed annotation) are mapped to a column by index.
static boolean allFieldsNameBased(Class<?> beanClass)
          Runs through all annotations of a given class to identify whether all annotated fields (with the Parsed annotation) are mapped to a column by name.
static void applyFormatSettings(Object formatter, String[] propertiesAndValues)
          Applied the configuration of a formatter object (SimpleDateFormat, NumberFormat and others).
static String[] deriveHeaderNamesFromFields(Class<?> beanClass)
          Runs through all Parsed annotations of a given class to identify all header names associated with its fields
static List<Annotation> findAllAnnotationsInPackage(AnnotatedElement annotatedElement, Package aPackage)
          Returns all annotations applied to an element, excluding the ones not in a given package.
static
<A> A
findAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType)
          Searches for an annotation of a given type that's been applied to an element either directly (as a regular annotation) or indirectly (as a meta-annotations, i.e.
static Headers findHeadersAnnotation(Class<?> beanClass)
          Searches for the Headers annotation in the hierarchy of a class
static Map<Field,PropertyWrapper> getAllFields(Class<?> beanClass)
          Returns all fields available from a given class.
static Conversion getConversion(Class classType, Annotation annotation)
          Identifies the proper conversion for a given type and an annotation from the package com.univocity.parsers.annotations
static Conversion getConversion(Field field, Annotation annotation)
          Identifies the proper conversion for a given Field and an annotation from the package com.univocity.parsers.annotations
static Conversion getDefaultConversion(Class fieldType, Parsed parsed)
          Identifies the proper conversion for a given type
static Conversion getDefaultConversion(Field field)
          Returns the default Conversion that should be applied to the field based on its type.
static Integer[] getSelectedIndexes(Class<?> beanClass)
          Runs through all Parsed annotations of a given class to identify all indexes associated with its fields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConversion

public static Conversion getConversion(Field field,
                                       Annotation annotation)
Identifies the proper conversion for a given Field and an annotation from the package com.univocity.parsers.annotations

Parameters:
field - The field to have conversions applied to
annotation - the annotation from com.univocity.parsers.annotations that identifies a Conversion instance.
Returns:
The Conversion that should be applied to the field

getConversion

public static Conversion getConversion(Class classType,
                                       Annotation annotation)
Identifies the proper conversion for a given type and an annotation from the package com.univocity.parsers.annotations

Parameters:
classType - the type to have conversions applied to
annotation - the annotation from com.univocity.parsers.annotations that identifies a Conversion instance.
Returns:
The Conversion that should be applied to the type

getDefaultConversion

public static Conversion getDefaultConversion(Class fieldType,
                                              Parsed parsed)
Identifies the proper conversion for a given type

Parameters:
fieldType - The type of field to have conversions applied to.
parsed - the Parsed annotation from com.univocity.parsers.annotations.
Returns:
The Conversion that should be applied to the field type

getDefaultConversion

public static Conversion getDefaultConversion(Field field)
Returns the default Conversion that should be applied to the field based on its type.

Parameters:
field - The field whose values must be converted from a given parsed String.
Returns:
The default Conversion applied to the given field.

applyFormatSettings

public static void applyFormatSettings(Object formatter,
                                       String[] propertiesAndValues)
Applied the configuration of a formatter object (SimpleDateFormat, NumberFormat and others).

Parameters:
formatter - the formatter instance
propertiesAndValues - a sequence of key-value pairs, where the key is a property of the formatter object to be set to the following value via reflection

allFieldsIndexBased

public static boolean allFieldsIndexBased(Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields (with the Parsed annotation) are mapped to a column by index.

Parameters:
beanClass - a class whose Parsed annotations will be processed.
Returns:
true if every field annotated with Parsed in the given class maps to an index, otherwise false.

allFieldsNameBased

public static boolean allFieldsNameBased(Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields (with the Parsed annotation) are mapped to a column by name.

Parameters:
beanClass - a class whose Parsed annotations will be processed.
Returns:
true if every field annotated with Parsed in the given class maps to a header name, otherwise false.

getSelectedIndexes

public static Integer[] getSelectedIndexes(Class<?> beanClass)
Runs through all Parsed annotations of a given class to identify all indexes associated with its fields

Parameters:
beanClass - a class whose Parsed annotations will be processed.
Returns:
an array of column indexes used by the given class

deriveHeaderNamesFromFields

public static String[] deriveHeaderNamesFromFields(Class<?> beanClass)
Runs through all Parsed annotations of a given class to identify all header names associated with its fields

Parameters:
beanClass - a class whose Parsed annotations will be processed.
Returns:
an array of column names used by the given class

findHeadersAnnotation

public static Headers findHeadersAnnotation(Class<?> beanClass)
Searches for the Headers annotation in the hierarchy of a class

Parameters:
beanClass - the class whose hierarchy will be searched
Returns:
the Headers annotation of the given class or its most immediate parent, or null if not found.

getAllFields

public static Map<Field,PropertyWrapper> getAllFields(Class<?> beanClass)
Returns all fields available from a given class.

Parameters:
beanClass - a class whose fields will be returned.
Returns:
a map of Field and the corresponding PropertyWrapper

findAnnotation

public static <A> A findAnnotation(AnnotatedElement annotatedElement,
                                   Class<A> annotationType)
Searches for an annotation of a given type that's been applied to an element either directly (as a regular annotation) or indirectly (as a meta-annotations, i.e. an annotation that has annotations).

Type Parameters:
A - the type of the annotation being searched for
Parameters:
annotatedElement - the element whose annotations will be searched
annotationType - the type of annotation to search for
Returns:
the annotation associated with the given element, or null if not found.

findAllAnnotationsInPackage

public static List<Annotation> findAllAnnotationsInPackage(AnnotatedElement annotatedElement,
                                                           Package aPackage)
Returns all annotations applied to an element, excluding the ones not in a given package.

Parameters:
annotatedElement - the element (method, field, etc) whose annotations will be extracted
aPackage - the package of the annotations that should be returned
Returns:
the list of annotation elements applied to the given element, that are also members of the given package.


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.