changeset 168:808c0befc3bd

8080884: Can't serialize ADC, DAC and PWM config objects Summary: Double is substituted by longbits view Reviewed-by: alkonsta
author snazarki
date Thu, 21 May 2015 19:00:33 +0300
parents 30bb431d877e
children 6f4fbf4511c5
files src/share/classes/jdk/dio/adc/ADCChannelConfig.java src/share/classes/jdk/dio/dac/DACChannelConfig.java src/share/classes/jdk/dio/pwm/PWMChannelConfig.java
diffstat 3 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu May 21 13:17:27 2015 +0300
+++ b/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu May 21 19:00:33 2015 +0300
@@ -73,7 +73,8 @@
     private int resolution = UNASSIGNED;
     private int samplingInterval = UNASSIGNED;
     private int samplingTime = UNASSIGNED;
-    private Double scaleFactor = 1.0;
+    // keep scale as longbits view of Double to make the class be friendly for serialization and easy comparizon
+    private long scaleFactor = 0x3FF0000000000000l;// 1.0
     private int inputBufferSize = UNASSIGNED;
 
     /**
@@ -218,7 +219,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            instance.scaleFactor = scaleFactor;
+            instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
 
@@ -447,7 +448,7 @@
      * @since 1.1
      */
     public double getScaleFactor() {
-        return scaleFactor;
+        return Double.longBitsToDouble(scaleFactor);
     }
 
     /**
@@ -478,7 +479,8 @@
             DEFAULT > channelNumber ||
             DEFAULT > resolution || 0 == resolution ||
             DEFAULT > samplingInterval || 0 == samplingInterval ||
-            DEFAULT > samplingTime || 0 == samplingTime) {
+            DEFAULT > samplingTime || 0 == samplingTime ||
+            getScaleFactor() < 0.0) {
             throw new IllegalArgumentException();
         }
     }
--- a/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu May 21 13:17:27 2015 +0300
+++ b/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu May 21 19:00:33 2015 +0300
@@ -70,7 +70,8 @@
     private int controllerNumber = UNASSIGNED;
     private int resolution = UNASSIGNED;
     private int samplingInterval = UNASSIGNED;
-    private Double scaleFactor = 1.0;
+    // keep scale as longbits view of Double to make the class be friendly for serialization and easy comparizon
+    private long scaleFactor = 0x3FF0000000000000l;// 1.0
     private int outputBufferSize = UNASSIGNED;
 
     /**
@@ -198,7 +199,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            instance.scaleFactor = scaleFactor;
+            instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
 
@@ -402,7 +403,7 @@
      * @since 1.1
      */
     public double getScaleFactor() {
-        return scaleFactor;
+        return Double.longBitsToDouble(scaleFactor);
     }
 
    /**
@@ -432,7 +433,8 @@
     private void checkValues() {
         if ((null == controllerName && DEFAULT > controllerNumber) || DEFAULT > channelNumber ||
             DEFAULT > resolution || 0 == resolution ||
-            DEFAULT > samplingInterval || 0 == samplingInterval) {
+            DEFAULT > samplingInterval || 0 == samplingInterval ||
+            getScaleFactor() < 0.0) {
             throw new IllegalArgumentException();
         }
     }
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu May 21 13:17:27 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu May 21 19:00:33 2015 +0300
@@ -91,7 +91,10 @@
     private GPIOPinConfig outputConfig;
     private int idleState = UNASSIGNED;
     private int pulsePeriod = UNASSIGNED;
-    private Double scaleFactor = 1.0;
+
+    // keep scale as longbits view of Double to make the class be friendly for serialization and easy comparizon
+    private long scaleFactor = 0x3FF0000000000000l;// 1.0
+
     private int pulseAlignment = UNASSIGNED;
     private int outputBufferSize = UNASSIGNED;
 
@@ -234,7 +237,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            instance.scaleFactor = scaleFactor;
+            instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
 
@@ -464,7 +467,8 @@
              (idleState != DEFAULT && idleState != IDLE_STATE_HIGH && idleState != IDLE_STATE_LOW) ||
              (pulsePeriod < DEFAULT || pulsePeriod == 0) ||
              (pulseAlignment != DEFAULT && pulseAlignment != ALIGN_CENTER && pulseAlignment != ALIGN_RIGHT && pulseAlignment != ALIGN_LEFT) ||
-             channelNumber < DEFAULT ) {
+             channelNumber < DEFAULT  ||
+             getScaleFactor() < 0.0) {
             throw new IllegalArgumentException();
         }
     }
@@ -605,7 +609,7 @@
      * @since 1.1
      */
     public double getScaleFactor() {
-        return scaleFactor;
+        return Double.longBitsToDouble(scaleFactor);
     }
 
     /**