]> source.dussan.org Git - poi.git/commitdiff
use a few more lambdas
authorPJ Fanning <fanningpj@apache.org>
Sun, 12 Jan 2020 11:04:21 +0000 (11:04 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 12 Jan 2020 11:04:21 +0000 (11:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872644 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
src/java/org/apache/poi/ss/formula/EvaluationCache.java
src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
src/testcases/org/apache/poi/ss/util/NumberComparisonExamples.java

index 752e7e1a8bb8541c94ccb0172d6f51a8dda486e4..78b93a0e41287682e9851427f29dc6fbcc9072b3 100644 (file)
@@ -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);
                         }
                     }
                 });
index ff655f36bbd27556d2dfcb39c977bff21329af93..451ccc7ba3467238615e5fc226d932fbb973e391 100644 (file)
@@ -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,
index fe7b087c2c3fa67b955c4f0dfcbd0a5eaea29fe0..8b583e44df10c1caec711346ebc8b02b388f94b4 100644 (file)
@@ -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);
index 325d15dc4abc5dbb44591e6a2a701ae95379dac1..925f968b37021c5f081867ef6ebbc28f42b7d749 100644 (file)
@@ -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<ComparisonExample> 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<ComparisonExample> 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<ComparisonExample> 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<ComparisonExample> 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;
-       }
 }