From 005101b7b1e7579b899c8a379f4516309e164c09 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 20 Jul 2008 22:24:30 +0000 Subject: Added normalization option for BigDecimal properties. --- .../amazon/carbonado/gen/StorableGenerator.java | 4 +- .../carbonado/raw/GenericEncodingStrategy.java | 128 +++++++++++++-------- .../amazon/carbonado/raw/GenericStorableCodec.java | 55 +++++---- 3 files changed, 118 insertions(+), 69 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index e88ba39..0eee3de 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -2732,7 +2732,7 @@ public final class StorableGenerator { LocalVariable encodedVar; try { - encodedVar = encoder.buildSerialEncoding(b, null); + encodedVar = encoder.buildSerialEncoding(b, null, null); } catch (SupportException e) { CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage()); return; @@ -2780,7 +2780,7 @@ public final class StorableGenerator { GenericEncodingStrategy encoder = new GenericEncodingStrategy(mStorableType, null); try { - encoder.buildSerialDecoding(b, null, encodedVar); + encoder.buildSerialDecoding(b, null, null, encodedVar); } catch (SupportException e) { CodeBuilderUtil.throwException(b, SupportException.class, e.getMessage()); return; diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java index c5417c4..e7a8ff9 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java @@ -25,6 +25,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -68,6 +69,26 @@ import com.amazon.carbonado.info.StorablePropertyAdapter; * @author Brian S O'Neill */ public class GenericEncodingStrategy { + /** + * Defines extra encoding options. + * + * @since 1.2 + */ + public static enum Option { + /** + * Access properties by public methods instead of protected fields. + * Option should be used if class being generated doesn't have access + * to these fields. + */ + USE_METHODS, + + /** + * Property values such as BigDecimal are normalized before being + * encoded. + */ + NORMALIZE, + } + private static enum Mode { KEY, DATA, SERIAL } private final Class mType; @@ -144,9 +165,7 @@ public class GenericEncodingStrategy { * of a Storable instance. * @param adapterInstanceClass class containing static references to * adapter instances - defaults to instanceVar - * @param useReadMethods when true, access properties by public read - * methods instead of protected fields - should be used if class being - * generated doesn't have access to these fields + * @param options optional encoding options * @param partialStartVar optional variable for supporting partial key * generation. It must be an int, whose runtime value must be less than the * properties array length. It marks the range start of the partial @@ -167,7 +186,7 @@ public class GenericEncodingStrategy { OrderedProperty[] properties, LocalVariable instanceVar, Class adapterInstanceClass, - boolean useReadMethods, + EnumSet