MethodsStringConverter.java | MethodsStringConverter.java | |||
---|---|---|---|---|
/* | /* | |||
* Copyright 2010 Stephen Colebourne | * Copyright 2010-2011 Stephen Colebourne | |||
* | * | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | |||
* | * | |||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | |||
* | * | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied . | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied . | |||
skipping to change at line 51 | skipping to change at line 51 | |||
* @param cls the class this converts for, not null | * @param cls the class this converts for, not null | |||
* @param toString the toString method, not null | * @param toString the toString method, not null | |||
* @param fromString the fromString method, not null | * @param fromString the fromString method, not null | |||
* @throws RuntimeException (or subclass) if the method signatures are invalid | * @throws RuntimeException (or subclass) if the method signatures are invalid | |||
*/ | */ | |||
MethodsStringConverter(Class<T> cls, Method toString, Method fromString ) { | MethodsStringConverter(Class<T> cls, Method toString, Method fromString ) { | |||
super(cls, toString); | super(cls, toString); | |||
if (fromString.getParameterTypes().length != 1) { | if (fromString.getParameterTypes().length != 1) { | |||
throw new IllegalStateException("FromString method must have on e parameter"); | throw new IllegalStateException("FromString method must have on e parameter"); | |||
} | } | |||
if (fromString.getParameterTypes()[0] != String.class) { | Class<?> param = fromString.getParameterTypes()[0]; | |||
throw new IllegalStateException("FromString method must take a | if (param != String.class && param != CharSequence.class) { | |||
String"); | throw new IllegalStateException("FromString method must take a | |||
String or CharSequence"); | ||||
} | } | |||
if (fromString.getReturnType().isAssignableFrom(cls) == false) { | if (fromString.getReturnType().isAssignableFrom(cls) == false) { | |||
throw new IllegalStateException("FromString method must return specified class or a superclass"); | throw new IllegalStateException("FromString method must return specified class or a superclass"); | |||
} | } | |||
this.fromString = fromString; | this.fromString = fromString; | |||
} | } | |||
//--------------------------------------------------------------------- -- | //--------------------------------------------------------------------- -- | |||
/** | /** | |||
* Converts the {@code String} to an object. | * Converts the {@code String} to an object. | |||
End of changes. 2 change blocks. | ||||
4 lines changed or deleted | 5 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |