changeset 200:5accb238f20b

8129842: Fix problem with some EqHashCode fails due to missed IAE Summary: Refactor Utils, checkInt... checkDouble... Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Thu, 25 Jun 2015 13:53:50 +0300
parents 1e2cf9f41b8b
children da7936b5c7b6
files src/share/classes/com/oracle/dio/utils/Utils.java src/share/classes/jdk/dio/adc/ADCChannelConfig.java src/share/classes/jdk/dio/dac/DACChannelConfig.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
diffstat 6 files changed, 34 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/utils/Utils.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Jun 25 13:53:50 2015 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015,  Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -162,6 +162,15 @@
         return verifyAndOrderActions(actions, DevicePermission.OPEN + "," + DevicePermission.POWER_MANAGE);
     }
 
+    /**
+     * Checks if given value is zero or positive
+     *
+     */
+    public static void checkIntZeroOrPozitive(final int val) {
+        if (DeviceConfig.UNASSIGNED >= val) {
+            throw new IllegalArgumentException(Integer.toString(val));
+        }
+    }
 
     /**
      * Checks if given value is UNASSIGNED or zero or positive
@@ -174,11 +183,11 @@
     }
 
     /**
-     * Checks if given value is greater than one or UNASSIGNED
+     * Checks if given value is greater than 0 or UNASSIGNED
      *
      */
-    public static void checkGreaterThanOne(final int val) {
-        if (DeviceConfig.UNASSIGNED > val || 1 > val){
+    public static void checkGreaterThanZero(final int val) {
+        if (DeviceConfig.UNASSIGNED != val && val < 1){
             throw new IllegalArgumentException(Integer.toString(val));
         }
     }
@@ -187,7 +196,8 @@
      * Checks if no NaN and positive value
      */
     public static void checkDoubleGreaterThanOne(double val) {
-        if (val  < 1.0 || Double.NaN == val || Double.POSITIVE_INFINITY == val) {
+
+        if (Double.compare(val, 1.0d) < 0 || Double.compare(val, Double.NaN) == 0 || Double.compare(val, Double.POSITIVE_INFINITY) == 0) {
             throw new IllegalArgumentException(Double.toString(val));
         }
     }
--- a/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu Jun 25 13:53:50 2015 +0300
@@ -173,7 +173,7 @@
          * defined range.
          */
         public Builder setResolution(int resolution) {
-            Utils.checkGreaterThanOne(resolution);
+            Utils.checkGreaterThanZero(resolution);
             instance.resolution = resolution;
             return this;
         }
@@ -192,7 +192,7 @@
          * @see #setScaleFactor
          */
         public Builder setSamplingInterval(int samplingInterval) {
-            Utils.checkGreaterThanOne(samplingInterval);
+            Utils.checkGreaterThanZero(samplingInterval);
             instance.samplingInterval = samplingInterval;
             return this;
         }
@@ -210,7 +210,7 @@
          * @see #setScaleFactor
          */
         public Builder setSamplingTime(int samplingTime) {
-            Utils.checkGreaterThanOne(samplingTime);
+            Utils.checkGreaterThanZero(samplingTime);
             instance.samplingTime = samplingTime;
             return this;
         }
@@ -487,9 +487,9 @@
     private void checkValues() throws IllegalArgumentException {
         Utils.checkIntValue(controllerNumber);
         Utils.checkIntValue(channelNumber);
-        Utils.checkGreaterThanOne(resolution);
-        Utils.checkGreaterThanOne(samplingInterval);
-        Utils.checkGreaterThanOne(samplingTime);
+        Utils.checkGreaterThanZero(resolution);
+        Utils.checkGreaterThanZero(samplingInterval);
+        Utils.checkGreaterThanZero(samplingTime);
     }
 }
 
--- a/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu Jun 25 13:53:50 2015 +0300
@@ -168,7 +168,7 @@
          * defined range.
          */
         public Builder setResolution(int resolution) {
-            Utils.checkGreaterThanOne(resolution);
+            Utils.checkGreaterThanZero(resolution);
             instance.resolution = resolution;
             return this;
         }
@@ -187,7 +187,7 @@
          * @see #setScaleFactor
          */
         public Builder setSamplingInterval(int samplingInterval) {
-            Utils.checkGreaterThanOne(samplingInterval);
+            Utils.checkGreaterThanZero(samplingInterval);
             instance.samplingInterval = samplingInterval;
             return this;
         }
@@ -439,8 +439,8 @@
     private void checkValues() {
         Utils.checkIntValue(controllerNumber);
         Utils.checkIntValue(channelNumber);
-        Utils.checkGreaterThanOne(resolution);
-        Utils.checkGreaterThanOne(samplingInterval);
+        Utils.checkGreaterThanZero(resolution);
+        Utils.checkGreaterThanZero(samplingInterval);
     }
 
 }
--- a/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Thu Jun 25 13:53:50 2015 +0300
@@ -223,7 +223,7 @@
          * the defined range.
          */
         public Builder setClockFrequency(int clockFrequency) {
-            Utils.checkGreaterThanOne(clockFrequency);
+            Utils.checkGreaterThanZero(clockFrequency);
             instance.clockFrequency = clockFrequency;
             return this;
         }
@@ -449,7 +449,7 @@
     private void checkValues() {
         Utils.checkIntValue(controllerNumber);
         Utils.checkIntValue(address);
-        Utils.checkGreaterThanOne(clockFrequency);
+        Utils.checkGreaterThanZero(clockFrequency);
         checkAddressSize(addressSize);
     }
 
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu Jun 25 13:53:50 2015 +0300
@@ -228,7 +228,7 @@
          * @see #setScaleFactor
          */
         public Builder setPulsePeriod(int pulsePeriod) {
-            Utils.checkGreaterThanOne(pulsePeriod);
+            Utils.checkGreaterThanZero(pulsePeriod);
             instance.pulsePeriod = pulsePeriod;
             return this;
         }
@@ -482,7 +482,7 @@
         Utils.checkIntValue(controllerNumber);
         Utils.checkIntValue(channelNumber);
         checkIdle(idleState);
-        Utils.checkGreaterThanOne(pulsePeriod);
+        Utils.checkGreaterThanZero(pulsePeriod);
         checkAligment(pulseAlignment);
     }
 
--- a/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Wed Jun 24 12:50:46 2015 +0300
+++ b/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Thu Jun 25 13:53:50 2015 +0300
@@ -196,7 +196,7 @@
          * </ul>
          */
         public Builder setAddress(int address) {
-            Utils.checkGreaterThanOne(address);
+            Utils.checkIntZeroOrPozitive(address);
             instance.address = address;
             return this;
         }
@@ -313,7 +313,7 @@
          * defined range.
          */
         public Builder setWordLength(int wordLength) {
-            Utils.checkGreaterThanOne(wordLength);
+            Utils.checkGreaterThanZero(wordLength);
             instance.wordLength = wordLength;
             return this;
         }
@@ -329,7 +329,7 @@
          * the defined range.
          */
         public Builder setClockFrequency(int clockFrequency) {
-            Utils.checkGreaterThanOne(clockFrequency);
+            Utils.checkGreaterThanZero(clockFrequency);
             instance.clockFrequency = clockFrequency;
             return this;
         }
@@ -690,10 +690,10 @@
 
     private void checkParameters(){
         Utils.checkIntValue(address);
-        Utils.checkGreaterThanOne(clockFrequency);
+        Utils.checkGreaterThanZero(clockFrequency);
         checkCsActive(csActive);
         checkClockMode(clockMode);
         checkBitOrdering(bitOrdering);
-        Utils.checkGreaterThanOne(wordLength);
+        Utils.checkGreaterThanZero(wordLength);
     }
 }