How to use checkedLongValue method of io.beanmother.core.util.NumberUtils class

Best Beanmother code snippet using io.beanmother.core.util.NumberUtils.checkedLongValue

Source:NumberUtils.java Github

copy

Full Screen

...75 if (targetClass.isInstance(number)) {76 return (T) number;77 }78 else if (Byte.class == targetClass) {79 long value = checkedLongValue(number, targetClass);80 if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {81 raiseOverflowException(number, targetClass);82 }83 return (T) Byte.valueOf(number.byteValue());84 }85 else if (Short.class == targetClass) {86 long value = checkedLongValue(number, targetClass);87 if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {88 raiseOverflowException(number, targetClass);89 }90 return (T) Short.valueOf(number.shortValue());91 }92 else if (Integer.class == targetClass) {93 long value = checkedLongValue(number, targetClass);94 if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {95 raiseOverflowException(number, targetClass);96 }97 return (T) Integer.valueOf(number.intValue());98 }99 else if (Long.class == targetClass) {100 long value = checkedLongValue(number, targetClass);101 return (T) Long.valueOf(value);102 }103 else if (BigInteger.class == targetClass) {104 if (number instanceof BigDecimal) {105 // do not lose precision - use BigDecimal's own conversion106 return (T) ((BigDecimal) number).toBigInteger();107 }108 else {109 // original value is not a Big* number - use standard long conversion110 return (T) BigInteger.valueOf(number.longValue());111 }112 }113 else if (Float.class == targetClass) {114 return (T) Float.valueOf(number.floatValue());115 }116 else if (Double.class == targetClass) {117 return (T) Double.valueOf(number.doubleValue());118 }119 else if (BigDecimal.class == targetClass) {120 // always use BigDecimal(String) here to avoid unpredictability of BigDecimal(double)121 // (see BigDecimal javadoc for details)122 return (T) new BigDecimal(number.toString());123 }124 else if (AtomicInteger.class == targetClass) {125 return (T) new AtomicInteger(number.intValue());126 }127 else if (AtomicLong.class == targetClass) {128 return (T) new AtomicLong(number.longValue());129 }130 else {131 throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" +132 number.getClass().getName() + "] to unsupported target class [" + targetClass.getName() + "]");133 }134 }135 /**136 * Check for a {@code BigInteger}/{@code BigDecimal} long overflow137 * before returning the given number as a long value.138 * @param number the number to convert139 * @param targetClass the target class to convert to140 * @return the long value, if convertible without overflow141 * @throws IllegalArgumentException if there is an overflow142 * @see #raiseOverflowException143 */144 private static long checkedLongValue(Number number, Class<? extends Number> targetClass) {145 BigInteger bigInt = null;146 if (number instanceof BigInteger) {147 bigInt = (BigInteger) number;148 }149 else if (number instanceof BigDecimal) {150 bigInt = ((BigDecimal) number).toBigInteger();151 }152 // Effectively analogous to JDK 8's BigInteger.longValueExact()153 if (bigInt != null && (bigInt.compareTo(LONG_MIN) < 0 || bigInt.compareTo(LONG_MAX) > 0)) {154 raiseOverflowException(number, targetClass);155 }156 return number.longValue();157 }158 /**...

Full Screen

Full Screen

checkedLongValue

Using AI Code Generation

copy

Full Screen

1import io.beanmother.core.util.NumberUtils;2import java.math.BigDecimal;3import java.math.BigInteger;4public class NumberUtilsExample {5 public static void main(String[] args) {6 System.out.println(NumberUtils.checkedLongValue(1));7 System.out.println(NumberUtils.checkedLongValue(1L));8 System.out.println(NumberUtils.checkedLongValue(1.0));9 System.out.println(NumberUtils.checkedLongValue(1.0f));10 System.out.println(NumberUtils.checkedLongValue(1.0d));11 System.out.println(NumberUtils.checkedLongValue(BigInteger.ONE));12 System.out.println(NumberUtils.checkedLongValue(BigDecimal.ONE));13 }14}

Full Screen

Full Screen

checkedLongValue

Using AI Code Generation

copy

Full Screen

1import io.beanmother.core.util.NumberUtils2import io.beanmother.core.converter.Converter3import io.beanmother.core.converter.ConverterModule4import java.lang.reflect.Type5class StringToLongConverter implements Converter<String, Long> {6 Long convert(String source, Type targetType) {7 return NumberUtils.checkedLongValue(source)8 }9}10class StringToLongConverterModule implements ConverterModule {11 void configure() {12 bind(String.class, Long.class).to(StringToLongConverter)13 }14}15import io.beanmother.core.mapper.ObjectMapper16import io.beanmother.core.mapper.ObjectMapperModule17class StringToLongObjectMapper implements ObjectMapper {18 Long map(Object source) {19 return NumberUtils.checkedLongValue(source.toString())20 }21}22class StringToLongObjectMapperModule implements ObjectMapperModule {23 void configure() {24 bind(String, Long).to(StringToLongObjectMapper)25 }26}27import io.beanmother.core.converter.ConverterModule28import io.beanmother.core.mapper.ObjectMapperModule29import io.beanmother.core.mapper.ObjectMapperM

Full Screen

Full Screen

checkedLongValue

Using AI Code Generation

copy

Full Screen

1 [{}]: # (This is a comment)2 [{}]: # (This is another comment)3 [{}]: # (This is a third comment)4 [{}]: # (This is a fourth comment)5 [{}]: # (This is a fifth comment)6 [{}]: # (This is a sixth comment)7 [{}]: # (This is a seventh comment)8 [{}]: # (This is a eighth comment)9 [{}]: # (This is a ninth comment)10 [{}]: # (This is a tenth comment)11 [{}]: # (This is a eleventh comment)12 [{}]: # (This is a twelfth comment)13 [{}]: # (This is a thirteenth comment)14 [{}]: # (This is a fourteenth comment)15 [{}]: # (This is a fifteenth comment)16 [{}]: # (This is a sixteenth comment)17 [{}]: # (This is a seventeenth comment)18 [{}]: # (This is a eighteenth comment)19 [{}]: # (This is a nineteenth comment)20 [{}]: # (This is a twentieth comment)21 [{}]: # (This is a twenty-first comment)22 [{}]: # (This is a twenty-second comment)23 [{}]: # (This is a twenty-third comment)24 [{}]: # (This is a twenty-fourth comment)25 [{}]: # (This is a twenty-fifth comment)26 [{}]: # (This is a twenty-sixth comment)27 [{}]: # (This is a twenty-seventh comment)28 [{}]: # (This is a twenty-eighth comment)29 [{}]: # (This is a twenty-ninth comment)30 [{}]: # (This is a thirtieth comment)31 [{}]: # (This is a thirty-first comment)32 [{}]: # (This is a thirty-second comment)33 [{}]: # (This is a thirty-third comment)34 [{}]: # (This is a thirty-fourth comment)35 [{}]: # (This is a thirty-fifth comment)36 [{}]: # (This is a

Full Screen

Full Screen

checkedLongValue

Using AI Code Generation

copy

Full Screen

1 long longValue = numberUtils.checkedLongValue("1234", 0);2 long longValue2 = numberUtils.checkedLongValue("1234.5", 0);3 long longValue3 = numberUtils.checkedLongValue("abc", 0);4 long longValue4 = numberUtils.checkedLongValue("", 0);5 long longValue5 = numberUtils.checkedLongValue(null, 0);6 long longValue6 = numberUtils.checkedLongValue(" ", 0);7 long longValue7 = numberUtils.checkedLongValue(" 1234", 0);8 long longValue8 = numberUtils.checkedLongValue("1234 ", 0);9 long longValue9 = numberUtils.checkedLongValue(" 1234 ", 0);10 long longValue10 = numberUtils.checkedLongValue(" 1234 5 ", 0);11 long longValue11 = numberUtils.checkedLongValue(" 1234 5 ", 0);12 long longValue12 = numberUtils.checkedLongValue(" 1234.5 ", 0);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Beanmother automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful