|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.geotools.resources.Classes
public final class Classes
A set of miscellaneous methods working on Class
objects.
Field Summary | |
---|---|
static byte |
BOOLEAN
Constants to be used in switch statements. |
static byte |
BYTE
Constants to be used in switch statements. |
static byte |
CHARACTER
Constants to be used in switch statements. |
static byte |
DOUBLE
Constants to be used in switch statements. |
static byte |
FLOAT
Constants to be used in switch statements. |
static byte |
INTEGER
Constants to be used in switch statements. |
static byte |
LONG
Constants to be used in switch statements. |
static byte |
OTHER
Constants to be used in switch statements. |
static byte |
SHORT
Constants to be used in switch statements. |
Method Summary | ||
---|---|---|
static java.lang.Class<?> |
boundOfParameterizedAttribute(java.lang.reflect.Field field)
Returns the upper bounds of the parameterized type of the given attribute. |
|
static java.lang.Class<?> |
boundOfParameterizedAttribute(java.lang.reflect.Method method)
If the given method is a getter or a setter for a parameterized attribute, returns the upper bounds of the parameterized type. |
|
static java.lang.Class<?> |
commonClass(java.util.Collection<?> objects)
Returns the most specific class which is a common parent of all specified objects. |
|
static int |
getBitCount(java.lang.Class<?> type)
Returns the number of bits used by number of the specified type. |
|
static
|
getClass(T object)
Returns the class of the specified object, or null if object is null. |
|
static byte |
getEnumConstant(java.lang.Class<?> type)
Returns one of DOUBLE , FLOAT , LONG , INTEGER ,
SHORT , BYTE , CHARACTER , BOOLEAN or OTHER
constants for the given type. |
|
static java.lang.String |
getShortClassName(java.lang.Object object)
Returns a short class name for the specified object. |
|
static java.lang.String |
getShortName(java.lang.Class<?> classe)
Returns a short class name for the specified class. |
|
static boolean |
isFloat(java.lang.Class<?> type)
Returns true if the given type is a floating point type. |
|
static boolean |
isInteger(java.lang.Class<?> type)
Returns true if the given type is an integer type. |
|
static java.lang.Class<?> |
primitiveToWrapper(java.lang.Class<?> type)
Changes a primitive class to its wrapper (e.g. |
|
static
|
sameInterfaces(java.lang.Class<? extends T> object1,
java.lang.Class<? extends T> object2,
java.lang.Class<T> base)
Returns true if the two specified objects implements exactly the same set of
interfaces. |
|
static java.lang.Class<?> |
specializedClass(java.util.Collection<?> objects)
Returns the most specific class implemented by the objects in the given collection. |
|
static
|
valueOf(java.lang.Class<T> type,
java.lang.String value)
Converts the specified string into a value object. |
|
static java.lang.Class<?> |
wrapperToPrimitive(java.lang.Class<?> type)
Changes a wrapper class to its primitive (e.g. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte DOUBLE
switch
statements.
public static final byte FLOAT
switch
statements.
public static final byte LONG
switch
statements.
public static final byte INTEGER
switch
statements.
public static final byte SHORT
switch
statements.
public static final byte BYTE
switch
statements.
public static final byte CHARACTER
switch
statements.
public static final byte BOOLEAN
switch
statements.
public static final byte OTHER
switch
statements.
Method Detail |
---|
public static java.lang.Class<?> boundOfParameterizedAttribute(java.lang.reflect.Field field)
null
.
This method is typically used for fetching the type of elements in a collection.
We do not provide a method working from a Class
instance because of the
way parameterized types are implemented in Java (by erasure).
Examples: When invoking this method for a field of the type below:
Set<Number>
returns Number.class
.Set<? extends Number>
returns Number.class
as well, since that
collection can not (in theory) contain instances of super-classes; Number
is the upper bound.Set<? super Number>
returns Object.class
, because that collection
is allowed to contain such elements.Set
returns null
because that collection is un-parameterized.
field
- The field for which to obtain the parameterized type.
null
if the given field
is not of a parameterized type.public static java.lang.Class<?> boundOfParameterizedAttribute(java.lang.reflect.Method method)
null
. This method
provides the same semantic than boundOfParameterizedAttribute(Field)
, but
works on a getter or setter method rather then the field. See the javadoc of above
methods for more details.
This method is typically used for fetching the type of elements in a collection.
We do not provide a method working from a Class
instance because of the
way parameterized types are implemented in Java (by erasure).
method
- The getter or setter method for which to obtain the parameterized type.
null
if the given method
do not opperate on an object of a parameterized type.public static <T> java.lang.Class<? extends T> getClass(T object)
null
if object
is null.
This method is also useful for fetching the class of an object known only by its bound
type. As of Java 6, the usual pattern:
doesn't seem to work ifNumber n = 0; Class extends Number> c = n.getClass();
Number
is replaced by a parametirez type T
.
T
- The type of the given object.object
- The object for which to get the class, or null
.
null
if the given object was null.public static java.lang.Class<?> specializedClass(java.util.Collection<?> objects)
objects
- A collection of objects. May contains duplicated values and null values.
public static java.lang.Class<?> commonClass(java.util.Collection<?> objects)
objects
- A collection of objects. May contains duplicated values and null values.
public static <T> boolean sameInterfaces(java.lang.Class<? extends T> object1, java.lang.Class<? extends T> object2, java.lang.Class<T> base)
true
if the two specified objects implements exactly the same set of
interfaces. Only interfaces assignable to base
are compared. Declaration order
doesn't matter. For example in ISO 19111, different interfaces exist for different coordinate
system geometries (CartesianCS
, PolarCS
, etc.). We can check if two
CS implementations has the same geometry with the following code:
if (sameInterfaces(cs1, cs2, CoordinateSystem.class))
T
- A common parent for both objects.object1
- The first object to check for interfaces.object2
- The second object to check for interfaces.base
- The parent of all interfaces to check.
true
if both objects implement the same set of interfaces,
considering only sub-interfaces of base
.public static boolean isFloat(java.lang.Class<?> type)
true
if the given type
is a floating point type.
type
- The type to test (may be null
).
true
if type
is the primitive or wrapper class of
Float
or Double
.public static boolean isInteger(java.lang.Class<?> type)
true
if the given type
is an integer type.
type
- The type to test (may be null
).
true
if type
is the primitive of wrapper class of
Long
, Integer
, Short
or Byte
.public static int getBitCount(java.lang.Class<?> type)
type
- The type (may be null
).
public static java.lang.Class<?> primitiveToWrapper(java.lang.Class<?> type)
int
to Integer
).
If the specified class is not a primitive type, then it is returned unchanged.
type
- The primitive type (may be null
).
public static java.lang.Class<?> wrapperToPrimitive(java.lang.Class<?> type)
Integer
to int
).
If the specified class is not a wrapper type, then it is returned unchanged.
type
- The wrapper type (may be null
).
public static byte getEnumConstant(java.lang.Class<?> type)
DOUBLE
, FLOAT
, LONG
, INTEGER
,
SHORT
, BYTE
, CHARACTER
, BOOLEAN
or OTHER
constants for the given type. This is a commodity for usage in switch
statememnts.
type
- A type (usually either a primitive type or its wrapper).
OTHER
if unknow.public static <T> T valueOf(java.lang.Class<T> type, java.lang.String value) throws java.lang.IllegalArgumentException, java.lang.NumberFormatException
Double
, Float
, Long
, Integer
, Short
, Byte
,
Boolean
, Character
or String
according the specified type. This
method is intentionnaly restricted to primitive types, with the addition of String
which can be though as an identity operation. Other types like File
are
not the purpose of this method.
T
- The requested type.type
- The requested type.value
- the value to parse.
null
if value
was null.
java.lang.IllegalArgumentException
- if type
is not a recognized type.
java.lang.NumberFormatException
- if type
is a subclass of Number
and the
string value is not parseable as a number of the specified type.public static java.lang.String getShortName(java.lang.Class<?> classe)
String
object. It will also name
array according Java language usage, for example "double[]" instead
of "[D".
classe
- The object class (may be null
).
public static java.lang.String getShortClassName(java.lang.Object object)
String
object.
object
- The object (may be null
).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |