mirror of https://github.com/apache/poi.git
update some code based on sonar issues
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896504 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
79a1e6b1e9
commit
6784dd81c2
|
@ -34,6 +34,8 @@ import java.util.Random;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
import org.apache.poi.ss.usermodel.DateUtil;
|
||||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||||
|
@ -73,6 +75,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
* See <a href="https://poi.apache.org/spreadsheet/how-to.html#sxssf">SXSSF (Streaming Usermodel API)</a>.
|
* See <a href="https://poi.apache.org/spreadsheet/how-to.html#sxssf">SXSSF (Streaming Usermodel API)</a>.
|
||||||
*/
|
*/
|
||||||
public final class BigGridDemo {
|
public final class BigGridDemo {
|
||||||
|
private static final Logger LOG = LogManager.getLogger(BigGridDemo.class);
|
||||||
private static final String XML_ENCODING = "UTF-8";
|
private static final String XML_ENCODING = "UTF-8";
|
||||||
|
|
||||||
private static final Random rnd = new Random();
|
private static final Random rnd = new Random();
|
||||||
|
@ -111,7 +114,11 @@ public final class BigGridDemo {
|
||||||
substitute(new File("template.xlsx"), tmp, sheetRef.substring(1), out);
|
substitute(new File("template.xlsx"), tmp, sheetRef.substring(1), out);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (tmp != null) tmp.delete();
|
if (tmp != null && tmp.exists()) {
|
||||||
|
if (!tmp.delete()) {
|
||||||
|
LOG.atInfo().log("failed to delete temp file");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Spliterator;
|
import java.util.Spliterator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -205,6 +206,12 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
|
||||||
final Rectangle2D b = getBoundsInPoints();
|
final Rectangle2D b = getBoundsInPoints();
|
||||||
return new Dimension2DDouble(abs(b.getWidth()), abs(b.getHeight()));
|
return new Dimension2DDouble(abs(b.getWidth()), abs(b.getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ctx
|
||||||
|
* @param graphicsBounds
|
||||||
|
* @throws IllegalStateException if the draw fails
|
||||||
|
*/
|
||||||
public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
|
public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
|
||||||
final Shape clip = ctx.getClip();
|
final Shape clip = ctx.getClip();
|
||||||
final AffineTransform at = ctx.getTransform();
|
final AffineTransform at = ctx.getTransform();
|
||||||
|
@ -232,8 +239,13 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
|
||||||
? winBounds
|
? winBounds
|
||||||
: emfBounds;
|
: emfBounds;
|
||||||
} else {
|
} else {
|
||||||
b = Stream.of(emfBounds, winBounds, viewBounds).
|
Optional<Rectangle2D> result = Stream.of(emfBounds, winBounds, viewBounds).
|
||||||
min(comparingDouble(r -> diff(r, recBounds))).get();
|
min(comparingDouble(r -> diff(r, recBounds)));
|
||||||
|
if (result.isPresent()) {
|
||||||
|
b = result.get();
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Failed to create Rectangle2D for drawing");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
|
ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
|
||||||
|
|
|
@ -94,7 +94,7 @@ final class XMatchFunction implements FreeRefFunction {
|
||||||
vector = LookupUtils.createRowVector(tableArray, 0);
|
vector = LookupUtils.createRowVector(tableArray, 0);
|
||||||
}
|
}
|
||||||
int matchedIdx = LookupUtils.xlookupIndexOfValue(lookupValue, vector, matchMode, searchMode);
|
int matchedIdx = LookupUtils.xlookupIndexOfValue(lookupValue, vector, matchMode, searchMode);
|
||||||
return new NumberEval(matchedIdx + 1);
|
return new NumberEval((double)matchedIdx + 1);
|
||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
return e.getErrorEval();
|
return e.getErrorEval();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Spliterator;
|
import java.util.Spliterator;
|
||||||
import java.util.Spliterators;
|
import java.util.Spliterators;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -142,7 +143,9 @@ public final class LookupUtils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer next() {
|
public Integer next() {
|
||||||
return pos--;
|
pos--;
|
||||||
|
if (pos < 0) throw new NoSuchElementException();
|
||||||
|
return pos;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public abstract class NumericFunction implements Function {
|
||||||
}
|
}
|
||||||
double dpm = Math.abs(d)+1;
|
double dpm = Math.abs(d)+1;
|
||||||
long x = ((long) dpm) & PARITY_MASK;
|
long x = ((long) dpm) & PARITY_MASK;
|
||||||
return MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x-1 : x+1);
|
return (double) MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x-1 : x+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ public abstract class NumericFunction implements Function {
|
||||||
|
|
||||||
double dpm = Math.abs(d);
|
double dpm = Math.abs(d);
|
||||||
long x = ((long) dpm) & PARITY_MASK;
|
long x = ((long) dpm) & PARITY_MASK;
|
||||||
return MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x : (x + 2));
|
return (double) MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x : (x + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,8 @@ public final class CellUtil {
|
||||||
|
|
||||||
// Copy CellStyle
|
// Copy CellStyle
|
||||||
if (policy.isCopyCellStyle()) {
|
if (policy.isCopyCellStyle()) {
|
||||||
if (destCell.getSheet().getWorkbook() == srcCell.getSheet().getWorkbook()) {
|
if (srcCell.getSheet() != null && destCell.getSheet() != null &&
|
||||||
|
destCell.getSheet().getWorkbook() == srcCell.getSheet().getWorkbook()) {
|
||||||
destCell.setCellStyle(srcCell.getCellStyle());
|
destCell.setCellStyle(srcCell.getCellStyle());
|
||||||
} else {
|
} else {
|
||||||
CellStyle srcStyle = srcCell.getCellStyle();
|
CellStyle srcStyle = srcCell.getCellStyle();
|
||||||
|
|
Loading…
Reference in New Issue