changeset 184:551d3edd1fcf

8086059: PWM: PWMChannelConfig.Builder.setOutputConfig() IllegalArgumentException should be thrown if direction is set to DIR_INPUT_ONLY or DIR_BOTH_INIT_INPUT Summary: Added verification to Builder methods Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Tue, 09 Jun 2015 16:44:00 +0300
parents 60ec35bb6d26
children 60b4d01ae4eb
files src/share/classes/jdk/dio/pwm/PWMChannelConfig.java
diffstat 1 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Tue Jun 09 16:19:20 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Tue Jun 09 16:44:00 2015 +0300
@@ -137,7 +137,6 @@
          * @return a new initialized {@code PWMChannelConfig} instance.
          */
         public PWMChannelConfig build() {
-            instance.checkParameters();
             return instance;
         }
 
@@ -164,6 +163,7 @@
          */
         public Builder setChannelNumber(int channelNumber) {
             instance.channelNumber = channelNumber;
+            instance.checkParameters();
             return this;
         }
 
@@ -178,6 +178,7 @@
          */
         public Builder setControllerNumber(int controllerNumber) {
             instance.controllerNumber = controllerNumber;
+            instance.checkParameters();
             return this;
         }
 
@@ -193,6 +194,7 @@
          */
         public Builder setOutputConfig(GPIOPinConfig outputConfig) {
             instance.outputConfig = outputConfig;
+            instance.checkParameters();
             return this;
         }
 
@@ -207,6 +209,7 @@
          */
         public Builder setIdleState(int idleState) {
             instance.idleState = idleState;
+            instance.checkParameters();
             return this;
         }
 
@@ -225,6 +228,7 @@
          */
         public Builder setPulsePeriod(int pulsePeriod) {
             instance.pulsePeriod = pulsePeriod;
+            instance.checkParameters();
             return this;
         }
 
@@ -238,6 +242,7 @@
          */
         public Builder setScaleFactor(double scaleFactor) {
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
+            instance.checkParameters();
             return this;
         }
 
@@ -252,6 +257,7 @@
          */
         public Builder setPulseAlignment(int pulseAlignment) {
             instance.pulseAlignment = pulseAlignment;
+            instance.checkParameters();
             return this;
         }
 
@@ -267,6 +273,7 @@
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
             instance.outputBufferSize = outputBufferSize;
+            instance.checkParameters();
             return this;
         }
     }
@@ -463,12 +470,16 @@
     }
 
     private void checkParameters(){
-        if ( (controllerNumber  < DEFAULT) ||
-             (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  ||
-             getScaleFactor() < 0.0) {
+        if ( (controllerNumber  < UNASSIGNED) ||
+             (idleState != UNASSIGNED && idleState != IDLE_STATE_HIGH && idleState != IDLE_STATE_LOW) ||
+             (pulsePeriod < UNASSIGNED || pulsePeriod == 0) ||
+             (pulseAlignment != UNASSIGNED && pulseAlignment != ALIGN_CENTER && pulseAlignment != ALIGN_RIGHT && pulseAlignment != ALIGN_LEFT) ||
+             channelNumber < UNASSIGNED  ||
+             getScaleFactor() < 0.0 ||
+             (outputConfig != null && outputConfig.getDirection() != GPIOPinConfig.DIR_OUTPUT_ONLY
+                    && outputConfig.getDirection() != GPIOPinConfig.DIR_BOTH_INIT_OUTPUT) ||
+             (outputBufferSize < UNASSIGNED)
+            ) {
             throw new IllegalArgumentException();
         }
     }