| 1 | package fr.sii.ogham.core.convert; | |
| 2 | ||
| 3 | import java.nio.charset.Charset; | |
| 4 | import java.nio.charset.UnsupportedCharsetException; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.exception.convert.ConversionException; | |
| 7 | ||
| 8 | /** | |
| 9 | * Converts a string to a {@link Charset} instance. It uses | |
| 10 | * {@link Charset#forName(String)} to instantiate the charset. | |
| 11 | * | |
| 12 | * | |
| 13 | * @author Aurélien Baudet | |
| 14 | * | |
| 15 | */ | |
| 16 | public class StringToCharsetConverter implements SupportingConverter { | |
| 17 | ||
| 18 | @SuppressWarnings("unchecked") | |
| 19 | @Override | |
| 20 | public <T> T convert(Object source, Class<T> targetType) { | |
| 21 | String charsetName = (String) source; | |
| 22 |
2
1. convert : negated conditional → RUN_ERROR 2. convert : negated conditional → RUN_ERROR |
if (charsetName == null || charsetName.isEmpty()) { |
| 23 | return null; | |
| 24 | } | |
| 25 | try { | |
| 26 |
1
1. convert : replaced return value with null for fr/sii/ogham/core/convert/StringToCharsetConverter::convert → RUN_ERROR |
return (T) Charset.forName(charsetName); |
| 27 | } catch(UnsupportedCharsetException e) { | |
| 28 | throw new ConversionException("Failed to convert "+charsetName+" into Charset", e); | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | @Override | |
| 33 | public boolean supports(Class<?> sourceType, Class<?> targetType) { | |
| 34 |
3
1. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → RUN_ERROR 2. supports : negated conditional → RUN_ERROR 3. supports : negated conditional → RUN_ERROR |
return String.class.isAssignableFrom(sourceType) && Charset.class.isAssignableFrom(targetType); |
| 35 | } | |
| 36 | ||
| 37 | } | |
Mutations | ||
| 22 |
1.1 2.2 |
|
| 26 |
1.1 |
|
| 34 |
1.1 2.2 3.3 |