use a few more lambdas

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872644 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2020-01-12 11:04:21 +00:00
parent aa11adebf1
commit b211a1362c
4 changed files with 114 additions and 141 deletions

View File

@ -685,17 +685,14 @@ public final class PageSettingsBlock extends RecordAggregate {
for (RecordBase rb : sheetRecords) { for (RecordBase rb : sheetRecords) {
if (rb instanceof CustomViewSettingsRecordAggregate) { if (rb instanceof CustomViewSettingsRecordAggregate) {
final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb; final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate) rb;
cv.visitContainedRecords(new RecordVisitor() { cv.visitContainedRecords(r -> {
@Override if (r.getSid() == UserSViewBegin.sid) {
public void visitRecord(org.apache.poi.hssf.record.Record r) { String guid = HexDump.toHex(((UserSViewBegin) r).getGuid());
if (r.getSid() == UserSViewBegin.sid) { HeaderFooterRecord hf = hfGuidMap.get(guid);
String guid = HexDump.toHex(((UserSViewBegin) r).getGuid());
HeaderFooterRecord hf = hfGuidMap.get(guid);
if (hf != null) { if (hf != null) {
cv.append(hf); cv.append(hf);
_sviewHeaderFooters.remove(hf); _sviewHeaderFooters.remove(hf);
}
} }
} }
}); });

View File

@ -118,12 +118,7 @@ final class EvaluationCache {
private void updateAnyBlankReferencingFormulas(int bookIndex, int sheetIndex, private void updateAnyBlankReferencingFormulas(int bookIndex, int sheetIndex,
final int rowIndex, final int columnIndex) { final int rowIndex, final int columnIndex) {
final BookSheetKey bsk = new BookSheetKey(bookIndex, sheetIndex); final BookSheetKey bsk = new BookSheetKey(bookIndex, sheetIndex);
_formulaCellCache.applyOperation(new IEntryOperation() { _formulaCellCache.applyOperation(entry -> entry.notifyUpdatedBlankCell(bsk, rowIndex, columnIndex, _evaluationListener));
public void processEntry(FormulaCellCacheEntry entry) {
entry.notifyUpdatedBlankCell(bsk, rowIndex, columnIndex, _evaluationListener);
}
});
} }
public PlainValueCellCacheEntry getPlainValueEntry(int bookIndex, int sheetIndex, public PlainValueCellCacheEntry getPlainValueEntry(int bookIndex, int sheetIndex,

View File

@ -40,12 +40,7 @@ public class TestPresetGeometries {
for(String name : shapes.keySet()) { for(String name : shapes.keySet()) {
CustomGeometry geom = shapes.get(name); CustomGeometry geom = shapes.get(name);
Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() { Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), presetName -> null);
@Override
public Guide getAdjustValue(String presetName) {
return null;
}
});
for(Path p : geom){ for(Path p : geom){
Path2D path = p.getPath(ctx); Path2D path = p.getPath(ctx);
assertNotNull(path); assertNotNull(path);

View File

@ -28,152 +28,138 @@ import java.util.List;
*/ */
final class NumberComparisonExamples { final class NumberComparisonExamples {
private NumberComparisonExamples() { private NumberComparisonExamples() {
// no instances of this class // no instances of this class
} }
/** /**
* represents one comparison test case * represents one comparison test case
*/ */
public static final class ComparisonExample { public static final class ComparisonExample {
private final long _rawBitsA; private final long _rawBitsA;
private final long _rawBitsB; private final long _rawBitsB;
private final int _expectedResult; private final int _expectedResult;
public ComparisonExample(long rawBitsA, long rawBitsB, int expectedResult) { public ComparisonExample(long rawBitsA, long rawBitsB, int expectedResult) {
_rawBitsA = rawBitsA; _rawBitsA = rawBitsA;
_rawBitsB = rawBitsB; _rawBitsB = rawBitsB;
_expectedResult = expectedResult; _expectedResult = expectedResult;
} }
public double getA() { public double getA() {
return Double.longBitsToDouble(_rawBitsA); return Double.longBitsToDouble(_rawBitsA);
} }
public double getB() { public double getB() {
return Double.longBitsToDouble(_rawBitsB); return Double.longBitsToDouble(_rawBitsB);
} }
public double getNegA() { public double getNegA() {
return -Double.longBitsToDouble(_rawBitsA); return -Double.longBitsToDouble(_rawBitsA);
} }
public double getNegB() { public double getNegB() {
return -Double.longBitsToDouble(_rawBitsB); return -Double.longBitsToDouble(_rawBitsB);
} }
public int getExpectedResult() { public int getExpectedResult() {
return _expectedResult; return _expectedResult;
} }
} }
private static final ComparisonExample[] examples = initExamples(); private static final ComparisonExample[] examples = initExamples();
private static ComparisonExample[] initExamples() { private static ComparisonExample[] initExamples() {
List<ComparisonExample> temp = new ArrayList<>(); List<ComparisonExample> temp = new ArrayList<>();
addStepTransition(temp, 0x4010000000000005L); addStepTransition(temp, 0x4010000000000005L);
addStepTransition(temp, 0x4010000000000010L); addStepTransition(temp, 0x4010000000000010L);
addStepTransition(temp, 0x401000000000001CL); addStepTransition(temp, 0x401000000000001CL);
addStepTransition(temp, 0x403CE0FFFFFFFFF1L); addStepTransition(temp, 0x403CE0FFFFFFFFF1L);
addStepTransition(temp, 0x5010000000000006L); addStepTransition(temp, 0x5010000000000006L);
addStepTransition(temp, 0x5010000000000010L); addStepTransition(temp, 0x5010000000000010L);
addStepTransition(temp, 0x501000000000001AL); addStepTransition(temp, 0x501000000000001AL);
addStepTransition(temp, 0x544CE6345CF32018L); addStepTransition(temp, 0x544CE6345CF32018L);
addStepTransition(temp, 0x544CE6345CF3205AL); addStepTransition(temp, 0x544CE6345CF3205AL);
addStepTransition(temp, 0x544CE6345CF3209CL); addStepTransition(temp, 0x544CE6345CF3209CL);
addStepTransition(temp, 0x544CE6345CF320DEL); addStepTransition(temp, 0x544CE6345CF320DEL);
addStepTransition(temp, 0x54B250001000101DL); addStepTransition(temp, 0x54B250001000101DL);
addStepTransition(temp, 0x54B2500010001050L); addStepTransition(temp, 0x54B2500010001050L);
addStepTransition(temp, 0x54B2500010001083L); addStepTransition(temp, 0x54B2500010001083L);
addStepTransition(temp, 0x6230100010001000L); addStepTransition(temp, 0x6230100010001000L);
addStepTransition(temp, 0x6230100010001005L); addStepTransition(temp, 0x6230100010001005L);
addStepTransition(temp, 0x623010001000100AL); addStepTransition(temp, 0x623010001000100AL);
addStepTransition(temp, 0x7F50300020001011L); addStepTransition(temp, 0x7F50300020001011L);
addStepTransition(temp, 0x7F5030002000102BL); addStepTransition(temp, 0x7F5030002000102BL);
addStepTransition(temp, 0x7F50300020001044L); addStepTransition(temp, 0x7F50300020001044L);
addStepTransition(temp, 0x2B2BFFFF1000102AL); addStepTransition(temp, 0x2B2BFFFF1000102AL);
addStepTransition(temp, 0x2B2BFFFF10001079L); addStepTransition(temp, 0x2B2BFFFF10001079L);
addStepTransition(temp, 0x2B2BFFFF100010C8L); addStepTransition(temp, 0x2B2BFFFF100010C8L);
addStepTransition(temp, 0x2B2BFF001000102DL); addStepTransition(temp, 0x2B2BFF001000102DL);
addStepTransition(temp, 0x2B2BFF0010001035L); addStepTransition(temp, 0x2B2BFF0010001035L);
addStepTransition(temp, 0x2B2BFF001000103DL); addStepTransition(temp, 0x2B2BFF001000103DL);
addStepTransition(temp, 0x2B61800040002024L); addStepTransition(temp, 0x2B61800040002024L);
addStepTransition(temp, 0x2B61800040002055L); addStepTransition(temp, 0x2B61800040002055L);
addStepTransition(temp, 0x2B61800040002086L); addStepTransition(temp, 0x2B61800040002086L);
addStepTransition(temp, 0x008000000000000BL); addStepTransition(temp, 0x008000000000000BL);
// just outside 'subnormal' range // just outside 'subnormal' range
addStepTransition(temp, 0x0010000000000007L); addStepTransition(temp, 0x0010000000000007L);
addStepTransition(temp, 0x001000000000001BL); addStepTransition(temp, 0x001000000000001BL);
addStepTransition(temp, 0x001000000000002FL); addStepTransition(temp, 0x001000000000002FL);
Collections.addAll(temp, new ComparisonExample[]{ Collections.addAll(temp, new ComparisonExample[]{
// negative, and exponents differ by more than 1 // negative, and exponents differ by more than 1
ce(0xBF30000000000000L, 0xBE60000000000000L, -1), ce(0xBF30000000000000L, 0xBE60000000000000L, -1),
// negative zero *is* less than positive zero, but not easy to get out of calculations // negative zero *is* less than positive zero, but not easy to get out of calculations
ce(0x0000000000000000L, 0x8000000000000000L, +1), ce(0x0000000000000000L, 0x8000000000000000L, +1),
// subnormal numbers compare without rounding for some reason // subnormal numbers compare without rounding for some reason
ce(0x0000000000000000L, 0x0000000000000001L, -1), ce(0x0000000000000000L, 0x0000000000000001L, -1),
ce(0x0008000000000000L, 0x0008000000000001L, -1), ce(0x0008000000000000L, 0x0008000000000001L, -1),
ce(0x000FFFFFFFFFFFFFL, 0x000FFFFFFFFFFFFEL, +1), ce(0x000FFFFFFFFFFFFFL, 0x000FFFFFFFFFFFFEL, +1),
ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFCL, -1), ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFCL, -1),
ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFEL, -1), ce(0x000FFFFFFFFFFFFBL, 0x000FFFFFFFFFFFFEL, -1),
// across subnormal threshold (some mistakes when close) // across subnormal threshold (some mistakes when close)
ce(0x000FFFFFFFFFFFFFL, 0x0010000000000000L, +1), ce(0x000FFFFFFFFFFFFFL, 0x0010000000000000L, +1),
ce(0x000FFFFFFFFFFFFBL, 0x0010000000000007L, +1), ce(0x000FFFFFFFFFFFFBL, 0x0010000000000007L, +1),
ce(0x000FFFFFFFFFFFFAL, 0x0010000000000007L, 0), ce(0x000FFFFFFFFFFFFAL, 0x0010000000000007L, 0),
// when a bit further apart - normal results // when a bit further apart - normal results
ce(0x000FFFFFFFFFFFF9L, 0x0010000000000007L, -1), ce(0x000FFFFFFFFFFFF9L, 0x0010000000000007L, -1),
ce(0x000FFFFFFFFFFFFAL, 0x0010000000000008L, -1), ce(0x000FFFFFFFFFFFFAL, 0x0010000000000008L, -1),
ce(0x000FFFFFFFFFFFFBL, 0x0010000000000008L, -1), ce(0x000FFFFFFFFFFFFBL, 0x0010000000000008L, -1),
}); });
ComparisonExample[] result = new ComparisonExample[temp.size()]; ComparisonExample[] result = new ComparisonExample[temp.size()];
temp.toArray(result); temp.toArray(result);
return result; return result;
} }
private static ComparisonExample ce(long rawBitsA, long rawBitsB, int expectedResult) { private static ComparisonExample ce(long rawBitsA, long rawBitsB, int expectedResult) {
return new ComparisonExample(rawBitsA, rawBitsB, expectedResult); return new ComparisonExample(rawBitsA, rawBitsB, expectedResult);
} }
private static void addStepTransition(List<ComparisonExample> temp, long rawBits) { private static void addStepTransition(List<ComparisonExample> temp, long rawBits) {
Collections.addAll(temp, new ComparisonExample[]{ Collections.addAll(temp, new ComparisonExample[]{
ce(rawBits - 1, rawBits + 0, 0), ce(rawBits - 1, rawBits + 0, 0),
ce(rawBits + 0, rawBits + 1, -1), ce(rawBits + 0, rawBits + 1, -1),
ce(rawBits + 1, rawBits + 2, 0), ce(rawBits + 1, rawBits + 2, 0),
}); });
} }
public static ComparisonExample[] getComparisonExamples() { public static ComparisonExample[] getComparisonExamples() {
return examples.clone(); return examples.clone();
} }
public static ComparisonExample[] getComparisonExamples2() {
ComparisonExample[] result = 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;
}
} }