Package org.geotools.util
Class Classes
Object
Classes
A set of miscellaneous methods working on 
Class objects.- Since:
- 2.5
- Author:
- Martin Desruisseaux (IRD)
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.static final byteConstants to be used inswitchstatements.
- 
Method SummaryModifier and TypeMethodDescriptionstatic Class<?>Returns the upper bounds of the parameterized type of the given attribute.static Class<?>boundOfParameterizedAttribute(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 Class<?>commonClass(Collection<?> objects) Returns the most specific class which is a common parent of all specified objects.static intgetBitCount(Class<?> type) Returns the number of bits used by number of the specified type.static <T> Class<? extends T>getClass(T object) Returns the class of the specified object, ornullifobjectis null.static bytegetEnumConstant(Class<?> type) static StringgetShortClassName(Object object) Returns a short class name for the specified object.static StringgetShortName(Class<?> classe) Returns a short class name for the specified class.static booleanReturnstrueif the giventypeis a floating point type.static booleanReturnstrueif the giventypeis an integer type.static Class<?>primitiveToWrapper(Class<?> type) Changes a primitive class to its wrapper (e.g.static <T> booleansameInterfaces(Class<? extends T> object1, Class<? extends T> object2, Class<T> base) Returnstrueif the two specified objects implements exactly the same set of interfaces.static Class<?>specializedClass(Collection<?> objects) Returns the most specific class implemented by the objects in the given collection.static <T> TConverts the specified string into a value object.static Class<?>wrapperToPrimitive(Class<?> type) Changes a wrapper class to its primitive (e.g.
- 
Field Details- 
DOUBLEpublic static final byte DOUBLEConstants to be used inswitchstatements.- See Also:
 
- 
FLOATpublic static final byte FLOATConstants to be used inswitchstatements.- See Also:
 
- 
LONGpublic static final byte LONGConstants to be used inswitchstatements.- See Also:
 
- 
INTEGERpublic static final byte INTEGERConstants to be used inswitchstatements.- See Also:
 
- 
SHORTpublic static final byte SHORTConstants to be used inswitchstatements.- See Also:
 
- 
BYTEpublic static final byte BYTEConstants to be used inswitchstatements.- See Also:
 
- 
CHARACTERpublic static final byte CHARACTERConstants to be used inswitchstatements.- See Also:
 
- 
BOOLEANpublic static final byte BOOLEANConstants to be used inswitchstatements.- See Also:
 
- 
OTHERpublic static final byte OTHERConstants to be used inswitchstatements.- See Also:
 
 
- 
- 
Method Details- 
boundOfParameterizedAttributeReturns the upper bounds of the parameterized type of the given attribute. If the attribute does not have a parameterized type, returnsnull.This method is typically used for fetching the type of elements in a collection. We do not provide a method working from a Classinstance 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.classas well, since that collection can not (in theory) contain instances of super-classes;- Numberis the upper bound.
- Set<? super Number>returns- Object.class, because that collection is allowed to contain such elements.
- Setreturns- nullbecause that collection is un-parameterized.
 - Parameters:
- field- The field for which to obtain the parameterized type.
- Returns:
- The upper bound of parameterized type, or nullif the given field is not of a parameterized type.
 
- 
boundOfParameterizedAttributeIf the given method is a getter or a setter for a parameterized attribute, returns the upper bounds of the parameterized type. Otherwise returnsnull. This method provides the same semantic thanboundOfParameterizedAttribute(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 Classinstance because of the way parameterized types are implemented in Java (by erasure).- Parameters:
- method- The getter or setter method for which to obtain the parameterized type.
- Returns:
- The upper bound of parameterized type, or nullif the given method do not opperate on an object of a parameterized type.
 
- 
getClassReturns the class of the specified object, ornullifobjectis 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(); Numberis replaced by a parametirez typeT.- Type Parameters:
- T- The type of the given object.
- Parameters:
- object- The object for which to get the class, or- null.
- Returns:
- The class of the given object, or nullif the given object was null.
 
- 
specializedClassReturns the most specific class implemented by the objects in the given collection. If no class are assignable to all others, then this method returns the most specific common super class.- Parameters:
- objects- A collection of objects. May contains duplicated values and null values.
- Returns:
- The most specific class.
 
- 
commonClassReturns the most specific class which is a common parent of all specified objects.- Parameters:
- objects- A collection of objects. May contains duplicated values and null values.
- Returns:
- The most specific class common to all supplied objects.
 
- 
sameInterfacespublic static <T> boolean sameInterfaces(Class<? extends T> object1, Class<? extends T> object2, Class<T> base) Returnstrueif the two specified objects implements exactly the same set of interfaces. Only interfaces assignable tobaseare 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))- Type Parameters:
- T- A common parent for both objects.
- Parameters:
- object1- The first object to check for interfaces.
- object2- The second object to check for interfaces.
- base- The parent of all interfaces to check.
- Returns:
- trueif both objects implement the same set of interfaces, considering only sub-interfaces of- base.
 
- 
isFloatReturnstrueif the giventypeis a floating point type.
- 
isIntegerReturnstrueif the giventypeis an integer type.
- 
getBitCountReturns the number of bits used by number of the specified type.- Parameters:
- type- The type (may be- null).
- Returns:
- The number of bits, or 0 if unknow.
 
- 
primitiveToWrapperChanges a primitive class to its wrapper (e.g.inttoInteger). If the specified class is not a primitive type, then it is returned unchanged.- Parameters:
- type- The primitive type (may be- null).
- Returns:
- The type as a wrapper.
 
- 
wrapperToPrimitiveChanges a wrapper class to its primitive (e.g.Integertoint). If the specified class is not a wrapper type, then it is returned unchanged.- Parameters:
- type- The wrapper type (may be- null).
- Returns:
- The type as a primitive.
 
- 
getEnumConstantReturns one ofDOUBLE,FLOAT,LONG,INTEGER,SHORT,BYTE,CHARACTER,BOOLEANorOTHERconstants for the given type. This is a commodity for usage inswitchstatememnts.- Parameters:
- type- A type (usually either a primitive type or its wrapper).
- Returns:
- The constant for the given type, or OTHERif unknow.
 
- 
valueOfpublic static <T> T valueOf(Class<T> type, String value) throws IllegalArgumentException, NumberFormatException Converts the specified string into a value object. The value object can be an instance ofDouble,Float,Long,Integer,Short,Byte,Boolean,CharacterorStringaccording the specified type. This method is intentionnaly restricted to primitive types, with the addition ofStringwhich can be though as an identity operation. Other types likeFileare not the purpose of this method.- Type Parameters:
- T- The requested type.
- Parameters:
- type- The requested type.
- value- the value to parse.
- Returns:
- The value object, or nullifvaluewas null.
- Throws:
- IllegalArgumentException- if- typeis not a recognized type.
- NumberFormatException- if- typeis a subclass of- Numberand the string value is not parseable as a number of the specified type.
 
- 
getShortNameReturns a short class name for the specified class. This method will omit the package name. For example, it will return "String" instead of "java.lang.String" for aStringobject. It will also name array according Java language usage, for example "double[]" instead of "[D".- Parameters:
- classe- The object class (may be- null).
- Returns:
- A short class name for the specified object.
 
- 
getShortClassNameReturns a short class name for the specified object. This method will omit the package name. For example, it will return "String" instead of "java.lang.String" for aStringobject.- Parameters:
- object- The object (may be- null).
- Returns:
- A short class name for the specified object.
 
 
-