[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
This commit is contained in:
PJ Fanning 2022-08-06 21:12:49 +00:00
parent eaa27548fa
commit bbfd7b9ec8
15 changed files with 61 additions and 124 deletions

View 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);

View 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) {

View 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);
};
}

View 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) {

View 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));

View 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));

View 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);
}
});
}

View 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);
}

View 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);

View 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

View 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;
};
/**

View 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() {

View 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() {

View 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() {

View 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