changeset 191:03997bac2a18

8129109: new GPIOPinConfig.Builder.build() doesn't throw neither IOE nor ISE as specified Summary: Redesigned values check procedures Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Thu, 18 Jun 2015 14:46:23 +0300
parents f1a65e783681
children 4acc8eae476b
files src/share/classes/jdk/dio/gpio/GPIOPinConfig.java
diffstat 1 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Thu Jun 18 14:44:43 2015 +0300
+++ b/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Thu Jun 18 14:46:23 2015 +0300
@@ -134,7 +134,7 @@
     public static final int TRIGGER_RISING_EDGE = 2;
 
     private String controllerName;
-    private int direction;
+    private int direction = UNASSIGNED;
     private boolean initValue;
     private int mode = UNASSIGNED;
     private int pinNumber = UNASSIGNED;
@@ -192,6 +192,10 @@
          * </ul>
          */
         public GPIOPinConfig build() {
+            if (instance.direction == UNASSIGNED) {
+                throw new IllegalStateException(
+                ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_DIRECTION));
+            }
             instance.checkConsistency();
             return instance;
         }
@@ -576,10 +580,7 @@
     }
 
     private void checkDirection() {
-        if (GPIOPinConfig.DIR_INPUT_ONLY != direction
-            && GPIOPinConfig.DIR_OUTPUT_ONLY != direction
-            && GPIOPinConfig.DIR_BOTH_INIT_INPUT != direction
-            && GPIOPinConfig.DIR_BOTH_INIT_OUTPUT != direction) {
+        if (direction < DIR_INPUT_ONLY || direction > DIR_BOTH_INIT_OUTPUT) {
             throw new IllegalArgumentException();
         }
     }
@@ -595,16 +596,7 @@
     }
 
     private void checkTrigger() {
-        switch (trigger) {
-            case GPIOPinConfig.TRIGGER_NONE:
-            case GPIOPinConfig.TRIGGER_FALLING_EDGE:
-            case GPIOPinConfig.TRIGGER_RISING_EDGE:
-            case GPIOPinConfig.TRIGGER_BOTH_EDGES:
-            case GPIOPinConfig.TRIGGER_HIGH_LEVEL:
-            case GPIOPinConfig.TRIGGER_LOW_LEVEL:
-            case GPIOPinConfig.TRIGGER_BOTH_LEVELS:
-                break;
-            default:
+        if (trigger < TRIGGER_NONE || trigger > TRIGGER_BOTH_LEVELS) {
                 throw new IllegalArgumentException();
         }
     }
@@ -612,6 +604,12 @@
     /** check if @see GPIOPinConfig.Builder.build() passed successfully.
     * It differs from checking for setters such as setPinNumber etc. */
     private void checkConsistency() {
+        if (direction == DIR_OUTPUT_ONLY && trigger != TRIGGER_NONE) {
+            throw new IllegalArgumentException(
+                    ExceptionMessage.format(ExceptionMessage.GPIO_TRIGGER_OR_MODE)
+                );
+        }
+
         switch (direction) {
         case GPIOPinConfig.DIR_INPUT_ONLY:
             if (DeviceConfig.DEFAULT != mode &&
@@ -648,7 +646,7 @@
         }
     }
 
-    /** check everuthing for deprecated @see GPIOPinConfig call */
+    /** check everything for deprecated @see GPIOPinConfig call */
     private void checkAll() {
         checkControllerNumber();
         checkPinNumber();