You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2021/04/06 06:10:20 UTC

svn commit: r1888415 - in /poi/trunk: main/src/main/java/org/apache/poi/ss/formula/eval/ main/src/main/java/org/apache/poi/ss/formula/functions/ main/src/test/java/org/apache/poi/util/ ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/

Author: centic
Date: Tue Apr  6 06:10:19 2021
New Revision: 1888415

URL: http://svn.apache.org/viewvc?rev=1888415&view=rev
Log:
Apply some IDE suggestions, improve exception message, add some JavaDoc

Modified:
    poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/AreaEval.java
    poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java
    poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java
    poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Countif.java
    poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java
    poi/trunk/main/src/test/java/org/apache/poi/util/TestIOUtils.java
    poi/trunk/ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java

Modified: poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/AreaEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/AreaEval.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/AreaEval.java (original)
+++ poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/AreaEval.java Tue Apr  6 06:10:19 2021
@@ -59,26 +59,29 @@ public interface AreaEval extends TwoDEv
      * returns true if the cell at row and col specified
      * as absolute indexes in the sheet is contained in
      * this area.
-     * @param row
-     * @param col
+     * @param row 0-based row index
+     * @param col 0-based column index
      */
     boolean contains(int row, int col);
 
     /**
      * returns true if the specified col is in range
-     * @param col
+     * @param col 0-based column index
      */
     boolean containsColumn(int col);
 
     /**
      * returns true if the specified row is in range
-     * @param row
+     * @param row 0-based row index
      */
     boolean containsRow(int row);
 
     int getWidth();
     int getHeight();
     /**
+     * @param relativeRowIndex 0-based row index relative to this area
+     * @param relativeColumnIndex 0-based column index relative to this area
+     *
      * @return the ValueEval from within this area at the specified relativeRowIndex and
      * relativeColumnIndex. Never <code>null</code> (possibly {@link BlankEval}). The
      * specified indexes should relative to the top left corner of this area.

Modified: poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java (original)
+++ poi/trunk/main/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java Tue Apr  6 06:10:19 2021
@@ -43,7 +43,7 @@ public final class OperandResolver {
                  "(\\."+Digits+"("+Exp+")?))"+
                  "[\\x00-\\x20]*");
     private static final Pattern fpPattern = Pattern.compile(fpRegex);
-    
+
     private OperandResolver() {
         // no instances of this class
     }
@@ -75,7 +75,7 @@ public final class OperandResolver {
         }
         return result;
     }
-    
+
     /**
      * Retrieves a single value from an area evaluation utilizing the 2D indices of the cell
      * within its own area reference to index the value in the area evaluation.
@@ -105,7 +105,7 @@ public final class OperandResolver {
         else if (ae.isRow() && relativeColIndex < ae.getWidth()) {
             return ae.getRelativeValue(0, relativeColIndex);
         }
-        
+
         return ErrorEval.NA;
     }
 
@@ -212,7 +212,7 @@ public final class OperandResolver {
         }
         return ae.getAbsoluteValue(ae.getFirstRow(), srcCellCol);
     }
-    
+
     private static ValueEval chooseSingleElementFromRef(RefEval ref) {
         return ref.getInnerValueEval( ref.getFirstSheetIndex() );
     }
@@ -251,7 +251,6 @@ public final class OperandResolver {
      * {@link StringEval}, {@link BoolEval} or {@link BlankEval}
      */
     public static double coerceValueToDouble(ValueEval ev) throws EvaluationException {
-
         if (ev == BlankEval.instance) {
             return 0.0;
         }
@@ -266,7 +265,7 @@ public final class OperandResolver {
             if (dd == null) {
                 throw EvaluationException.invalidValue();
             }
-            return dd.doubleValue();
+            return dd;
         }
         throw new RuntimeException("Unexpected arg eval type (" + ev.getClass().getName() + ")");
     }
