|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||
java.lang.Objectjava.lang.Enum<Primitive>
dk.rode.thesis.meta.util.Primitive
public enum Primitive
A primitive constant associates a primitive type with its wrapper class.
For example, the primitive type int is represented by the
java.lang.Integer.TYPE class, and the associated wrapper class
is the java.lang.Integer class.
The order of declaration is as follows:
| Enum Constant Summary | |
|---|---|
Boolean
Corresponding to the primitive type boolean
(java.lang.Boolean.TYPE) and the non-primitive
wrapper class java.lang.Boolean. |
|
Byte
Corresponding to the primitive type byte
(java.lang.Byte.TYPE) and the non-primitive
wrapper class java.lang.Byte. |
|
Character
Corresponding to the primitive type char
(java.lang.Character.TYPE) and the non-primitive
wrapper class java.lang.Character. |
|
Double
Corresponding to the primitive type double
(java.lang.Double.TYPE) and the non-primitive
wrapper class java.lang.Double. |
|
Float
Corresponding to the primitive type float
(java.lang.Float.TYPE) and the non-primitive
wrapper class java.lang.Float. |
|
Integer
Constant corresponding to the primitive type int,
represented by the java.lang.Integer.TYPE class,
and the non-primitive wrapper class java.lang.Integer. |
|
Long
Corresponding to the primitive type long
(java.lang.Long.TYPE) and the non-primitive
wrapper class java.lang.Long. |
|
Short
Corresponding to the primitive type short
(java.lang.Short.TYPE) and the non-primitive
wrapper class java.lang.Short. |
|
| Field Summary | |
|---|---|
Class<?> |
nonPrimitive
The non-primitive wrapper class associated with this enumeration type. |
Class<?> |
primitive
The primitive type associated with this enumeration type, e.g. |
| Method Summary | ||
|---|---|---|
|
asPrimitive(Object value,
Class<T> type)
Returns the value supplied as value wrapped in the non-primitive
type corresponding to the (primitive) type supplied as type. |
|
protected abstract Object |
asPrimitive(Object value,
Primitive primitive)
Returns the value supplied as value wrapped in the non-primitive
type stored in in primitive. |
|
abstract Object |
getDefaultValue()
Returns the default primitive value of the primitive type associated with this enumeration type, wrapped in a wrapper class. |
|
static Object |
getDefaultValue(Class<?> type)
Returns the default primitive value of the primitive (wrapper) type supplied as type, wrapped in an appropriate wrapper class,
or null if type is neither primitive nor a primitive wrapper
class. |
|
static Map<Class<?>,Class<?>> |
getNonPrimitivesMap()
Returns a Map where the keys are the non-primitive
primitives having an associated primitive type, which is also
the value associated with a key. |
|
static Class<?> |
getNonPrimitiveType(Class<?> type)
Returns the non-primitive type corresponding to the (primitive) type supplied as type, if any. |
|
static Class<?> |
getNonPrimitiveType(Primitive primitive)
Returns the non-primitive type corresponding to the enumeration type supplied as primitive; for example
java.lang.Integer for Integer. |
|
static Class<?>[] |
getNonPrimitiveTypes(Class<?>... primitives)
Returns an array of the non-primitives corresponding to the primitives supplied in primitives. |
|
static Class<?>[] |
getNonPrimitiveTypes(Primitive primitive,
Primitive... primitives)
Returns an array containing the non-primitives corresponding to the enumeration primitives supplied in primitive and primitives. |
|
static Primitive |
getPrimitive(Class<?> type)
Returns the enumeration type corresponding to type,
if any; for example Integer for either
java.lang.Integer or int
(java.lang.Integer.TYPE). |
|
static Map<Class<?>,Class<?>> |
getPrimitivesMap()
Returns a Map where the keys are the primitive
primitives, and the values the associated non-primitives. |
|
static Class<?> |
getPrimitiveType(Class<?> type)
Returns the primitive type corresponding to the type supplied as type, if any. |
|
static Class<?> |
getPrimitiveType(Primitive primitive)
Returns the primitive type corresponding to the enumeration type supplied as primitive; for
example int (java.lang.Integer.TYPE)
for Integer. |
|
static Class<?>[] |
getPrimitiveTypes(Class<?>... primitives)
Returns an array containing the primitives corresponding to the primitives supplied in primitives. |
|
static Class<?>[] |
getPrimitiveTypes(Primitive primitive,
Primitive... primitives)
Returns an array containing the primitives corresponding to the enumeration primitives supplied in primitive and primitives. |
|
boolean |
isAssignableFromIgnorePrimitives(Class<?> type)
Returns true if the non-primitive type of this enumeration type is assignable from the non-primitive type of type. |
|
static boolean |
isAssignableFromIgnorePrimitives(Class<?>[] a,
Class<?>[] b)
Returns true if and only if: a and b are both null or identical (==); or
a and b contains the same number of elements,
and each class in a is assignable from the class in
b at the corresponding index ignoring primitives,
respectively. |
|
static boolean |
isAssignableFromIgnorePrimitives(Class<?> a,
Class<?> b)
Returns true if a is assignable from b when primitive
primitives are ignored. |
|
boolean |
isCompatibleWith(Class<?> type)
Returns true if the type corresponding to type is
compatible with this enumeration type, false if not. |
|
abstract boolean |
isCompatibleWith(Primitive primitive)
Returns true if the type supplied as primitive is
compatible with this enumeration type, false if not. |
|
boolean |
isEqualIgnorePrimitives(Class<?> type)
Returns true if the non-primitive type of type
represents the same non-primitive type as this enumeration type
does, false if not. |
|
static boolean |
isEqualIgnorePrimitives(Class<?>[] a,
Class<?>[] b)
Returns true if and only if: a and b are both null or identical (==); or
a and b contains the same number of elements and
primitives at the same index in a and b have the same
non-primitive type (using equals). |
|
static boolean |
isEqualIgnorePrimitives(Class<?> a,
Class<?> b)
Returns true if and only if: a and b are both null; or
a and b have the same non-primitive
type. |
|
private static Primitive[] |
merge(Primitive primitive,
Primitive... primitives)
Merges primitive with primitives. |
|
static String |
toString(Object object)
Returns the string representing of object that ensures
that arrays of primitives are formatted correctly. |
|
static Primitive |
valueOf(String name)
Returns the enum constant of this type with the specified name. |
|
static Primitive[] |
values()
Returns an array containing the constants of this enum type, in the order they are declared. |
|
| Methods inherited from class java.lang.Enum |
|---|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Enum Constant Detail |
|---|
public static final Primitive Boolean
boolean
(java.lang.Boolean.TYPE) and the non-primitive
wrapper class java.lang.Boolean. This type is compatible with the following primitives:
A value of true will be translated to one (1), and
a value of false will be translated to zero (0).
public static final Primitive Byte
byte
(java.lang.Byte.TYPE) and the non-primitive
wrapper class java.lang.Byte. This type is compatible with the following primitives:
public static final Primitive Character
char
(java.lang.Character.TYPE) and the non-primitive
wrapper class java.lang.Character. This type is compatible with the following primitives:
public static final Primitive Double
double
(java.lang.Double.TYPE) and the non-primitive
wrapper class java.lang.Double. This type is only compatible with itself.
public static final Primitive Float
float
(java.lang.Float.TYPE) and the non-primitive
wrapper class java.lang.Float. This type is compatible with the following primitives:
Note that neither Integer or Long are not compatible,
since the decimal points would then be truncated.
public static final Primitive Integer
int,
represented by the java.lang.Integer.TYPE class,
and the non-primitive wrapper class java.lang.Integer. This type is compatible with the following types:
public static final Primitive Long
long
(java.lang.Long.TYPE) and the non-primitive
wrapper class java.lang.Long. This type is compatible with the following primitives:
public static final Primitive Short
short
(java.lang.Short.TYPE) and the non-primitive
wrapper class java.lang.Short. This type is compatible with the following primitives:
| Field Detail |
|---|
public final Class<?> nonPrimitive
Never null.
public final Class<?> primitive
java.lang.Integer.TYPE for the primitive type int. Never null.
| Method Detail |
|---|
public final <T> T asPrimitive(Object value,
Class<T> type)
value wrapped in the non-primitive
type corresponding to the (primitive) type supplied as type.
value must have the type stored as the non-primitive type for
this enumeration type.
T - The desired type.value - The value; can be null.type - The type as a class literal; cannot be null.
type; can be null.
NullPointerException - If type is null.
IllegalArgumentException - If type is not compatible with
this type, or if value is not null and not an instance of
the non-primitive type of this type.
protected abstract Object asPrimitive(Object value,
Primitive primitive)
value wrapped in the non-primitive
type stored in in primitive.
value - The value; never null and known to be of correct type.primitive - The type to represent value as; never null
and known to be compatible.
public abstract Object getDefaultValue()
public static final Object getDefaultValue(Class<?> type)
type, wrapped in an appropriate wrapper class,
or null if type is neither primitive nor a primitive wrapper
class.
NullPointerException - If type is null.getDefaultValue()public static final Map<Class<?>,Class<?>> getNonPrimitivesMap()
Map where the keys are the non-primitive
primitives having an associated primitive type, which is also
the value associated with a key.
public static final Class<?> getNonPrimitiveType(Class<?> type)
type, if any.
If type is non-primitive, it is simply returned.
type - The type to find the corresponding non-primitive
type for; cannot be null.
NullPointerException - If type is null.public static final Class<?> getNonPrimitiveType(Primitive primitive)
primitive; for example
java.lang.Integer for Integer.
primitive - The primitive; cannot be null.
NullPointerException - If primitive is null.public static final Class<?>[] getNonPrimitiveTypes(Class<?>... primitives)
primitives.
If primitives is null, or has zero length, all non-primitive
primitives having an associated primitive type will be returned. The
order corresponds to the order of the Primitive enumeration.
If primitives is not null, the length of the returned array
is always equal to the length of primitives. primitives
may contain duplicates. Non-primitives are included as is.
The order is maintained in the returned array.
primitives - An array of primitives; can be null.
primitives; never null.
public static final Class<?>[] getNonPrimitiveTypes(Primitive primitive,
Primitive... primitives)
primitive and primitives.
If primitive is null and primitives is null or empty,
the returned array will contain all non-primitives having
an associated primitive type. The order corresponds to the declaration
order of this enumeration.
primitive and primitives may contain duplicates.
The order is maintained in the returned array.
primitive - The first primitive; can be null.primitives - The last primitives; can contain null entries.
primitive and
primitives; never null.public static final Primitive getPrimitive(Class<?> type)
type,
if any; for example Integer for either
java.lang.Integer or int
(java.lang.Integer.TYPE).
type - The type; cannot be null.
NullPointerException - If type is null.public static final Map<Class<?>,Class<?>> getPrimitivesMap()
Map where the keys are the primitive
primitives, and the values the associated non-primitives.
public static final Class<?> getPrimitiveType(Class<?> type)
type, if any. If type
is primitive, it is simply returned. If no such primitive type can be found, null will be returned.
type - The type to find the corresponding primitive
type for; cannot be null.
NullPointerException - If type is null.public static final Class<?> getPrimitiveType(Primitive primitive)
primitive; for
example int (java.lang.Integer.TYPE)
for Integer.
primitive - The primitive; cannot be null.
NullPointerException - If primitive is null.public static final Class<?>[] getPrimitiveTypes(Class<?>... primitives)
primitives.
If primitives is null, or has zero length, all primitive
primitives will be returned. The order corresponds to the order of
the Primitive enumeration.
Primitives having no associated primitive type are ignored, and
primitives may contain duplicates. Primitive primitives are
included as is.
The order is maintained in the returned array.
primitives - An array of primitives; can be null.
primitives; never null.
public static final Class<?>[] getPrimitiveTypes(Primitive primitive,
Primitive... primitives)
primitive and primitives.
If primitive is null and primitives is null or empty,
the returned array will contain all primitives. The order
corresponds to the order of the Primitive enumeration.
primitive and primitives may contain duplicates.
The order is maintained in the returned array.
primitive - The first primitive; can be null.primitives - The last primitives; can contain null entries.
primitive and
primitives; never null.public boolean isAssignableFromIgnorePrimitives(Class<?> type)
type.
type - The type to test; cannot be null.
type, false if
not.
NullPointerException - If type is null.
public static final boolean isAssignableFromIgnorePrimitives(Class<?>[] a,
Class<?>[] b)
a and b are both null or identical (==); or
a and b contains the same number of elements,
and each class in a is assignable from the class in
b at the corresponding index ignoring primitives,
respectively.
a[x] is a Number and b[x] is
int (Integer.TYPE), then the normal assignable test
would fail. Here, int is treated as an Integer, and
the assignable test succeeds.
a - The first array; can be null.b - The second array; can be null.
a is assignable from each class
in b at the same index, respectively, false if not.
NullPointerException - If a or b contains
a null entry.
public static final boolean isAssignableFromIgnorePrimitives(Class<?> a,
Class<?> b)
a is assignable from b when primitive
primitives are ignored.
For example, if a is a Number and b is
int (Integer.TYPE), then the normal assignable test
would fail. Here, int is treated as an Integer, and
the assignable test succeeds.
a - The first type; cannot be null.b - The second type; cannot be null.
a is assignable from b ignoring
primitives, false if not.
NullPointerException - If either argument is null.public boolean isCompatibleWith(Class<?> type)
type is
compatible with this enumeration type, false if not.
The corresponding enumeration type is compatible if an actual
primitive value of this type can be (implicitly) represented by the
corresponding enumeration type without loss of precision. For example,
the primitive int value stored in a java.lang.Integer
wrapper can also be represented by by a java.lang.Long wrapper
without loss of precision.
If the corresponding enumeration type is compatible with this type, it
is safe to invoke asPrimitive(Object, Class) on this type using
type as the second argument.
type - The type to test; cannot be null.
NullPointerException - If type is null.getPrimitive(Class)public abstract boolean isCompatibleWith(Primitive primitive)
primitive is
compatible with this enumeration type, false if not.
primitive is compatible if an actual primitive value of this
type can be (implicitly) represented by primitive without loss
of precision. For example, the primitive int value stored
in a java.lang.Integer wrapper can also be represented by
by a java.lang.Long wrapper without loss of precision.
If primitive is compatible with this type, it is safe to invoke
asPrimitive(Object, Class) on this type the non-primitive type
associated with primitive as the second argument.
primitive - The primitive to test; cannot be null.
NullPointerException - If primitive is null.public boolean isEqualIgnorePrimitives(Class<?> type)
type
represents the same non-primitive type as this enumeration type
does, false if not.
type - The type to test; can be null in which case
false is returned.
public static final boolean isEqualIgnorePrimitives(Class<?>[] a,
Class<?>[] b)
a and b are both null or identical (==); or
a and b contains the same number of elements and
primitives at the same index in a and b have the same
non-primitive type (using equals).
a - The first array; can be null.b - The second array; can be null.
NullPointerException - If a or b contains
a null entry.
public static final boolean isEqualIgnorePrimitives(Class<?> a,
Class<?> b)
a and b are both null; or
a and b have the same non-primitive
type.
a - The first type; can be null.b - The second type; can be null.
private static final Primitive[] merge(Primitive primitive,
Primitive... primitives)
primitive with primitives.
Null Primitive objects are ignored.
primitive - The first primitive; can be null (ignored).primitives - The remaining primitives; can contain null entries (ignored).
Primitive objects;
never null.public static final String toString(Object object)
object that ensures
that arrays of primitives are formatted correctly.
If object is null, the string null is returned.
If the class of object is not an array type, the
object.toString() is returned.
If the class of object is an array and the component type
is primitive, the the proper Arrays.toString(..) method
is invoked, e.g. Arrays.toString(boolean[]) for the
boolean primitive type. If the component type is not primitive, the
Arrays.toString(Object[]) method is used.
object - The object to format into a string; can be null.
public static Primitive valueOf(String name)
name - the name of the enum constant to be returned.
IllegalArgumentException - if this enum type has no constant
with the specified name
NullPointerException - if the argument is nullpublic static Primitive[] values()
for (Primitive c : Primitive.values()) System.out.println(c);
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||