it.avutils.jmapper.util
Class GeneralUtility

java.lang.Object
  extended by it.avutils.jmapper.util.GeneralUtility

public final class GeneralUtility
extends Object

Utility class that allows you to identify the type of classes given as input, to obtain name of methods starting from name of fields and more useful functions.

Author:
Alessandro Vurro

Field Summary
static ArrayList<String> basicTypes
          basicTypes contains all the names of primitive and wrapper classes
static String fileSeparator
          file separator of this operating system
static org.apache.commons.collections.bidimap.DualHashBidiMap implementationClass
          implementationClass contains the interfaces names as key and their implementation as value
static String newLine
          line separator of this operating system
 
Method Summary
static
<T extends Collection<E>,E>
T
add(T collection, E... elements)
          Add elements to collection.
static boolean areArrays(Class<?> dClass, Class<?> sClass)
          Returns true if both classes are of Array type, false otherwise.
static boolean areBasic(Class<?> dClass, Class<?> sClass)
          Returns true if both classes are of base type, false otherwise.
static boolean areCollections(Class<?> dClass, Class<?> sClass)
          Returns true if both classes are of Collection type, false otherwise.
static boolean areMaps(Class<?> dClass, Class<?> sClass)
          Returns true if both classes are of Map type, false otherwise.
static boolean collectionIsAssignableFrom(Class<?> aClass)
          Determines if the Collection interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter.
static boolean containsAll(String line, String... elements)
          This method verifies that the line contains all elements.
static
<T> void
enrichList(List<T> aListToEnrich, T[] anArrayToAdd)
          Enriches the specified aListToEnrich parameter with the specified anArrayToAdd parameter.
static String getMethod(Class<?> clazz, String field)
          if clazz is a boolean, this method calls mIs(field), in other cases this method calls the mGet(field)
static boolean isAccessModifier(String str)
          Returns true if str is an access modifier, false otherwise.
static boolean isArray(Class<?> aClass)
          Determines if the specified Class parameter represents an array class.
static boolean isBasic(Class<?> aClass)
          Returns true if aClass is a wrapper or primitive class, false otherwise.
static boolean isStructure(Class<?> aClass)
          Returns true if the specified Class parameter is a Collection, Map or Array, false otherwise.
static boolean listIsAssignableFrom(Class<?> aClass)
          Determines if the List interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter.
static boolean mapIsAssignableFrom(Class<?> aClass)
          Determines if the Map interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter.
static String mGet(String fieldName)
           
static String mIs(String fieldName)
           
static String mSet(String fieldName)
           
static boolean setIsAssignableFrom(Class<?> aClass)
          Determines if the Set interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter.
static boolean sortedSetIsAssignableFrom(Class<?> aClass)
          Determines if the SortedSet interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter.
static
<T> List<T>
toList(T[] anArrayToConvert)
          Returns a list equivalent to the array given as input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newLine

public static final String newLine
line separator of this operating system


fileSeparator

public static final String fileSeparator
file separator of this operating system


implementationClass

public static final org.apache.commons.collections.bidimap.DualHashBidiMap implementationClass
implementationClass contains the interfaces names as key and their implementation as value


basicTypes

public static final ArrayList<String> basicTypes
basicTypes contains all the names of primitive and wrapper classes

Method Detail

isBasic

public static boolean isBasic(Class<?> aClass)
Returns true if aClass is a wrapper or primitive class, false otherwise.

Parameters:
aClass -
Returns:
returns true if aClass is a wrapper or primitive class, false otherwise

isAccessModifier

public static boolean isAccessModifier(String str)
Returns true if str is an access modifier, false otherwise.

Parameters:
str -
Returns:
returns true if str is an access modifier, false otherwise

toList

public static <T> List<T> toList(T[] anArrayToConvert)
Returns a list equivalent to the array given as input.

Parameters:
anArrayToConvert - a generic Array to convert in a List
Returns:
a List

enrichList

public static <T> void enrichList(List<T> aListToEnrich,
                                  T[] anArrayToAdd)
Enriches the specified aListToEnrich parameter with the specified anArrayToAdd parameter.