@@ -274,8 +273,8 @@ public final class OperandResolver {
     /**
      * Converts a string to a double using standard rules that Excel would use.<br>
      * Tolerates leading and trailing spaces, <p>
-     * 
-     * Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings.  
+     *
+     * Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings.
      *
      *  Some examples:<br>
      *  " 123 " -&gt; 123.0<br>
@@ -301,7 +300,7 @@ public final class OperandResolver {
         else {
             return null;
         }
-        
+
     }
 
     public static Double parseDateTime(String pText) {
@@ -340,7 +339,7 @@ public final class OperandResolver {
             return null;
         }
         if (ve instanceof BoolEval) {
-            return Boolean.valueOf(((BoolEval) ve).getBooleanValue());
+            return ((BoolEval) ve).getBooleanValue();
         }
 
         if (ve instanceof StringEval) {
@@ -364,7 +363,7 @@ public final class OperandResolver {
             if (Double.isNaN(d)) {
                 throw new EvaluationException(ErrorEval.VALUE_INVALID);
             }
-            return Boolean.valueOf(d != 0);
+            return d != 0;
         }
         if (ve instanceof ErrorEval) {
             throw new EvaluationException((ErrorEval) ve);

Modified: poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java (original)
+++ poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java Tue Apr  6 06:10:19 2021
@@ -30,7 +30,7 @@ import org.apache.poi.ss.formula.functio
 import org.apache.poi.ss.formula.functions.Countif.ErrorMatcher;
 
 /**
- * Base class for SUMIFS() and COUNTIFS() functions, as they share much of the same logic, 
+ * Base class for SUMIFS() and COUNTIFS() functions, as they share much of the same logic,
  * the difference being the source of the totals.
  */
 /*package*/ abstract class Baseifs implements FreeRefFunction {
@@ -40,11 +40,11 @@ import org.apache.poi.ss.formula.functio
      * @return true if there should be a range argument before the criteria pairs
      */
     protected abstract boolean hasInitialRange();
-        
+
     public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
         final boolean hasInitialRange = hasInitialRange();
         final int firstCriteria = hasInitialRange ? 1 : 0;
-        
+
         if( args.length < (2+firstCriteria) || args.length % 2 != firstCriteria ) {
             return ErrorEval.VALUE_INVALID;
         }
@@ -54,13 +54,13 @@ import org.apache.poi.ss.formula.functio
             if (hasInitialRange) {
                 sumRange = convertRangeArg(args[0]);
             }
-            
+
             // collect pairs of ranges and criteria
             AreaEval[] ae = new AreaEval[(args.length - firstCriteria)/2];
             I_MatchPredicate[] mp = new I_MatchPredicate[ae.length];
             for(int i = firstCriteria, k=0; i < args.length; i += 2, k++){
                 ae[k] = convertRangeArg(args[i]);
-                
+
                 mp[k] = Countif.createCriteriaPredicate(args[i+1], ec.getRowIndex(), ec.getColumnIndex());
             }
 
@@ -84,13 +84,13 @@ import org.apache.poi.ss.formula.functio
     private static void validateCriteriaRanges(AreaEval sumRange, AreaEval[] criteriaRanges) throws EvaluationException {
         int h = criteriaRanges[0].getHeight();
         int w = criteriaRanges[0].getWidth();
-        
-        if (sumRange != null 
-                && (sumRange.getHeight() != h 
+
+        if (sumRange != null
+                && (sumRange.getHeight() != h
                     || sumRange.getWidth() != w) ) {
             throw EvaluationException.invalidValue();
         }
-        
+
         for(AreaEval r : criteriaRanges){
             if(r.getHeight() != h ||
                r.getWidth() != w ) {
@@ -107,7 +107,7 @@ import org.apache.poi.ss.formula.functio
      */
     private static void validateCriteria(I_MatchPredicate[] criteria) throws EvaluationException {
         for(I_MatchPredicate predicate : criteria) {
-            
+
             // check for errors in predicate and return immediately using this error code
             if(predicate instanceof ErrorMatcher) {
                 throw new EvaluationException(ErrorEval.valueOf(((ErrorMatcher)predicate).getValue()));
@@ -154,14 +154,16 @@ import org.apache.poi.ss.formula.functio
     /**
      * For counts, this would return 1, for sums it returns a cell value or zero.
      * This is only called after all the criteria are confirmed true for the coordinates.
+     *
      * @param sumRange if used
-     * @param relRowIndex
-     * @param relColIndex
+     * @param relRowIndex 0-based row index relative to the sumRange area
+     * @param relColIndex 0-based column index relative to the sumRange area
+     *
      * @return the aggregate input value corresponding to the given range coordinates
      */
     private static double accumulate(AreaEval sumRange, int relRowIndex, int relColIndex) {
         if (sumRange == null) return 1.0; // count
-        
+
         ValueEval addend = sumRange.getRelativeValue(relRowIndex, relColIndex);
         if (addend instanceof NumberEval) {
             return ((NumberEval)addend).getNumberValue();

Modified: poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Countif.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Countif.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Countif.java (original)
+++ poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Countif.java Tue Apr  6 06:10:19 2021
@@ -138,11 +138,9 @@ public final class Countif extends Fixed
         }
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(64);
-            sb.append(getClass().getName());
-            sb.append(" [").append(_representation).append("]");
-            return sb.toString();
+            return getClass().getName() + " [" + _representation + "]";
         }
+
         public String getRepresentation() {
             return _representation;
         }
@@ -208,7 +206,7 @@ public final class Countif extends Fixed
                     // x is text that is not a number
                     return false;
                 }
-                return _value == val.doubleValue();
+                return _value == val;
             } else if((x instanceof NumberEval)) {
                 NumberEval ne = (NumberEval) x;
                 testValue = ne.getNumberValue();
@@ -304,7 +302,7 @@ public final class Countif extends Fixed
             }
             return false;
         }
-        
+
         public int getValue() {
             return _value;
         }
@@ -505,12 +503,12 @@ public final class Countif extends Fixed
 
         Boolean booleanVal = parseBoolean(value);
         if(booleanVal != null) {
-            return new BooleanMatcher(booleanVal.booleanValue(), operator);
+            return new BooleanMatcher(booleanVal, operator);
         }
 
         Double doubleVal = OperandResolver.parseDouble(value);
         if(doubleVal != null) {
-            return new NumberMatcher(doubleVal.doubleValue(), operator);
+            return new NumberMatcher(doubleVal, operator);
         }
         ErrorEval ee = parseError(value);
         if (ee != null) {

Modified: poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java (original)
+++ poi/trunk/main/src/main/java/org/apache/poi/ss/formula/functions/Sumproduct.java Tue Apr  6 06:10:19 2021
@@ -81,17 +81,13 @@ public final class Sumproduct implements
 		} catch (EvaluationException e) {
 			return e.getErrorEval();
 		}
-		throw new RuntimeException("Invalid arg type for SUMPRODUCT: ("
-				+ firstArg.getClass().getName() + ")");
+		throw new RuntimeException("Invalid arg type for SUMPRODUCT: " + firstArg);
 	}
 
 	private static ValueEval evaluateSingleProduct(ValueEval[] evalArgs) throws EvaluationException {
-		int maxN = evalArgs.length;
-
 		double term = 1D;
-		for(int n=0; n<maxN; n++) {
-			double val = getScalarValue(evalArgs[n]);
-			term *= val;
+		for (ValueEval evalArg : evalArgs) {
+			term *= getScalarValue(evalArg);
 		}
 		return new NumberEval(term);
 	}
@@ -180,13 +176,12 @@ public final class Sumproduct implements
 	}
 
 	private static boolean areasAllSameSize(TwoDEval[] args, int height, int width) {
-		for (int i = 0; i < args.length; i++) {
-			TwoDEval areaEval = args[i];
+		for (TwoDEval areaEval : args) {
 			// check that height and width match
-			if(areaEval.getHeight() != height) {
+			if (areaEval.getHeight() != height) {
 				return false;
 			}
-			if(areaEval.getWidth() != width) {
+			if (areaEval.getWidth() != width) {
 				return false;
 			}
 		}

Modified: poi/trunk/main/src/test/java/org/apache/poi/util/TestIOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/main/src/test/java/org/apache/poi/util/TestIOUtils.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/main/src/test/java/org/apache/poi/util/TestIOUtils.java (original)
+++ poi/trunk/main/src/test/java/org/apache/poi/util/TestIOUtils.java Tue Apr  6 06:10:19 2021
@@ -531,7 +531,7 @@ final class TestIOUtils {
         }
     }
 
-    public class NullInputStream extends InputStream {
+    public static class NullInputStream extends InputStream {
         private final int bytes;
         private final boolean exception;
 

Modified: poi/trunk/ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java?rev=1888415&r1=1888414&r2=1888415&view=diff
==============================================================================
--- poi/trunk/ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java (original)
+++ poi/trunk/ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java Tue Apr  6 06:10:19 2021
@@ -79,7 +79,7 @@ public abstract class ContentTypeManager
     /**
      * Default content type tree. <Extension, ContentType>
      */
-    private TreeMap<String, String> defaultContentType;
+    private final TreeMap<String, String> defaultContentType;
 
     /**
      * Override content type tree.
@@ -286,7 +286,7 @@ public abstract class ContentTypeManager
             throw new IllegalArgumentException("contentType");
         }
 
-        return (this.defaultContentType.containsValue(contentType) || 
+        return (this.defaultContentType.containsValue(contentType) ||
                 (this.overrideContentType != null && this.overrideContentType.containsValue(contentType)));
     }
 
@@ -353,9 +353,9 @@ public abstract class ContentTypeManager
          */
         if (this.container != null && this.container.getPart(partName) != null) {
             throw new OpenXML4JRuntimeException(
-                "Rule M2.4 exception : Part \'"
+                "Rule M2.4 exception : Part '"
                 + partName
-                + "\' not found - this error should NEVER happen!\n"
+                + "' not found - this error should NEVER happen!\n"
                 + "Check that your code is closing the open resources in the correct order prior to filing a bug report.\n"
                 + "If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!");
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org