From 8433427527214c83f56c533259efd7f56a1863b3 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 03 Nov 2014 10:50:04 +0000
Subject: [PATCH] AutoRefactored: - work with null checked expressions first - revert conditions - collapse if statements - push negations down - invert equals()

---
 opendj-config/src/main/java/org/forgerock/opendj/config/DurationPropertyDefinition.java |   47 ++++++++++++++---------------------------------
 1 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/opendj-config/src/main/java/org/forgerock/opendj/config/DurationPropertyDefinition.java b/opendj-config/src/main/java/org/forgerock/opendj/config/DurationPropertyDefinition.java
index 556cac8..efb250c 100644
--- a/opendj-config/src/main/java/org/forgerock/opendj/config/DurationPropertyDefinition.java
+++ b/opendj-config/src/main/java/org/forgerock/opendj/config/DurationPropertyDefinition.java
@@ -143,12 +143,9 @@
         public final void setBaseUnit(DurationUnit unit) {
             Reject.ifNull(unit);
 
-            // Make sure that the base unit is not bigger than the maximum
-            // unit.
-            if (maximumUnit != null) {
-                if (unit.getDuration() > maximumUnit.getDuration()) {
-                    throw new IllegalArgumentException("Base unit greater than maximum unit");
-                }
+            // Make sure that the base unit is not bigger than the maximum unit.
+            if (maximumUnit != null && unit.getDuration() > maximumUnit.getDuration()) {
+                throw new IllegalArgumentException("Base unit greater than maximum unit");
             }
 
             this.baseUnit = unit;
@@ -167,11 +164,7 @@
          *             base unit.
          */
         public final void setMaximumUnit(String unit) {
-            if (unit == null) {
-                setMaximumUnit((DurationUnit) null);
-            } else {
-                setMaximumUnit(DurationUnit.getUnit(unit));
-            }
+            setMaximumUnit(unit != null ? DurationUnit.getUnit(unit) : null);
         }
 
         /**
@@ -186,12 +179,9 @@
          *             unit.
          */
         public final void setMaximumUnit(DurationUnit unit) {
-            if (unit != null) {
-                // Make sure that the maximum unit is not smaller than the
-                // base unit.
-                if (unit.getDuration() < baseUnit.getDuration()) {
-                    throw new IllegalArgumentException("Maximum unit smaller than base unit");
-                }
+            // Make sure that the maximum unit is not smaller than the base unit.
+            if (unit != null && unit.getDuration() < baseUnit.getDuration()) {
+                throw new IllegalArgumentException("Maximum unit smaller than base unit");
             }
 
             this.maximumUnit = unit;
@@ -276,11 +266,7 @@
          *             limit is greater than the upper limit.
          */
         public final void setUpperLimit(String upperLimit) {
-            if (upperLimit == null) {
-                setUpperLimit((Long) null);
-            } else {
-                setUpperLimit(DurationUnit.parseValue(upperLimit, baseUnit));
-            }
+            setUpperLimit(upperLimit != null ? DurationUnit.parseValue(upperLimit, baseUnit) : null);
         }
 
         /**
@@ -413,12 +399,9 @@
     public String encodeValue(Long value) {
         Reject.ifNull(value);
 
-        // Make sure that we correctly encode negative values as
-        // "unlimited".
-        if (allowUnlimited) {
-            if (value < 0) {
-                return UNLIMITED;
-            }
+        // Make sure that we correctly encode negative values as "unlimited".
+        if (allowUnlimited && value < 0) {
+            return UNLIMITED;
         }
 
         // Encode the size value using the base unit.
@@ -435,10 +418,8 @@
         Reject.ifNull(value);
 
         // First check for the special "unlimited" value when necessary.
-        if (allowUnlimited) {
-            if (value.trim().equalsIgnoreCase(UNLIMITED)) {
-                return -1L;
-            }
+        if (allowUnlimited && UNLIMITED.equalsIgnoreCase(value.trim())) {
+            return -1L;
         }
 
         // Parse the string representation.
@@ -459,10 +440,10 @@
         Long i = (long) baseUnit.fromMilliSeconds(ms);
         try {
             validateValue(i);
+            return i;
         } catch (PropertyException e) {
             throw PropertyException.illegalPropertyValueException(this, value);
         }
-        return i;
     }
 
     /** {@inheritDoc} */

--
Gitblit v1.10.0