changeset 204:622781a8dcaf

8132543: I2CDeviceConfig.Build.er.setAddress(-1, 10) wont throw IAE, build() won't throw ISE if address is not initialized Summary: initialize address and type parameters by UNASSIGNED; Rename deprecated DEFAULT constant as UNASSIGNED Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Wed, 29 Jul 2015 18:06:45 +0300
parents 2146ba8bc43a
children dd3123ec4c0d
files src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java src/share/classes/jdk/dio/counter/PulseCounterConfig.java src/share/classes/jdk/dio/generic/GenericDeviceConfig.java src/share/classes/jdk/dio/gpio/GPIOPinConfig.java src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java src/share/classes/jdk/dio/pwm/PWMChannelConfig.java src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java src/share/classes/jdk/dio/uart/UARTConfig.java src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java
diffstat 9 files changed, 29 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -87,7 +87,7 @@
      *             if {@code controller name} is {@code null}.
      */
     public ATDeviceConfig(String controllerName, int channelNumber) {
-        this(DEFAULT, channelNumber);
+        this(UNASSIGNED, channelNumber);
         // checks for NPE
         controllerName.length();
         this.controllerName = controllerName;
@@ -104,7 +104,7 @@
      *             if {@code channelNumber} is not in the defined range.
      */
     public ATDeviceConfig(int controllerNumber, int channelNumber) {
-        if (DEFAULT > channelNumber || DEFAULT > controllerNumber) {
+        if (UNASSIGNED > channelNumber || UNASSIGNED > controllerNumber) {
             throw new  IllegalArgumentException();
         }
         this.controllerNumber = controllerNumber;
--- a/src/share/classes/jdk/dio/counter/PulseCounterConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/counter/PulseCounterConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -105,7 +105,7 @@
     private GPIOPinConfig sourceConfig;
 
 
-    private int type;
+    private int type = UNASSIGNED;
 
     /**
      * The {@code Builder} class allows for creating and initializing
@@ -329,7 +329,7 @@
      */
     @Deprecated
     public PulseCounterConfig(String controllerName, int channelNumber, int type) {
-        this(DEFAULT, channelNumber, type);
+        this(UNASSIGNED, channelNumber, type);
         // checks for null
         controllerName.length();
         this.controllerName = controllerName;
--- a/src/share/classes/jdk/dio/generic/GenericDeviceConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/generic/GenericDeviceConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -214,7 +214,7 @@
      */
     @Deprecated
     public GenericDeviceConfig(int controllerNumber, int channelNumber) {
-        if (controllerNumber< DEFAULT || channelNumber < DEFAULT) {
+        if (controllerNumber < UNASSIGNED || channelNumber < UNASSIGNED) {
             throw new IllegalArgumentException();
         }
         this.controllerNumber = controllerNumber;
@@ -237,7 +237,7 @@
      */
     @Deprecated
     public GenericDeviceConfig(String controllerName, int channelNumber) {
-        this(DEFAULT, channelNumber);
+        this(UNASSIGNED, channelNumber);
         // NPE check
         controllerName.length();
         this.controllerName = controllerName;
--- a/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -370,7 +370,7 @@
     public GPIOPinConfig(int controllerNumber, int pinNumber, int direction, int mode, int trigger, boolean initValue) {
         this.controllerNumber = controllerNumber;
         this.pinNumber = pinNumber;
-        if (controllerNumber < DeviceConfig.DEFAULT || pinNumber < DeviceConfig.DEFAULT ) {
+        if (controllerNumber < DeviceConfig.UNASSIGNED || pinNumber < DeviceConfig.UNASSIGNED ) {
             throw new IllegalArgumentException();
         }
         this.direction = direction;
@@ -425,7 +425,7 @@
      */
     @Deprecated
     public GPIOPinConfig(String controllerName, int pinNumber, int direction, int mode, int trigger, boolean initValue) {
-        this(DEFAULT, pinNumber, direction, mode, trigger, initValue);
+        this(UNASSIGNED, pinNumber, direction, mode, trigger, initValue);
         controllerName.length();// NPE check
         this.controllerName = controllerName;
     }
@@ -591,7 +591,7 @@
 
         switch (direction) {
         case GPIOPinConfig.DIR_INPUT_ONLY:
-            if (DeviceConfig.DEFAULT != mode &&
+            if (UNASSIGNED != mode &&
                 0 != (mode & ~(GPIOPinConfig.MODE_INPUT_PULL_DOWN | GPIOPinConfig.MODE_INPUT_PULL_UP))) {
                 throw new IllegalArgumentException(
                     ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
@@ -599,7 +599,7 @@
             }
             break;
         case GPIOPinConfig.DIR_OUTPUT_ONLY:
-            if (DeviceConfig.DEFAULT != mode &&
+            if (UNASSIGNED != mode &&
                 0 != (mode & ~(GPIOPinConfig.MODE_OUTPUT_OPEN_DRAIN | GPIOPinConfig.MODE_OUTPUT_PUSH_PULL ))) {
                 throw new IllegalArgumentException(
                     ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
@@ -608,7 +608,7 @@
             break;
         case GPIOPinConfig.DIR_BOTH_INIT_INPUT:
         case GPIOPinConfig.DIR_BOTH_INIT_OUTPUT:
-            if (DeviceConfig.DEFAULT != mode &&
+            if (UNASSIGNED != mode &&
                ((mode != (MODE_INPUT_PULL_DOWN | MODE_OUTPUT_OPEN_DRAIN)) &&
                 (mode != (MODE_INPUT_PULL_DOWN | MODE_OUTPUT_PUSH_PULL)) &&
                 (mode != (MODE_INPUT_PULL_UP   | MODE_OUTPUT_OPEN_DRAIN)) &&
--- a/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -75,7 +75,7 @@
     public static final int ADDR_SIZE_10 = 10;
 
     private String controllerName;
-    private int address;
+    private int address = UNASSIGNED;
     private int addressSize = UNASSIGNED;
     private int controllerNumber = UNASSIGNED;
     private int clockFrequency = UNASSIGNED;
@@ -122,7 +122,7 @@
          * </ul>
          */
         public I2CDeviceConfig build() {
-            if (UNASSIGNED ==instance.address) {
+            if (UNASSIGNED == instance.address) {
                 throw new IllegalStateException();
             }
             return (I2CDeviceConfig) Platform.clone(instance);
@@ -299,7 +299,7 @@
      */
     @Deprecated
     public I2CDeviceConfig(String controllerName, int address, int addressSize, int clockFrequency) {
-        this(DEFAULT, address, addressSize, clockFrequency);
+        this(UNASSIGNED, address, addressSize, clockFrequency);
         // check for null
         controllerName.length();
         this.controllerName = controllerName;
@@ -441,7 +441,7 @@
 
 
     private static void checkAddressSize(int addressSize) {
-        if (ADDR_SIZE_7 != addressSize && ADDR_SIZE_10 != addressSize && DEFAULT != addressSize) {
+        if (ADDR_SIZE_7 != addressSize && ADDR_SIZE_10 != addressSize && UNASSIGNED != addressSize) {
             throw new IllegalArgumentException(Integer.toString(addressSize));
         }
     }
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -407,7 +407,7 @@
      */
     @Deprecated
     public PWMChannelConfig(String controllerName, int channelNumber, int idleState, int pulsePeriod, int pulseAlignment) {
-        this(DEFAULT, channelNumber, idleState, pulsePeriod, pulseAlignment);
+        this(UNASSIGNED, channelNumber, idleState, pulsePeriod, pulseAlignment);
         // null check
         controllerName.length();
         this.controllerName = controllerName;
@@ -455,7 +455,7 @@
     @Deprecated
     public PWMChannelConfig(String controllerName, int channelNumber, int idleState, int pulsePeriod,
             int pulseAlignment, GPIOPinConfig output) {
-       this(DEFAULT, channelNumber, idleState, pulsePeriod, pulseAlignment, output);
+       this(UNASSIGNED, channelNumber, idleState, pulsePeriod, pulseAlignment, output);
        // null check
        controllerName.length();
        this.controllerName = controllerName;
--- a/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -112,7 +112,7 @@
     public static final int CS_NOT_CONTROLLED = 2;
 
     private String controllerName;
-    private int address;
+    private int address = UNASSIGNED;
     private int csActive = UNASSIGNED;
     private int controllerNumber = UNASSIGNED;
     private int bitOrdering = UNASSIGNED;
@@ -374,7 +374,7 @@
     @Deprecated
     public SPIDeviceConfig(int controllerNumber, int address, int clockFrequency, int clockMode, int wordLength,
             int bitOrdering) {
-        this(controllerNumber, address, DEFAULT, clockFrequency, clockMode, wordLength, bitOrdering);
+        this(controllerNumber, address, UNASSIGNED, clockFrequency, clockMode, wordLength, bitOrdering);
     }
 
     /**
@@ -460,7 +460,7 @@
     @Deprecated
     public SPIDeviceConfig(String controllerName, int address, int clockFrequency, int clockMode, int wordLength,
             int bitOrdering) {
-        this(controllerName, address, DEFAULT, clockFrequency, clockMode, wordLength, bitOrdering);
+        this(controllerName, address, UNASSIGNED, clockFrequency, clockMode, wordLength, bitOrdering);
     }
 
     /**
@@ -501,7 +501,7 @@
     @Deprecated
     public SPIDeviceConfig(String controllerName, int address, int csActive, int clockFrequency, int clockMode, int wordLength,
             int bitOrdering) {
-        this(DEFAULT, address, csActive, clockFrequency, clockMode, wordLength, bitOrdering);
+        this(UNASSIGNED, address, csActive, clockFrequency, clockMode, wordLength, bitOrdering);
         // checks for null
         controllerName.length();
         this.controllerName  = controllerName;
@@ -671,7 +671,7 @@
     }
 
     private static void checkCsActive(int csActive) {
-        if (csActive < DEFAULT || csActive > CS_NOT_CONTROLLED) {
+        if (csActive < UNASSIGNED || csActive > CS_NOT_CONTROLLED) {
             throw new IllegalArgumentException(Integer.toString(csActive));
         }
     }
@@ -683,7 +683,7 @@
     }
 
     private static void checkBitOrdering(int bitOrdering) {
-        if (bitOrdering < DEFAULT || bitOrdering > SPIDevice.MIXED_ENDIAN) {
+        if (bitOrdering < UNASSIGNED || bitOrdering > SPIDevice.MIXED_ENDIAN) {
             throw new IllegalArgumentException(Integer.toString(bitOrdering));
         }
     }
--- a/src/share/classes/jdk/dio/uart/UARTConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/uart/UARTConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -569,8 +569,8 @@
     }
 
     private void checkParameters(){
-        if ((null == controllerName && controllerNumber < DEFAULT) ||
-            channelNumber < DEFAULT ||
+        if ((null == controllerName && controllerNumber < UNASSIGNED) ||
+            channelNumber < UNASSIGNED ||
             baudRate <= 0 ||
             (dataBits < DATABITS_5 || dataBits > DATABITS_9) ||
             (parity < PARITY_NONE || parity > PARITY_SPACE) ||
@@ -583,8 +583,8 @@
             (0!=(flowcontrol&UARTConfig.FLOWCONTROL_RTSCTS_IN) && 0!=(flowcontrol&UARTConfig.FLOWCONTROL_XONXOFF_IN)) ||
             //check if 1 flaf for output is set
             (0!=(flowcontrol&UARTConfig.FLOWCONTROL_RTSCTS_OUT) && 0!=(flowcontrol&UARTConfig.FLOWCONTROL_XONXOFF_OUT)) ||
-            inputBufferSize  < DEFAULT ||
-            outputBufferSize < DEFAULT ) {
+            inputBufferSize  < UNASSIGNED ||
+            outputBufferSize < UNASSIGNED ) {
            throw new IllegalArgumentException();
         }
     }
--- a/src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java	Wed Jul 29 11:51:44 2015 +0300
+++ b/src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java	Wed Jul 29 18:06:45 2015 +0300
@@ -90,7 +90,7 @@
         this.timerNumber = timerNumber;
         // checks for null
         controllerName.length();
-        if (DEFAULT > timerNumber) {
+        if (UNASSIGNED > timerNumber) {
             throw new IllegalArgumentException();
         }
     }
@@ -108,7 +108,7 @@
     public WatchdogTimerConfig(int controllerNumber, int timerNumber) {
         this.controllerNumber = controllerNumber;
         this.timerNumber = timerNumber;
-        if (DEFAULT > timerNumber || DEFAULT > controllerNumber) {
+        if (UNASSIGNED > timerNumber || UNASSIGNED > controllerNumber) {
             throw new IllegalArgumentException();
         }
     }