From: PJ Fanning Date: Sun, 12 Jan 2020 11:04:21 +0000 (+0000) Subject: use a few more lambdas X-Git-Tag: REL_4_1_2~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b211a1362c9d0a067bff9de057e2ae12b3f8d774;p=poi.git use a few more lambdas git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872644 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java index 752e7e1a8b..78b93a0e41 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java @@ -685,17 +685,14 @@ public final class PageSettingsBlock extends RecordAggregate { for (RecordBase rb : sheetRecords) { if (rb instanceof CustomViewSettingsRecordAggregate) { final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb; - cv.visitContainedRecords(new RecordVisitor() { - @Override - public void visitRecord(org.apache.poi.hssf.record.Record r) { - if (r.getSid() == UserSViewBegin.sid) { - String guid = HexDump.toHex(((UserSViewBegin) r).getGuid()); - HeaderFooterRecord hf = hfGuidMap.get(guid); - - if (hf != null) { - cv.append(hf); - _sviewHeaderFooters.remove(hf); - } + cv.visitContainedRecords(r -> { + if (r.getSid() == UserSViewBegin.sid) { + String guid = HexDump.toHex(((UserSViewBegin) r).getGuid()); + HeaderFooterRecord hf = hfGuidMap.get(guid); + + if (hf != null) { + cv.append(hf); + _sviewHeaderFooters.remove(hf); } } }); diff --git a/src/java/org/apache/poi/ss/formula/EvaluationCache.java b/src/java/org/apache/poi/ss/formula/EvaluationCache.java index ff655f36bb..451ccc7ba3 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationCache.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationCache.java @@ -118,12 +118,7 @@ final class EvaluationCache { private void updateAnyBlankReferencingFormulas(int bookIndex, int sheetIndex, final int rowIndex, final int columnIndex) { final BookSheetKey bsk = new BookSheetKey(bookIndex, sheetIndex); - _formulaCellCache.applyOperation(new IEntryOperation() { - - public void processEntry(FormulaCellCacheEntry entry) { - entry.notifyUpdatedBlankCell(bsk, rowIndex, columnIndex, _evaluationListener); - } - }); + _formulaCellCache.applyOperation(entry -> entry.notifyUpdatedBlankCell(bsk, rowIndex, columnIndex, _evaluationListener)); } public PlainValueCellCacheEntry getPlainValueEntry(int bookIndex, int sheetIndex, diff --git a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java index fe7b087c2c..8b583e44df 100644 --- a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java +++ b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java @@ -40,12 +40,7 @@ public class TestPresetGeometries { for(String name : shapes.keySet()) { CustomGeometry geom = shapes.get(name); - Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() { - @Override - public Guide getAdjustValue(String presetName) { - return null; - } - }); + Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), presetName -> null); for(Path p : geom){ Path2D path = p.getPath(ctx); assertNotNull(path); diff --git a/src/testcases/org/apache/poi/ss/util/NumberComparisonExamples.java b/src/testcases/org/apache/poi/ss/util/NumberComparisonExamples.java index 325d15dc4a..925f968b37 100644 --- a/src/testcases/org/apache/poi/ss/util/NumberComparisonExamples.java +++ b/src/testcases/org/apache/poi/ss/util/NumberComparisonExamples.java @@ -28,152 +28,138 @@ import java.util.List; */ final class NumberComparisonExamples { - private NumberComparisonExamples() { - // no instances of this class - } - - /** - * represents one comparison test case - */ - public static final class ComparisonExample { - private final long _rawBitsA; - private final long _rawBitsB; - private final int _expectedResult; - - public ComparisonExample(long rawBitsA, long rawBitsB, int expectedResult) { - _rawBitsA = rawBitsA; - _rawBitsB = rawBitsB; - _expectedResult = expectedResult; - } - - public double getA() { - return Double.longBitsToDouble(_rawBitsA); - } - public double getB() { - return Double.longBitsToDouble(_rawBitsB); - } - public double getNegA() { - return -Double.longBitsToDouble(_rawBitsA); - } - public double getNegB() { - return -Double.longBitsToDouble(_rawBitsB); - } - public int getExpectedResult() { - return _expectedResult; - } - } - - private static final ComparisonExample[] examples = initExamples(); - - private static ComparisonExample[] initExamples() { - - List temp = new ArrayList<>(); - - addStepTransition(temp, 0x4010000000000005L); - addStepTransition(temp, 0x4010000000000010L); - addStepTransition(temp, 0x401000000000001CL); - - addStepTransition(temp, 0x403CE0FFFFFFFFF1L); - - addStepTransition(temp, 0x5010000000000006L); - addStepTransition(temp, 0x5010000000000010L); - addStepTransition(temp, 0x501000000000001AL); - - addStepTransition(temp, 0x544CE6345CF32018L); - addStepTransition(temp, 0x544CE6345CF3205AL); - addStepTransition(temp, 0x544CE6345CF3209CL); - addStepTransition(temp, 0x544CE6345CF320DEL); - - addStepTransition(temp, 0x54B250001000101DL); - addStepTransition(temp, 0x54B2500010001050L); - addStepTransition(temp, 0x54B2500010001083L); - - addStepTransition(temp, 0x6230100010001000L); - addStepTransition(temp, 0x6230100010001005L); - addStepTransition(temp, 0x623010001000100AL); - - addStepTransition(temp, 0x7F50300020001011L); - addStepTransition(temp, 0x7F5030002000102BL); - addStepTransition(temp, 0x7F50300020001044L); - - - addStepTransition(temp, 0x2B2BFFFF1000102AL); - addStepTransition(temp, 0x2B2BFFFF10001079L); - addStepTransition(temp, 0x2B2BFFFF100010C8L); - - addStepTransition(temp, 0x2B2BFF001000102DL); - addStepTransition(temp, 0x2B2BFF0010001035L); - addStepTransition(temp, 0x2B2BFF001000103DL); - - addStepTransition(temp, 0x2B61800040002024L); - addStepTransition(temp, 0x2B61800040002055L); - addStepTransition(temp, 0x2B61800040002086L); - - - addStepTransition(temp, 0x008000000000000BL); - // just outside 'subnormal' range - addStepTransition(temp, 0x0010000000000007L); - addStepTransition(temp, 0x001000000000001BL); - addStepTransition(temp, 0x001000000000002FL); - - Collections.addAll(temp, new ComparisonExample[]{ - // negative, and exponents differ by more than 1 - ce(0xBF30000000000000L, 0xBE60000000000000L, -1), - - // negative zero *is* less than positive zero, but not easy to get out of calculations - ce(0x0000000000000000L, 0x8000000000000000L, +1), - // subnormal numbers compare without rounding for some reason - ce(0x0000000000000000L, 0x0000000000000001L, -1), - ce(0x0008000000000000L, 0x0008000000000001L, -1), - ce(0x000FFFFFFFFFFFFFL, 0x000FFFFFFFFFFFFEL, +1), - ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFCL, -1), - ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFEL, -1), - - // across subnormal threshold (some mistakes when close) - ce(0x000FFFFFFFFFFFFFL, 0x0010000000000000L, +1), - ce(0x000FFFFFFFFFFFFBL, 0x0010000000000007L, +1), - ce(0x000FFFFFFFFFFFFAL, 0x0010000000000007L, 0), - - // when a bit further apart - normal results - ce(0x000FFFFFFFFFFFF9L, 0x0010000000000007L, -1), - ce(0x000FFFFFFFFFFFFAL, 0x0010000000000008L, -1), - ce(0x000FFFFFFFFFFFFBL, 0x0010000000000008L, -1), - }); - - ComparisonExample[] result = new ComparisonExample[temp.size()]; - temp.toArray(result); - return result; - } - - private static ComparisonExample ce(long rawBitsA, long rawBitsB, int expectedResult) { - return new ComparisonExample(rawBitsA, rawBitsB, expectedResult); - } - - private static void addStepTransition(List temp, long rawBits) { - Collections.addAll(temp, new ComparisonExample[]{ - ce(rawBits - 1, rawBits + 0, 0), - ce(rawBits + 0, rawBits + 1, -1), - ce(rawBits + 1, rawBits + 2, 0), - }); - - } + private NumberComparisonExamples() { + // no instances of this class + } + + /** + * represents one comparison test case + */ + public static final class ComparisonExample { + private final long _rawBitsA; + private final long _rawBitsB; + private final int _expectedResult; + + public ComparisonExample(long rawBitsA, long rawBitsB, int expectedResult) { + _rawBitsA = rawBitsA; + _rawBitsB = rawBitsB; + _expectedResult = expectedResult; + } + + public double getA() { + return Double.longBitsToDouble(_rawBitsA); + } + public double getB() { + return Double.longBitsToDouble(_rawBitsB); + } + public double getNegA() { + return -Double.longBitsToDouble(_rawBitsA); + } + public double getNegB() { + return -Double.longBitsToDouble(_rawBitsB); + } + public int getExpectedResult() { + return _expectedResult; + } + } + + private static final ComparisonExample[] examples = initExamples(); + + private static ComparisonExample[] initExamples() { + + List temp = new ArrayList<>(); + + addStepTransition(temp, 0x4010000000000005L); + addStepTransition(temp, 0x4010000000000010L); + addStepTransition(temp, 0x401000000000001CL); + + addStepTransition(temp, 0x403CE0FFFFFFFFF1L); + + addStepTransition(temp, 0x5010000000000006L); + addStepTransition(temp, 0x5010000000000010L); + addStepTransition(temp, 0x501000000000001AL); + + addStepTransition(temp, 0x544CE6345CF32018L); + addStepTransition(temp, 0x544CE6345CF3205AL); + addStepTransition(temp, 0x544CE6345CF3209CL); + addStepTransition(temp, 0x544CE6345CF320DEL); + + addStepTransition(temp, 0x54B250001000101DL); + addStepTransition(temp, 0x54B2500010001050L); + addStepTransition(temp, 0x54B2500010001083L); + + addStepTransition(temp, 0x6230100010001000L); + addStepTransition(temp, 0x6230100010001005L); + addStepTransition(temp, 0x623010001000100AL); + + addStepTransition(temp, 0x7F50300020001011L); + addStepTransition(temp, 0x7F5030002000102BL); + addStepTransition(temp, 0x7F50300020001044L); + + + addStepTransition(temp, 0x2B2BFFFF1000102AL); + addStepTransition(temp, 0x2B2BFFFF10001079L); + addStepTransition(temp, 0x2B2BFFFF100010C8L); + + addStepTransition(temp, 0x2B2BFF001000102DL); + addStepTransition(temp, 0x2B2BFF0010001035L); + addStepTransition(temp, 0x2B2BFF001000103DL); + + addStepTransition(temp, 0x2B61800040002024L); + addStepTransition(temp, 0x2B61800040002055L); + addStepTransition(temp, 0x2B61800040002086L); + + + addStepTransition(temp, 0x008000000000000BL); + // just outside 'subnormal' range + addStepTransition(temp, 0x0010000000000007L); + addStepTransition(temp, 0x001000000000001BL); + addStepTransition(temp, 0x001000000000002FL); + + Collections.addAll(temp, new ComparisonExample[]{ + // negative, and exponents differ by more than 1 + ce(0xBF30000000000000L, 0xBE60000000000000L, -1), + + // negative zero *is* less than positive zero, but not easy to get out of calculations + ce(0x0000000000000000L, 0x8000000000000000L, +1), + // subnormal numbers compare without rounding for some reason + ce(0x0000000000000000L, 0x0000000000000001L, -1), + ce(0x0008000000000000L, 0x0008000000000001L, -1), + ce(0x000FFFFFFFFFFFFFL, 0x000FFFFFFFFFFFFEL, +1), + ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFCL, -1), + ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFEL, -1), + + // across subnormal threshold (some mistakes when close) + ce(0x000FFFFFFFFFFFFFL, 0x0010000000000000L, +1), + ce(0x000FFFFFFFFFFFFBL, 0x0010000000000007L, +1), + ce(0x000FFFFFFFFFFFFAL, 0x0010000000000007L, 0), + + // when a bit further apart - normal results + ce(0x000FFFFFFFFFFFF9L, 0x0010000000000007L, -1), + ce(0x000FFFFFFFFFFFFAL, 0x0010000000000008L, -1), + ce(0x000FFFFFFFFFFFFBL, 0x0010000000000008L, -1), + }); + + ComparisonExample[] result = new ComparisonExample[temp.size()]; + temp.toArray(result); + return result; + } + + private static ComparisonExample ce(long rawBitsA, long rawBitsB, int expectedResult) { + return new ComparisonExample(rawBitsA, rawBitsB, expectedResult); + } + + private static void addStepTransition(List temp, long rawBits) { + Collections.addAll(temp, new ComparisonExample[]{ + ce(rawBits - 1, rawBits + 0, 0), + ce(rawBits + 0, rawBits + 1, -1), + ce(rawBits + 1, rawBits + 2, 0), + }); - public static ComparisonExample[] getComparisonExamples() { - return examples.clone(); - } + } - public static ComparisonExample[] getComparisonExamples2() { - ComparisonExample[] result = examples.clone(); + public static ComparisonExample[] getComparisonExamples() { + return examples.clone(); + } - for (int i = 0; i < result.length; i++) { - int ha = ("a"+i).hashCode(); - double a = ha * Math.pow(0.75, ha % 100); - int hb = ("b"+i).hashCode(); - double b = hb * Math.pow(0.75, hb % 100); - - result[i] = new ComparisonExample(Double.doubleToLongBits(a), Double.doubleToLongBits(b), Double.compare(a, b)); - } - - return result; - } }