jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1782579 - /jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java
Date Sat, 11 Feb 2017 10:46:41 GMT
Author: fschumacher
Date: Sat Feb 11 10:46:40 2017
New Revision: 1782579

URL: http://svn.apache.org/viewvc?rev=1782579&view=rev
Log:
Don't reuse parameters as variables, or hide fields with local variables.

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java?rev=1782579&r1=1782578&r2=1782579&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/gui/ObjectTableSorter.java Sat Feb 11 10:46:40
2017
@@ -31,6 +31,8 @@ import java.util.stream.Stream;
 import javax.swing.RowSorter;
 import javax.swing.SortOrder;
 
+import org.apache.commons.lang3.ObjectUtils;
+
 /**
  * Implementation of a {@link RowSorter} for {@link ObjectTableModel}
  * @since 3.2
@@ -143,10 +145,7 @@ public class ObjectTableSorter extends R
      */
     public ObjectTableSorter setValueComparator(int column, Comparator<?> comparator)
{
         invalidate();
-        if (comparator == null) {
-            comparator = getDefaultComparator(column);
-        }
-        valueComparators[column] = comparator;
+        valueComparators[column] = ObjectUtils.defaultIfNull(comparator, getDefaultComparator(column));
         return this;
     }
 
@@ -182,10 +181,7 @@ public class ObjectTableSorter extends R
      */
     public ObjectTableSorter setFallbackComparator(Comparator<Row> comparator) {
         invalidate();
-        if (comparator == null) {
-            comparator = Comparator.comparingInt(Row::getIndex);
-        }
-        fallbackComparator = comparator;
+        fallbackComparator = ObjectUtils.defaultIfNull(comparator, Comparator.comparingInt(Row::getIndex));
         return this;
     }
 
@@ -247,9 +243,10 @@ public class ObjectTableSorter extends R
         invalidate();
         if (sortkey != null) {
             int column = sortkey.getColumn();
-            Comparator<?> comparator = valueComparators[column];
-            if (comparator == null) {
-                throw new IllegalArgumentException(format("Can't sort column %s, it is mapped
to type %s and this one have no natural order. So an explicit one must be specified", column,
model.getColumnClass(column)));
+            if (valueComparators[column] == null) {
+                throw new IllegalArgumentException(
+                        format("Can't sort column %s, it is mapped to type %s and this one
have no natural order. So an explicit one must be specified",
+                                column, model.getColumnClass(column)));
             }
         }
         this.sortkey    = sortkey;
@@ -332,12 +329,12 @@ public class ObjectTableSorter extends R
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     protected Comparator<Row> getComparatorFromSortKey(SortKey sortkey) {
-        Comparator comparator = getValueComparator(sortkey.getColumn());
+        Comparator comp = getValueComparator(sortkey.getColumn());
         if (sortkey.getSortOrder() == SortOrder.DESCENDING) {
-            comparator = comparator.reversed();
+            comp = comp.reversed();
         }
         Function<Row,Object> getValueAt = (Row row) -> row.getValueAt(sortkey.getColumn());
-        return Comparator.comparing(getValueAt, comparator);
+        return Comparator.comparing(getValueAt, comp);
     }
 
     /**



Mime
View raw message