]> source.dussan.org Git - poi.git/commitdiff
[github-365] use lambdas. Thanks to Arturo Bernal. This closes #365
authorPJ Fanning <fanningpj@apache.org>
Sat, 6 Aug 2022 21:12:49 +0000 (21:12 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 6 Aug 2022 21:12:49 +0000 (21:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903258 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java
poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java
poi-ooxml/src/main/java/org/apache/poi/xssf/util/CTColComparator.java
poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPBinTable.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PAPBinTable.java
poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java
poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java
poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
poi/src/main/java/org/apache/poi/ss/formula/IStabilityClassifier.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Count.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Counta.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2my2.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2py2.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Sumxmy2.java

index 49feb3f7aaeece6926c509586b39a29463787c92..308008a4a32460ce8635b7f8a3973c0bd1d24ad0 100644 (file)
@@ -53,12 +53,7 @@ public class SettingExternalFunction {
             // dummy function that returns NA
             // don't care about the implementation, we are not interested in evaluation
             // and this method will never be called
-            FreeRefFunction NA = new FreeRefFunction() {
-                @Override
-                public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
-                    return ErrorEval.NA;
-                }
-            };
+            FreeRefFunction NA = (args, ec) -> ErrorEval.NA;
             _functionsByName = new HashMap<>();
             _functionsByName.put("BDP", NA);
             _functionsByName.put("BDH", NA);
index 2e4d89647d14cec949cd6d804c058f45acb2a553..158927e7ef566b23de82de244fa0a5ff82cdef6f 100644 (file)
@@ -43,12 +43,7 @@ public abstract class ShapeVisitor {
      * mixing visitors and acceptors
      */
     protected ShapeVisitorAcceptor getAcceptor() {
-        return new ShapeVisitorAcceptor() {
-            @Override
-            public boolean accept(XDGFShape shape) {
-                return !shape.isDeleted();
-            }
-        };
+        return shape -> !shape.isDeleted();
     }
 
     public void setAcceptor(ShapeVisitorAcceptor acceptor) {
index ef8e526a4357dcb68024c52e7169a404d517be36..bc6d7dde97a82473ef5036b74c35a20f7df3b873 100644 (file)
@@ -25,22 +25,16 @@ public class CTColComparator {
 
     private CTColComparator() {}
 
-    public static final Comparator<CTCol> BY_MAX = new Comparator<CTCol>() {
-        @Override
-        public int compare(CTCol col1, CTCol col2) {
-            long col1max = col1.getMax();
-            long col2max = col2.getMax();
-            return Long.compare(col1max, col2max);
-        }
+    public static final Comparator<CTCol> BY_MAX = (col1, col2) -> {
+        long col1max = col1.getMax();
+        long col2max = col2.getMax();
+        return Long.compare(col1max, col2max);
     };
 
-    public static final Comparator<CTCol> BY_MIN_MAX = new Comparator<CTCol>() {
-        @Override
-        public int compare(CTCol col1, CTCol col2) {
-            long col11min = col1.getMin();
-            long col2min = col2.getMin();
-            return col11min < col2min ? -1 : col11min > col2min ? 1 : BY_MAX.compare(col1, col2);
-        }
+    public static final Comparator<CTCol> BY_MIN_MAX = (col1, col2) -> {
+        long col11min = col1.getMin();
+        long col2min = col2.getMin();
+        return col11min < col2min ? -1 : col11min > col2min ? 1 : BY_MAX.compare(col1, col2);
     };
 
 }
index d29ffc2b944884ec02297a0e23db84c31dd64c0d..a992bd0cc9bc214b4ec9550813846b7328d05320 100644 (file)
@@ -32,20 +32,12 @@ public class TypesLister {
    
    public void listByName(PrintStream out) {
       ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
-      all.sort(new Comparator<MAPIProperty>() {
-          public int compare(MAPIProperty a, MAPIProperty b) {
-              return a.name.compareTo(b.name);
-          }
-      });
+      all.sort((a, b) -> a.name.compareTo(b.name));
       list(all, out);
    }
    public void listById(PrintStream out) {
       ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
-      all.sort(new Comparator<MAPIProperty>() {
-          public int compare(MAPIProperty a, MAPIProperty b) {
-              return Integer.compare(a.id, b.id);
-          }
-      });
+      all.sort((a, b) -> Integer.compare(a.id, b.id));
       list(all, out);
    }
    private void list(ArrayList<MAPIProperty> list, PrintStream out) {
index 3f2bd010814b861a35cc20744c7e5fbb4fdb867a..42b28dd500928bd721bd30e8abfbf1d7f9576422 100644 (file)
@@ -178,14 +178,10 @@ public class CHPBinTable
                 chpxToFileOrder.put( chpx, Integer.valueOf( counter++ ) );
             }
         }
-        final Comparator<CHPX> chpxFileOrderComparator = new Comparator<CHPX>()
-        {
-            public int compare( CHPX o1, CHPX o2 )
-            {
-                Integer i1 = chpxToFileOrder.get( o1 );
-                Integer i2 = chpxToFileOrder.get( o2 );
-                return i1.compareTo( i2 );
-            }
+        final Comparator<CHPX> chpxFileOrderComparator = (o1, o2) -> {
+            Integer i1 = chpxToFileOrder.get( o1 );
+            Integer i2 = chpxToFileOrder.get( o2 );
+            return i1.compareTo( i2 );
         };
 
         LOG.atDebug().log("CHPX's order map created in {} ms", box(currentTimeMillis() - start));
index 917c7d895812f93079beca3da7306ca1c0d25fcc..03b231a9e5079d688354bf7b3d02fe9cfa814c6a 100644 (file)
@@ -164,14 +164,10 @@ public class PAPBinTable
                 papxToFileOrder.put( papx, Integer.valueOf( counter++ ) );
             }
         }
-        final Comparator<PAPX> papxFileOrderComparator = new Comparator<PAPX>()
-        {
-            public int compare( PAPX o1, PAPX o2 )
-            {
-                Integer i1 = papxToFileOrder.get( o1 );
-                Integer i2 = papxToFileOrder.get( o2 );
-                return i1.compareTo( i2 );
-            }
+        final Comparator<PAPX> papxFileOrderComparator = (o1, o2) -> {
+            Integer i1 = papxToFileOrder.get( o1 );
+            Integer i2 = papxToFileOrder.get( o2 );
+            return i1.compareTo( i2 );
         };
 
         LOG.atDebug().log("PAPX's order map created in {} ms", box(currentTimeMillis() - start));
index bebd3643cf74552bdc6a1de452212947278debf3..a37aa7ceeb55beb242d504da53c0723823f5dd5e 100644 (file)
@@ -78,13 +78,11 @@ public class DataSpaceMapUtils {
             dir.getEntry(fileName).delete();
         }
         
-        return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){
-            public void processPOIFSWriterEvent(POIFSWriterEvent event) {
-                try {
-                    event.getStream().write(buf, 0, event.getLimit());
-                } catch (IOException e) {
-                    throw new EncryptedDocumentException(e);
-                }
+        return dir.createDocument(fileName, bos.getWriteIndex(), event -> {
+            try {
+                event.getStream().write(buf, 0, event.getLimit());
+            } catch (IOException e) {
+                throw new EncryptedDocumentException(e);
             }
         });
     }   
index d5430631215a08a718e6378f755ce2eea705a74a..64139ca6b2de40113d131498a0d22f92dfa53c5a 100644 (file)
@@ -106,14 +106,11 @@ public class BinaryRC4Encryptor extends Encryptor {
         final EncryptionInfo info = getEncryptionInfo();
         final BinaryRC4EncryptionHeader header = (BinaryRC4EncryptionHeader)info.getHeader();
         final BinaryRC4EncryptionVerifier verifier = (BinaryRC4EncryptionVerifier)info.getVerifier();
-        EncryptionRecord er = new EncryptionRecord() {
-            @Override
-            public void write(LittleEndianByteArrayOutputStream bos) {
-                bos.writeShort(info.getVersionMajor());
-                bos.writeShort(info.getVersionMinor());
-                header.write(bos);
-                verifier.write(bos);
-            }
+        EncryptionRecord er = bos -> {
+            bos.writeShort(info.getVersionMajor());
+            bos.writeShort(info.getVersionMinor());
+            header.write(bos);
+            verifier.write(bos);
         };
         DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er);
     }
index 0e1beaeb11e0aa9fb8842cb9d8cb9642ab763662..683ac4e807367eeab0301e77eceb95a14c329fac 100644 (file)
@@ -221,15 +221,12 @@ public class StandardEncryptor extends Encryptor {
         final StandardEncryptionHeader header = (StandardEncryptionHeader)info.getHeader();
         final StandardEncryptionVerifier verifier = (StandardEncryptionVerifier)info.getVerifier();
 
-        EncryptionRecord er = new EncryptionRecord(){
-            @Override
-            public void write(LittleEndianByteArrayOutputStream bos) {
-                bos.writeShort(info.getVersionMajor());
-                bos.writeShort(info.getVersionMinor());
-                bos.writeInt(info.getEncryptionFlags());
-                header.write(bos);
-                verifier.write(bos);
-            }
+        EncryptionRecord er = bos -> {
+            bos.writeShort(info.getVersionMajor());
+            bos.writeShort(info.getVersionMinor());
+            bos.writeInt(info.getEncryptionFlags());
+            header.write(bos);
+            verifier.write(bos);
         };
 
         createEncryptionEntry(dir, "EncryptionInfo", er);
index ec20d26ca3a6827f5fc4d9c45485865ebe8c7da7..78696a4c98c608472d15163bc2d7cce2adbaf76e 100644 (file)
@@ -59,11 +59,7 @@ public interface IStabilityClassifier {
      * Convenience implementation for situations where all cell definitions remain fixed after
      * evaluation begins.
      */
-    IStabilityClassifier TOTALLY_IMMUTABLE = new IStabilityClassifier() {
-        public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
-            return true;
-        }
-    };
+    IStabilityClassifier TOTALLY_IMMUTABLE = (sheetIndex, rowIndex, columnIndex) -> true;
 
     /**
      * Checks if a cell's value(/formula) is fixed - in other words - not expected to be modified
index eca5d422b47f5a9f1349add76df4399263d6cf19..e74cfc143385b9ef8f77f177c9dd04713181bea2 100644 (file)
@@ -68,22 +68,19 @@ public final class Count implements Function {
         return new NumberEval(temp);
     }
 
-    private static final I_MatchPredicate defaultPredicate = new I_MatchPredicate() {
+    private static final I_MatchPredicate defaultPredicate = valueEval -> {
 
-        public boolean matches(ValueEval valueEval) {
-
-            if(valueEval instanceof NumberEval) {
-                // only numbers are counted
-                return true;
-            }
-            if(valueEval == MissingArgEval.instance) {
-                // oh yeah, and missing arguments
-                return true;
-            }
-
-            // error values and string values not counted
-            return false;
+        if(valueEval instanceof NumberEval) {
+            // only numbers are counted
+            return true;
         }
+        if(valueEval == MissingArgEval.instance) {
+            // oh yeah, and missing arguments
+            return true;
+        }
+
+        // error values and string values not counted
+        return false;
     };
 
     /**
index 6ed0ad03ce4ea8470ad0900588db01537b2681d9..e89c326f73a89d1f515f6bc5fb58d0538f038c9a 100644 (file)
@@ -64,19 +64,16 @@ public final class Counta implements Function {
         return new NumberEval(temp);
     }
 
-    private static final I_MatchPredicate defaultPredicate = new I_MatchPredicate() {
+    private static final I_MatchPredicate defaultPredicate = valueEval -> {
+        // Note - observed behavior of Excel:
+        // Error values like #VALUE!, #REF!, #DIV/0!, #NAME? etc don't cause this COUNTA to return an error
+        // in fact, they seem to get counted
 
-        public boolean matches(ValueEval valueEval) {
-            // Note - observed behavior of Excel:
-            // Error values like #VALUE!, #REF!, #DIV/0!, #NAME? etc don't cause this COUNTA to return an error
-            // in fact, they seem to get counted
-
-            if(valueEval == BlankEval.instance) {
-                return false;
-            }
-            // Note - everything but BlankEval counts
-            return true;
+        if(valueEval == BlankEval.instance) {
+            return false;
         }
+        // Note - everything but BlankEval counts
+        return true;
     };
 
     private static final I_MatchPredicate subtotalPredicate = new I_MatchAreaPredicate() {
index 59343bb2dd9b21a083e590b1b55a9f535d006aea..d389aace2c51156a2d47673354c429ff76e71bde 100644 (file)
@@ -29,12 +29,7 @@ package org.apache.poi.ss.formula.functions;
  */
 public final class Sumx2my2 extends XYNumericFunction {
 
-    private static final Accumulator XSquaredMinusYSquaredAccumulator = new Accumulator() {
-        @Override
-        public double accumulate(double x, double y) {
-            return x * x - y * y;
-        }
-    };
+    private static final Accumulator XSquaredMinusYSquaredAccumulator = (x, y) -> x * x - y * y;
 
     @Override
     protected Accumulator createAccumulator() {
index a438cb639a247494c35591a44bd93e620696f048..6e39920f0fec4407e70f66de47710154245ffa49 100644 (file)
@@ -29,12 +29,7 @@ package org.apache.poi.ss.formula.functions;
  */
 public final class Sumx2py2 extends XYNumericFunction {
 
-    private static final Accumulator XSquaredPlusYSquaredAccumulator = new Accumulator() {
-        @Override
-        public double accumulate(double x, double y) {
-            return x * x + y * y;
-        }
-    };
+    private static final Accumulator XSquaredPlusYSquaredAccumulator = (x, y) -> x * x + y * y;
 
     @Override
     protected Accumulator createAccumulator() {
index 681104e6d5c8cd3e2513c6a08d276c147ff230a0..a8063654da7c757e6a71b3024136f7b6d88e2e43 100644 (file)
@@ -28,12 +28,9 @@ package org.apache.poi.ss.formula.functions;
  */
 public final class Sumxmy2 extends XYNumericFunction {
 
-    private static final Accumulator XMinusYSquaredAccumulator = new Accumulator() {
-        @Override
-        public double accumulate(double x, double y) {
-            double xmy = x - y;
-            return xmy * xmy;
-        }
+    private static final Accumulator XMinusYSquaredAccumulator = (x, y) -> {
+        double xmy = x - y;
+        return xmy * xmy;
     };
 
     @Override