Skip to content

Commit

Permalink
Minor code readability improvement #2
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 1, 2013
1 parent febe037 commit f31aa60
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,34 @@ public <S, T> Converter<S, T> getConverter(Class<S> source, Class<T> target)
break;
}
}
if (result == null && String.class.equals(target))
{
result = (Converter<S, T>) Converters.TO_STRING;
}
if (result == null && target.isAssignableFrom(source))
{
result = (Converter<S, T>) Converters.NOOP;
}
if (result == null)
{
try
if (String.class.equals(target))
{
result = new MethodConverter<S, T>(source, target, null, target.getMethod("valueOf", source));
result = (Converter<S, T>) Converters.TO_STRING;
}
catch (NoSuchMethodException noValueOf)
else if (target.isAssignableFrom(source))
{
result = (Converter<S, T>) Converters.NOOP;
}
else
{
try
{
result = new ConstructorConverter<S, T>(source, target, target.getConstructor(source));
result = new MethodConverter<S, T>(source, target, null, target.getMethod("valueOf", source));
}
catch (NoSuchMethodException noConstructor)
catch (NoSuchMethodException noValueOf)
{
throw new ConverterNotFoundException(source, target);
try
{
result = new ConstructorConverter<S, T>(source, target, target.getConstructor(source));
}
catch (NoSuchMethodException noConstructor)
{
throw new ConverterNotFoundException(source, target);
}
}

}
}
return result;
Expand Down

0 comments on commit f31aa60

Please sign in to comment.