|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.jparam.conversion.converters.AbstractConverter
Field Summary | |
(package private) ScalarConversionWeight |
conversionWeight
|
(package private) java.lang.Class |
sourceClass
the source and target classes, and conversion weight, subclasses must initialize these in order to index the converter correctly |
(package private) java.lang.Class |
targetClass
|
Constructor Summary | |
AbstractConverter()
|
Method Summary | |
java.lang.Object |
convert(java.lang.Object o)
Perform the conversion of the given object to the expected target class, if for some reason the conversion fails (or if the source/target objects do not match the expected classes), an exception should be thrown |
protected abstract boolean |
converterEquals(IConverter o)
Tests if this converter is equal to the given converter, all validity checks of source/target/weight and class instance are performed in the equal method, the derived class can perform all casts with
no verification
The check must verify equality, and not similarity meaning to converters
performing the same conversion with the same weight are not necesarily
equal, for instance two conversion paths from the same source to the same
target but not through the same types, will cause ambiguity if not equal |
boolean |
equals(java.lang.Object obj)
Verify all trivial tests, and let subclass to specific verification only |
java.lang.Class |
getSourceClass()
Return the Class object the converter expects the source to
be instanceof |
java.lang.Class |
getTargetClass()
Return the Class object the target object will be instanceof |
ScalarConversionWeight |
getWeight()
Return the scalar weight of this converter, if this is a concatenated converter, its weight should include the weight of all of its subconverters |
int |
hashCode()
|
protected abstract java.lang.Object |
internalConvert(java.lang.Object o)
Internal conversion method, all subclasses must implement the actual conversion logic here |
java.lang.String |
toConversionString()
Return a string representation of the conversion process only, no additional data, this output will be used when ambiguity is detected in order to give the user meaningfull error messages An ambiguity output would be: |
java.lang.String |
toString()
A more programatically meaningfull description of the conversion, it should show at least the weight of the conversion and possibly more data for example: A path conversion string could look like: |
Methods inherited from class java.lang.Object |
|
Methods inherited from interface net.sourceforge.jparam.conversion.converters.IConverter |
update |
Field Detail |
java.lang.Class sourceClass
java.lang.Class targetClass
ScalarConversionWeight conversionWeight
Constructor Detail |
public AbstractConverter()
Method Detail |
public java.lang.Class getTargetClass()
IConverter
Class
object the target object will be instanceofgetTargetClass
in interface IConverter
net.sourceforge.jparam.conversion.converters.IConverter
Class
public ScalarConversionWeight getWeight()
IConverter
getWeight
in interface IConverter
net.sourceforge.jparam.conversion.converters.IConverter
public java.lang.Class getSourceClass()
IConverter
Class
object the converter expects the source to
be instanceofgetSourceClass
in interface IConverter
net.sourceforge.jparam.conversion.converters.IConverter
Class
public java.lang.Object convert(java.lang.Object o) throws JParamException
IConverter
convert
in interface IConverter
net.sourceforge.jparam.conversion.converters.IConverter
o
- the source object (should be instance of getSourceClass)JParamException
- if for some reason the conversion failedprotected abstract java.lang.Object internalConvert(java.lang.Object o) throws java.lang.Exception
No tests are needed since the given object is of the expected type
o
- An object instanceof getSourceClass
getTargetClass
java.lang.Exception
- If there was an error performing the conversionpublic java.lang.String toString()
IConverter
duck --> archduck --> ducky(USER + TO_PARENT)
An ambigous conversion could look like:
AMBIGOUS( duck -> short -> double duck -> uchar -> double)(USER + PROMOTION)
toString
in interface IConverter
toString
in class java.lang.Object
net.sourceforge.jparam.conversion.converters.IConverter
public java.lang.String toConversionString()
IConverter
duckling -> duck -> short -> int duckling -> duck -> char -> int
Note that there is no additional text or info here
toConversionString
in interface IConverter
net.sourceforge.jparam.conversion.converters.IConverter
protected abstract boolean converterEquals(IConverter o)
equal
method, the derived class can perform all casts with
no verification
The check must verify equality, and not similarity meaning to converters
performing the same conversion with the same weight are not necesarily
equal, for instance two conversion paths from the same source to the same
target but not through the same types, will cause ambiguity if not equalo
- A converter to check for equalitypublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |