svn commit: r1849741 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity: GenericEntity.java util/EntityListIterator.java util/EntityUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1849741 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity: GenericEntity.java util/EntityListIterator.java util/EntityUtil.java

adityasharma
Author: adityasharma
Date: Wed Dec 26 08:37:47 2018
New Revision: 1849741

URL: http://svn.apache.org/viewvc?rev=1849741&view=rev
Log:
Improved: Refactor boolean returns from methods
(OFBIZ-10725)
Improved boolean returns with a single statement, replacing if blocks with the explicit boolean return.
Improves code in methods:
isPrimaryKey() of GenericEntity
hasNext() and hasPrevious() of EntityListIterator
isValueActive() of EntityUtil

Additional change:
Improved return for getStartIndexFromViewIndex() method in EntityUtil. Instead of using if-else block, a ternary operator is used for improving readability.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java?rev=1849741&r1=1849740&r2=1849741&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java Wed Dec 26 08:37:47 2018
@@ -403,10 +403,7 @@ public class GenericEntity implements Ma
             }
             fieldKeys.remove(fieldName);
         }
-        if (!fieldKeys.isEmpty()) {
-            return false;
-        }
-        return true;
+        return fieldKeys.isEmpty();
     }
 
     /** Returns true if the entity contains all of the primary key fields. */

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java?rev=1849741&r1=1849740&r2=1849741&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java Wed Dec 26 08:37:47 2018
@@ -292,12 +292,10 @@ public class EntityListIterator implemen
         }
 
         try {
-            if (resultSet.isLast() || resultSet.isAfterLast()) {
-                return false;
-            }
             // do a quick game to see if the resultSet is empty:
             // if we are not in the first or beforeFirst positions and we haven't made any values yet, the result set is empty so return false
-            return haveMadeValue || resultSet.isBeforeFirst() || resultSet.isFirst();
+            return !(resultSet.isLast() || resultSet.isAfterLast())
+                    && (haveMadeValue || resultSet.isBeforeFirst() || resultSet.isFirst());
         } catch (SQLException e) {
             tryCloseWithWarning("Warning: auto-closed EntityListIterator because of exception: " + e.toString());
             throw new GeneralRuntimeException("Error while checking to see if this is the last result", e);
@@ -310,13 +308,10 @@ public class EntityListIterator implemen
      */
     public boolean hasPrevious() {
         try {
-            if (resultSet.isFirst() || resultSet.isBeforeFirst()) {
-                return false;
-            }
             // do a quick game to see if the resultSet is empty:
             // if we are not in the first or beforeFirst positions and we haven't made any values yet, the result set is
             // empty so return false
-            return haveMadeValue || resultSet.isAfterLast() || resultSet.isLast();
+            return !(resultSet.isFirst() || resultSet.isBeforeFirst()) && (haveMadeValue || resultSet.isAfterLast() || resultSet.isLast());
         } catch (SQLException e) {
             tryCloseWithWarning("Warning: auto-closed EntityListIterator because of exception: " + e.toString());
             throw new GeneralRuntimeException("Error while checking to see if this is the first result", e);

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java?rev=1849741&r1=1849740&r2=1849741&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java Wed Dec 26 08:37:47 2018
@@ -251,13 +251,8 @@ public final class EntityUtil {
     public static boolean isValueActive(GenericValue datedValue, java.sql.Timestamp moment, String fromDateName, String thruDateName) {
         java.sql.Timestamp fromDate = datedValue.getTimestamp(fromDateName);
         java.sql.Timestamp thruDate = datedValue.getTimestamp(thruDateName);
-
-        if ((thruDate == null || thruDate.after(moment)) && (fromDate == null || fromDate.before(moment) || fromDate.equals(moment))) {
-            return true;
-        } else {
-            // else not active at moment
-            return false;
-        }
+        return (thruDate == null || thruDate.after(moment)) &&
+                (fromDate == null || fromDate.before(moment) || fromDate.equals(moment));
     }
 
     /**
@@ -517,10 +512,7 @@ public final class EntityUtil {
      * @see EntityUtil#getPagedList
      */
     public static int getStartIndexFromViewIndex(int viewIndex, int viewSize) {
-        if (viewIndex == 0) {
-            return 1;
-        }
-        return (viewIndex * viewSize) + 1;
+        return viewIndex == 0 ? 1 : (viewIndex * viewSize) + 1;
     }
 
     /**