From: PJ Fanning Date: Sat, 6 Aug 2022 21:12:49 +0000 (+0000) Subject: [github-365] use lambdas. Thanks to Arturo Bernal. This closes #365 X-Git-Tag: REL_5_2_3~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bbfd7b9ec86e1912d2adf61fc77c800e6a8a074e;p=poi.git [github-365] use lambdas. Thanks to Arturo Bernal. This closes #365 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903258 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java index 49feb3f7aa..308008a4a3 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java @@ -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); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java index 2e4d89647d..158927e7ef 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/shape/ShapeVisitor.java @@ -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) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/util/CTColComparator.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/util/CTColComparator.java index ef8e526a43..bc6d7dde97 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/util/CTColComparator.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/util/CTColComparator.java @@ -25,22 +25,16 @@ public class CTColComparator { private CTColComparator() {} - public static final Comparator BY_MAX = new Comparator() { - @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 BY_MAX = (col1, col2) -> { + long col1max = col1.getMax(); + long col2max = col2.getMax(); + return Long.compare(col1max, col2max); }; - public static final Comparator BY_MIN_MAX = new Comparator() { - @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 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); }; } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java index d29ffc2b94..a992bd0cc9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java @@ -32,20 +32,12 @@ public class TypesLister { public void listByName(PrintStream out) { ArrayList all = new ArrayList<>(MAPIProperty.getAll()); - all.sort(new Comparator() { - 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 all = new ArrayList<>(MAPIProperty.getAll()); - all.sort(new Comparator() { - 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 list, PrintStream out) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPBinTable.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPBinTable.java index 3f2bd01081..42b28dd500 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPBinTable.java @@ -178,14 +178,10 @@ public class CHPBinTable chpxToFileOrder.put( chpx, Integer.valueOf( counter++ ) ); } } - final Comparator chpxFileOrderComparator = new Comparator() - { - public int compare( CHPX o1, CHPX o2 ) - { - Integer i1 = chpxToFileOrder.get( o1 ); - Integer i2 = chpxToFileOrder.get( o2 ); - return i1.compareTo( i2 ); - } + final Comparator 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)); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PAPBinTable.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PAPBinTable.java index 917c7d8958..03b231a9e5 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PAPBinTable.java @@ -164,14 +164,10 @@ public class PAPBinTable papxToFileOrder.put( papx, Integer.valueOf( counter++ ) ); } } - final Comparator papxFileOrderComparator = new Comparator() - { - public int compare( PAPX o1, PAPX o2 ) - { - Integer i1 = papxToFileOrder.get( o1 ); - Integer i2 = papxToFileOrder.get( o2 ); - return i1.compareTo( i2 ); - } + final Comparator 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)); diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java index bebd3643cf..a37aa7ceeb 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java @@ -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); } }); } diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java index d543063121..64139ca6b2 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java @@ -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); } diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java index 0e1beaeb11..683ac4e807 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java @@ -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); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/IStabilityClassifier.java b/poi/src/main/java/org/apache/poi/ss/formula/IStabilityClassifier.java index ec20d26ca3..78696a4c98 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/IStabilityClassifier.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/IStabilityClassifier.java @@ -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 diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Count.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Count.java index eca5d422b4..e74cfc1433 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Count.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Count.java @@ -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; }; /** diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Counta.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Counta.java index 6ed0ad03ce..e89c326f73 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Counta.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Counta.java @@ -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() { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2my2.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2my2.java index 59343bb2dd..d389aace2c 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2my2.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2my2.java @@ -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() { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2py2.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2py2.java index a438cb639a..6e39920f0f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2py2.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumx2py2.java @@ -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() { diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumxmy2.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumxmy2.java index 681104e6d5..a8063654da 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumxmy2.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Sumxmy2.java @@ -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