cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/3] cayenne git commit: CAY-2103 cayenne-crypto: support for mapping non-String and non-binary types
Date Fri, 19 Aug 2016 10:21:59 GMT
CAY-2103 cayenne-crypto: support for mapping non-String and non-binary types


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/75925490
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/75925490
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/75925490

Branch: refs/heads/master
Commit: 759254901f43ef1fbf82c0fd5f983d986b599929
Parents: 12d340a
Author: Andrei Tomashpolskiy <nordmann89@gmail.com>
Authored: Fri Aug 19 12:00:27 2016 +0300
Committer: Andrei Tomashpolskiy <nordmann89@gmail.com>
Committed: Fri Aug 19 12:00:27 2016 +0300

----------------------------------------------------------------------
 .../crypto/transformer/value/BigDecimalConverter.java  | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/75925490/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/BigDecimalConverter.java
b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/BigDecimalConverter.java
index cd76b4a..4b13007 100644
--- a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/BigDecimalConverter.java
+++ b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/BigDecimalConverter.java
@@ -13,7 +13,8 @@ public class BigDecimalConverter implements BytesConverter<BigDecimal>
{
 
     public static final BytesConverter<BigDecimal> INSTANCE = new BigDecimalConverter();
 
-    private static final int MIN_BYTES = Integer.BYTES + 1;
+    private static final int INTEGER_BYTES = Integer.SIZE / Byte.SIZE;
+    private static final int MIN_BYTES = INTEGER_BYTES + 1;
 
     static BigDecimal getBigDecimal(byte[] bytes) {
 
@@ -23,8 +24,8 @@ public class BigDecimalConverter implements BytesConverter<BigDecimal>
{
             throw new IllegalArgumentException("byte[] is too small for a BigDecimal value:
" + bytes.length);
         }
 
-        scaleBytes = Arrays.copyOfRange(bytes, 0, Integer.BYTES);
-        unscaledBytes = Arrays.copyOfRange(bytes, Integer.BYTES, bytes.length);
+        scaleBytes = Arrays.copyOfRange(bytes, 0, INTEGER_BYTES);
+        unscaledBytes = Arrays.copyOfRange(bytes, INTEGER_BYTES, bytes.length);
 
         return new BigDecimal(new BigInteger(unscaledBytes), IntegerConverter.getInt(scaleBytes));
     }
@@ -36,9 +37,9 @@ public class BigDecimalConverter implements BytesConverter<BigDecimal>
{
         unscaledBytes = bigDecimal.unscaledValue().toByteArray();
         scaleBytes = IntegerConverter.getBytes(bigDecimal.scale());
 
-        result = new byte[Integer.BYTES + unscaledBytes.length];
-        System.arraycopy(scaleBytes, 0, result, Integer.BYTES - scaleBytes.length, scaleBytes.length);
-        System.arraycopy(unscaledBytes, 0, result, Integer.BYTES, unscaledBytes.length);
+        result = new byte[INTEGER_BYTES + unscaledBytes.length];
+        System.arraycopy(scaleBytes, 0, result, INTEGER_BYTES - scaleBytes.length, scaleBytes.length);
+        System.arraycopy(unscaledBytes, 0, result, INTEGER_BYTES, unscaledBytes.length);
 
         return result;
     }


Mime
View raw message