Package eu.simuline.util
Class BasicTypesCompatibilityChecker
- java.lang.Object
-
- eu.simuline.util.BasicTypesCompatibilityChecker
-
public final class BasicTypesCompatibilityChecker extends java.lang.ObjectProvides methods to map basic types to their wrappers, to map wrapper types to the corresponding basic types and for compatibility checks.- Version:
- 1.0
- Author:
- Ernst Reissner
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>>MAP_BASIC_TYPE2WRAPPERMaps basic classes to the corresponding wrapper classes.private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>>MAP_WRAPPER2BASIC_TYPEMaps wrapper classes to the corresponding basic classes.
-
Constructor Summary
Constructors Modifier Constructor Description privateBasicTypesCompatibilityChecker()PreventsBasicTypesCompatibilityCheckerfrom being instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareCompatible(java.lang.Class<?> cls, java.lang.Object obj)Decides whether the given class and object are compatible.static java.lang.Class<?>getWrappedCls(java.lang.Class<?> cls, boolean allowsVoid)Maps a wrapper classclsto wrapped primitive class.static java.lang.Class<?>getWrapperCls(java.lang.Class<?> cls, boolean allowsVoid)Maps a primitive classclsto the corresponding wrapper class.static booleanisPrimitive(java.lang.Class<?> cls)Returns whetherclsrepresents a primitive type.static booleanwrapsPrimitive(java.lang.Class<?> cls)Returns whetherclsrepresents a type wrapping a primitive type.
-
-
-
Field Detail
-
MAP_WRAPPER2BASIC_TYPE
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> MAP_WRAPPER2BASIC_TYPE
Maps wrapper classes to the corresponding basic classes. E.g. Boolean is mapped to boolean. Note thatVoid.TYPEis mapped to itself.- See Also:
areCompatible(Class, Object)
-
MAP_BASIC_TYPE2WRAPPER
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> MAP_BASIC_TYPE2WRAPPER
Maps basic classes to the corresponding wrapper classes. E.g. boolean is mapped to Boolean. Note thatVoid.TYPEis mapped to itself.- See Also:
(Class, Object)
-
-
Method Detail
-
isPrimitive
public static boolean isPrimitive(java.lang.Class<?> cls)
Returns whetherclsrepresents a primitive type. Note that alsoVoid.TYPEis a primitive type. An implementation ofClass.isPrimitive().- Returns:
- Whether
clsrepresents a primitive type. - See Also:
wrapsPrimitive(Class)
-
wrapsPrimitive
public static boolean wrapsPrimitive(java.lang.Class<?> cls)
Returns whetherclsrepresents a type wrapping a primitive type. As an exampleIntegerwrapsintandVoid.TYPEwraps itself.- Returns:
- Whether
clswraps a primitive type. - See Also:
isPrimitive(Class)
-
areCompatible
public static boolean areCompatible(java.lang.Class<?> cls, java.lang.Object obj)Decides whether the given class and object are compatible.- Parameters:
cls- aClass(of course notnull).obj- anObjectincludingnull.- Returns:
trueif and only if either of the following holds:-
clsdoes not refer to a primitive type andobjmay be casted tocls, i.e. if eitherobj == nullor (sequentially)cls.isInstance(obj). -
clsrefers to a primitive type and (sequentially)obj != nullandobj.getClass()is the corresponding wrapper type.
-
- See Also:
MAP_WRAPPER2BASIC_TYPE
-
getWrappedCls
public static java.lang.Class<?> getWrappedCls(java.lang.Class<?> cls, boolean allowsVoid)Maps a wrapper classclsto wrapped primitive class.- Parameters:
cls- someClassobject.allowsVoid- whetherVoid.TYPEis wrapped by itself.- Returns:
- the primitive type wrapped type
clsifclsis the wrapper of a primitive type. Note thatVoid.TYPEmay be wrapped by itself. - Throws:
java.lang.IllegalArgumentException- ifclswraps no primitive type or ifclsisVoid.TYPEbut this is not allowed byallowsVoid.
-
getWrapperCls
public static java.lang.Class<?> getWrapperCls(java.lang.Class<?> cls, boolean allowsVoid)Maps a primitive classclsto the corresponding wrapper class.- Parameters:
cls- someClassobject.allowsVoid- whetherVoid.TYPEwraps itself.- Returns:
- the wrapper type of type
clsifclsis a primitive type. Note thatVoid.TYPEmay wrap itself. - Throws:
java.lang.IllegalArgumentException- ifclsis no primitive type or ifclsisVoid.TYPEbut this is not allowed byallowsVoid.
-
-