|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ckkloverdos.type.java.JavaTypeRegistry
public class JavaTypeRegistry
A JavaType
registry, able to remember type aliases.
Also, in case a primitive type needs to be handled uniformly as its respective
object type (e.g. int
and java.lang.Integer
), then their classes
can be registered with the setRepresentative(Class, Class)
or
setRepresentative(Class, JavaType)
methods. For example:
JavaTypeRegistry r = new JavaTypeRegistry(); r.setRepresentative(int.class, Integer.class);
Representatives must be registered before anything else.
The common practice for an application is to have a singleton registry that internally
uses an instance of JavaTypeRegistry
. ObjectJavaTypes
uses this idiom.
JavaType
,
ObjectJavaTypes
Constructor Summary | |
---|---|
JavaTypeRegistry()
The only constructor. |
Method Summary | |
---|---|
JavaTypeRegistry |
copy()
Returns a new instance having exactly the same mappings maintained by this registry. |
JavaType |
getByClass(java.lang.Class c)
Returns the JavaType wrapping class c . |
JavaType |
getByName(java.lang.String name)
Returns the JavaType for the alias represented by name . |
java.lang.Class |
getRepresentative(java.lang.Class what)
Returns the representative of class what or null if no
representative has been set for class what . |
java.util.Map |
getRepresentatives()
Returns the representatives mapping. |
boolean |
is(java.lang.Class a,
java.lang.Class b)
Checks if the two types are equal, taking representatives into account. |
boolean |
is(java.lang.Class a,
JavaType b)
Checks if the two types are equal, taking representatives into account. |
boolean |
is(java.lang.Class a,
java.lang.String b)
Checks if the two types are equal, taking representatives into account. |
boolean |
is(JavaType a,
JavaType b)
Checks if the two types are equal, taking representatives into account. |
boolean |
is(JavaType a,
java.lang.String b)
Checks if the two types are equal, taking representatives into account. |
JavaType |
register(java.lang.Class c)
Returns the JavaType wrapping class c or creates a new one
if it doesnot exist in the registry. |
JavaType |
register(JavaType javaType)
Registers javaType for the java class it wraps . |
JavaType |
register(java.lang.String alias,
java.lang.Class c)
Registers the alias for the java class c . |
JavaType |
register(java.lang.String alias,
JavaType type)
Registers the alias for the class wrapped by type . |
void |
setRepresentative(java.lang.Class original,
java.lang.Class representative)
Sets representative to be the representative class of original class. |
void |
setRepresentative(java.lang.Class original,
JavaType representativeType)
Sets the java class wrapped by representativeType to be the representative
class of the original class. |
java.lang.String |
toString()
|
void |
toStringAware(ToString ts)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JavaTypeRegistry()
Method Detail |
---|
public void setRepresentative(java.lang.Class original, java.lang.Class representative)
representative
to be the representative class of original
class.
This is usually used for primitive classes and their corresponding object classes.
original
- representative
- public void setRepresentative(java.lang.Class original, JavaType representativeType)
representativeType
to be the representative
class of the original
class.
original
- representativeType
- public java.lang.Class getRepresentative(java.lang.Class what)
what
or null
if no
representative has been set for class what
.
what
- public java.util.Map getRepresentatives()
public JavaType register(java.lang.Class c)
JavaType
wrapping class c
or creates a new one
if it doesnot exist in the registry.
if the class c
has a representative, the JavaType
of its representative is
returned. In any case, if the JavaType
doesnot exist it is created in-place.
c
- public JavaType register(JavaType javaType)
javaType
for the java class it wraps
.
If the wrapped java class has a representative, then javaType
is registered
for the representative instead.
javaType
- public JavaType register(java.lang.String alias, java.lang.Class c)
alias
for the java class c
.
If c
has a representative, then the alias
is registered for the representative instead.
If this alias
registration
is happening before any other registration for class c
, then
a new JavaType
is created for class c
and registered
as well. So, the following code:
r.register("INTEGER", Integer.class)is equivalent to:
r.register(Integer.class) r.register("INTEGER", Integer.class)
alias
- c
-
JavaType
representing the alias
.public JavaType register(java.lang.String alias, JavaType type)
alias
for the class wrapped by type
.
In effect, this is equivalent to register(alias, type.getJavaClass())
.
alias
- type
-
JavaType
created for the alias.public JavaType getByClass(java.lang.Class c)
JavaType
wrapping class c
.
If c
has a representative, then it returns the JavaType
wrapping the representative.
JavaType
or null
if none
is found in the registry.public JavaType getByName(java.lang.String name)
JavaType
for the alias represented by name
.
If the alias refers to a java class that has a representative, then the
representative's JavaType
is returned instead.
JavaType
or null
if none
is found in the registry.public JavaTypeRegistry copy()
public java.lang.String toString()
toString
in class java.lang.Object
public void toStringAware(ToString ts)
toStringAware
in interface IToStringAware
public boolean is(JavaType a, JavaType b)
public boolean is(JavaType a, java.lang.String b)
public boolean is(java.lang.Class a, JavaType b)
public boolean is(java.lang.Class a, java.lang.Class b)
public boolean is(java.lang.Class a, java.lang.String b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |