import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
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.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
* See <a href="https://poi.apache.org/spreadsheet/how-to.html#sxssf">SXSSF (Streaming Usermodel API)</a>.
*/
public final class BigGridDemo {
+ private static final Logger LOG = LogManager.getLogger(BigGridDemo.class);
private static final String XML_ENCODING = "UTF-8";
private static final Random rnd = new Random();
substitute(new File("template.xlsx"), tmp, sheetRef.substring(1), out);
}
} finally {
- if (tmp != null) tmp.delete();
+ if (tmp != null && tmp.exists()) {
+ if (!tmp.delete()) {
+ LOG.atInfo().log("failed to delete temp file");
+ }
+ }
}
}
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Function;
final Rectangle2D b = getBoundsInPoints();
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) {
final Shape clip = ctx.getClip();
final AffineTransform at = ctx.getTransform();
? winBounds
: emfBounds;
} else {
- b = Stream.of(emfBounds, winBounds, viewBounds).
- min(comparingDouble(r -> diff(r, recBounds))).get();
+ Optional<Rectangle2D> result = Stream.of(emfBounds, winBounds, viewBounds).
+ 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());
HemfGraphics g = new HemfGraphics(ctx, b);
- int idx=0;
+ int idx = 0;
for (HemfRecord r : getRecords()) {
try {
g.draw(r);
vector = LookupUtils.createRowVector(tableArray, 0);
}
int matchedIdx = LookupUtils.xlookupIndexOfValue(lookupValue, vector, matchMode, searchMode);
- return new NumberEval(matchedIdx + 1);
+ return new NumberEval((double)matchedIdx + 1);
} catch (EvaluationException e) {
return e.getErrorEval();
}
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.regex.Matcher;
@Override
public Integer next() {
- return pos--;
+ pos--;
+ if (pos < 0) throw new NoSuchElementException();
+ return pos;
}
};
}
}
double dpm = Math.abs(d)+1;
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);
}
double dpm = Math.abs(d);
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));
}
// Copy CellStyle
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());
} else {
CellStyle srcStyle = srcCell.getCellStyle();