*/
public class LongPrimitiveTypeConverter implements TypeConverter {
@Override
public Object convert(String value) throws ConversionException {
NumberRadixResult result = NumberRadixUtil.parseNumberRadix(value);
try {
if (result.getRadix() == 16) {
String hex = NumberRadixUtil.normalizeLeadingHexZeroes(result.getNumber(), 16);
byte[] bytes = HexUtil.toByteArray(hex);
return ByteArrayUtil.toLong(bytes);
} else {
// special handling of longs with a TimeUnit ending
TimeUnitUtil.Result timeResult = TimeUnitUtil.parse(result.getNumber());
if (timeResult != null) {
long l = Long.parseLong(timeResult.getNumber());
long ms = TimeUnit.MILLISECONDS.convert(l, timeResult.getTimeUnit());
return ms;
} else {
return Long.parseLong(result.getNumber());
}
}
} catch (NumberFormatException e) {
throw new ConversionException(e.getMessage());
}