diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-03-29 17:26:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 17:26:03 +0200 |
commit | 0707de28355fbc6c8d062717c3939ed45e4e561f (patch) | |
tree | 0b32dc5507c307ce021642e422e24e742810a426 /src/main | |
parent | Merge pull request #15 from UnionInternationalCheminsdeFer/maven_dependencies (diff) | |
parent | BigInteger without ValueExact function supported (diff) | |
download | UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar.gz UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar.bz2 UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar.lz UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar.xz UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.tar.zst UIC-barcode-0707de28355fbc6c8d062717c3939ed45e4e561f.zip |
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/uic/barcode/asn1/uper/IntCoder.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java b/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java index 87b561b..5964a64 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/IntCoder.java @@ -223,11 +223,11 @@ class IntCoder implements Encoder, Decoder { } else if (classOfT == BigInteger.class) { return (T) resultValue; } else if (classOfT == Long.class) { - return (T) Long.valueOf(resultValue.longValueExact()); + return (T) bigToLong(resultValue); } else if (classOfT == Integer.class) { - return (T) Integer.valueOf(resultValue.intValueExact()); + return (T) bigToInteger(resultValue); } else if (classOfT == Short.class) { - return (T) Short.valueOf(resultValue.shortValueExact()); + return (T) bigToShort(resultValue); } } catch (Exception e){ UperEncoder.logger.debug(String.format("INTEGER Decoded as %s is too big for data type", resultValue)); @@ -235,6 +235,42 @@ class IntCoder implements Encoder, Decoder { return null; } + private Long bigToLong(BigInteger b) { + + Long l = b.longValue(); + + if (BigInteger.valueOf(l).equals(b)) { + return l; + } else { + throw new ArithmeticException("BigInteger To Long failed"); + } + + } + + private Integer bigToInteger(BigInteger b) { + + Integer l = b.intValue(); + + if (BigInteger.valueOf(l).equals(b)) { + return l; + } else { + throw new ArithmeticException("BigInteger To Integer failed"); + } + + } + + private Short bigToShort(BigInteger b) { + + Short l = b.shortValue(); + + if (BigInteger.valueOf(l).equals(b)) { + return l; + } else { + throw new ArithmeticException("BigInteger To Short failed"); + } + + } + @SuppressWarnings("unchecked") @Override public <T> T getDefault(Class<T> classOfT, Annotation[] extraAnnotations) { |