Parameters:
aListToEnrich - a List to enrich
anArrayToAdd - an array to add

isStructure

public static boolean isStructure(Class<?> aClass)
Returns true if the specified Class parameter is a Collection, Map or Array, false otherwise.

Parameters:
aClass -
Returns:
returns true if the specified Class parameter is a Collection, Map or Array, false otherwise
See Also:
collectionIsAssignableFrom, mapIsAssignableFrom, isArray

areBasic

public static boolean areBasic(Class<?> dClass,
                               Class<?> sClass)
Returns true if both classes are of base type, false otherwise.

Parameters:
dClass - class to analyze
sClass - class to analyze
Returns:
true if both classes are of base type, false otherwise.

areArrays

public static boolean areArrays(Class<?> dClass,
                                Class<?> sClass)
Returns true if both classes are of Array type, false otherwise.

Parameters:
dClass - class to analyze
sClass - class to analyze
Returns:
true if both classes are of Array type, false otherwise.

areCollections

public static boolean areCollections(Class<?> dClass,
                                     Class<?> sClass)
Returns true if both classes are of Collection type, false otherwise.

Parameters:
dClass - class to analyze
sClass - class to analyze
Returns:
true if both classes are of Collection type, false otherwise.

areMaps

public static boolean areMaps(Class<?> dClass,
                              Class<?> sClass)
Returns true if both classes are of Map type, false otherwise.

Parameters:
dClass - class to analyze
sClass - class to analyze
Returns:
true if both classes are of Map type, false otherwise.

collectionIsAssignableFrom

public static boolean collectionIsAssignableFrom(Class<?> aClass)
Determines if the Collection interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

Parameters:
aClass - the Class to be checked
Returns:
the boolean value indicating whether objects of the type aClass can be assigned to objects of Collection interface

mapIsAssignableFrom

public static boolean mapIsAssignableFrom(Class<?> aClass)
Determines if the Map interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

Parameters:
aClass - the Class to be checked
Returns:
the boolean value indicating whether objects of the type aClass can be assigned to objects of Map interface

listIsAssignableFrom

public static boolean listIsAssignableFrom(Class<?> aClass)
Determines if the List interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

Parameters:
aClass - the Class to be checked
Returns:
the boolean value indicating whether objects of the type aClass can be assigned to objects of List interface

setIsAssignableFrom

public static boolean setIsAssignableFrom(Class<?> aClass)
Determines if the Set interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

Parameters:
aClass - the Class to be checked
Returns:
the boolean value indicating whether objects of the type aClass can be assigned to objects of Set interface

sortedSetIsAssignableFrom

public static boolean sortedSetIsAssignableFrom(Class<?> aClass)
Determines if the SortedSet interface is either the same as, or is a superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

Parameters:
aClass - the Class to be checked
Returns:
the boolean value indicating whether objects of the type aClass can be assigned to objects of SortedSet interface

isArray

public static boolean isArray(Class<?> aClass)
Determines if the specified Class parameter represents an array class.

Parameters:
aClass - the Class to be checked
Returns:
true if the specified Class parameter represents an array class; false otherwise.

mGet

public static String mGet(String fieldName)
Parameters:
fieldName -
Returns:
returns a getMethod name of the string given in input

mSet

public static String mSet(String fieldName)
Parameters:
fieldName -
Returns:
returns a setMethod name of the string given in input

mIs

public static String mIs(String fieldName)
Parameters:
fieldName -
Returns:
returns a isMethod name of the string given in input

getMethod

public static String getMethod(Class<?> clazz,
                               String field)
if clazz is a boolean, this method calls mIs(field), in other cases this method calls the mGet(field)

Parameters:
clazz -
field -
Returns:
a get method name of the field
See Also:
mIs(String), mGet(String)

add

public static <T extends Collection<E>,E> T add(T collection,
                                                E... elements)
Add elements to collection.

Parameters:
collection - to enrich
elements - to be added
Returns:
the collection, given in input, enriched

containsAll

public static boolean containsAll(String line,
                                  String... elements)
This method verifies that the line contains all elements.

Parameters:
line - line to check
elements - elements to check
Returns:
true if line contains all elements


Copyright © 2013. All Rights Reserved.