package silentium.commons.configuration.transformers; import silentium.commons.configuration.PropertyTransformer; import silentium.commons.configuration.TransformationException; import java.lang.reflect.Field; /** * Transfomrs string to integer. Integer can be represented both as decimal or hex value. * * @author SoulKeeper */ public class IntegerTransformer implements PropertyTransformer<Integer> { /** * Shared instance of this transformer. It's thread-safe so no need of multiple instances */ public static final IntegerTransformer SHARED_INSTANCE = new IntegerTransformer(); /** * Transforms value to integer * * @param value value that will be transformed * @param field value will be assigned to this field * @return Integer object that represents value * @throws TransformationException if something went wrong */ @Override public Integer transform(final String value, final Field field) throws TransformationException { try { return Integer.decode(value); } catch (Exception e) { throw new TransformationException(e); } } }