mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-69658] use EnumMap elsewhere
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1925250 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
712c484a65
commit
691c8baa5a
@ -571,7 +571,7 @@ public final class CellUtil {
|
||||
@Deprecated
|
||||
@Removal(version = "7.0.0")
|
||||
public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) {
|
||||
Map<CellPropertyType, Object> strPropMap = new HashMap<>(properties.size());
|
||||
EnumMap<CellPropertyType, Object> strPropMap = new EnumMap<>(CellPropertyType.class);
|
||||
properties.forEach((k, v) -> strPropMap.put(namePropertyMap.get(k), v));
|
||||
setCellStyleProperties(cell, strPropMap, false);
|
||||
}
|
||||
@ -611,7 +611,7 @@ public final class CellUtil {
|
||||
CellStyle originalStyle = cell.getCellStyle();
|
||||
|
||||
CellStyle newStyle = null;
|
||||
Map<CellPropertyType, Object> values = getFormatProperties(originalStyle);
|
||||
EnumMap<CellPropertyType, Object> values = getFormatProperties(originalStyle);
|
||||
if (properties.containsKey(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR) && properties.get(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR) == null) {
|
||||
values.remove(CellPropertyType.FILL_FOREGROUND_COLOR);
|
||||
}
|
||||
@ -777,7 +777,6 @@ public final class CellUtil {
|
||||
*
|
||||
* @param src the property map to copy from (read-only)
|
||||
* @param dest the property map to copy into
|
||||
* @since POI 3.15 beta 3
|
||||
*/
|
||||
private static void putAll(final Map<CellPropertyType, Object> src, Map<CellPropertyType, Object> dest) {
|
||||
for (final CellPropertyType key : src.keySet()) {
|
||||
|
||||
@ -28,7 +28,10 @@ import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.util.Removal;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -42,9 +45,9 @@ import java.util.Set;
|
||||
* sheet in any workbook.
|
||||
*
|
||||
* This class requires the full spreadsheet to be in memory, so
|
||||
* {@link org.apache.poi.xssf.streaming.SXSSFWorkbook} Spreadsheets are not
|
||||
* <code>SXSSFWorkbook</code> Spreadsheets are not
|
||||
* supported. The same PropertyTemplate can, however, be applied to both
|
||||
* {@link HSSFWorkbook} and {@link org.apache.poi.xssf.usermodel.XSSFWorkbook}
|
||||
* {@link HSSFWorkbook} and <code>XSSFWorkbook</code>
|
||||
* objects if necessary. Portions of the border that fall outside the max range
|
||||
* of the {@link Workbook} sheet are ignored.
|
||||
* </p>
|
||||
@ -59,7 +62,7 @@ public final class PropertyTemplate {
|
||||
* This is a list of cell properties for one shot application to a range of
|
||||
* cells at a later time.
|
||||
*/
|
||||
private final Map<CellAddress, Map<CellPropertyType, Object>> _propertyTemplate;
|
||||
private final Map<CellAddress, EnumMap<CellPropertyType, Object>> _propertyTemplate;
|
||||
|
||||
/**
|
||||
* Create a PropertyTemplate object
|
||||
@ -75,17 +78,17 @@ public final class PropertyTemplate {
|
||||
*/
|
||||
public PropertyTemplate(PropertyTemplate template) {
|
||||
this();
|
||||
for (Map.Entry<CellAddress, Map<CellPropertyType, Object>> entry : template.getTemplate().entrySet()) {
|
||||
for (Map.Entry<CellAddress, EnumMap<CellPropertyType, Object>> entry : template.getTemplate().entrySet()) {
|
||||
_propertyTemplate.put(new CellAddress(entry.getKey()), cloneCellProperties(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<CellAddress, Map<CellPropertyType, Object>> getTemplate() {
|
||||
private Map<CellAddress, EnumMap<CellPropertyType, Object>> getTemplate() {
|
||||
return _propertyTemplate;
|
||||
}
|
||||
|
||||
private static Map<CellPropertyType, Object> cloneCellProperties(Map<CellPropertyType, Object> properties) {
|
||||
return new HashMap<>(properties);
|
||||
private static EnumMap<CellPropertyType, Object> cloneCellProperties(EnumMap<CellPropertyType, Object> properties) {
|
||||
return new EnumMap<>(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -433,7 +436,7 @@ public final class PropertyTemplate {
|
||||
*/
|
||||
public void applyBorders(Sheet sheet) {
|
||||
Workbook wb = sheet.getWorkbook();
|
||||
for (Map.Entry<CellAddress, Map<CellPropertyType, Object>> entry : _propertyTemplate
|
||||
for (Map.Entry<CellAddress, EnumMap<CellPropertyType, Object>> entry : _propertyTemplate
|
||||
.entrySet()) {
|
||||
CellAddress cellAddress = entry.getKey();
|
||||
if (cellAddress.getRow() < wb.getSpreadsheetVersion().getMaxRows()
|
||||
@ -756,11 +759,11 @@ public final class PropertyTemplate {
|
||||
* @param range - {@link CellRangeAddress} range of cells to remove borders.
|
||||
*/
|
||||
private void removeBorderColors(CellRangeAddress range) {
|
||||
Set<CellPropertyType> properties = new HashSet<>();
|
||||
properties.add(CellPropertyType.TOP_BORDER_COLOR);
|
||||
properties.add(CellPropertyType.BOTTOM_BORDER_COLOR);
|
||||
properties.add(CellPropertyType.LEFT_BORDER_COLOR);
|
||||
properties.add(CellPropertyType.RIGHT_BORDER_COLOR);
|
||||
Set<CellPropertyType> properties = EnumSet.of(
|
||||
CellPropertyType.TOP_BORDER_COLOR,
|
||||
CellPropertyType.BOTTOM_BORDER_COLOR,
|
||||
CellPropertyType.LEFT_BORDER_COLOR,
|
||||
CellPropertyType.RIGHT_BORDER_COLOR);
|
||||
for (int row = range.getFirstRow(); row <= range.getLastRow(); row++) {
|
||||
for (int col = range.getFirstColumn(); col <= range
|
||||
.getLastColumn(); col++) {
|
||||
@ -781,9 +784,9 @@ public final class PropertyTemplate {
|
||||
*/
|
||||
private void addProperty(int row, int col, CellPropertyType property, Object value) {
|
||||
CellAddress cell = new CellAddress(row, col);
|
||||
Map<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
EnumMap<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
if (cellProperties == null) {
|
||||
cellProperties = new HashMap<>();
|
||||
cellProperties = new EnumMap<>(CellPropertyType.class);
|
||||
}
|
||||
cellProperties.put(property, value);
|
||||
_propertyTemplate.put(cell, cellProperties);
|
||||
@ -795,7 +798,7 @@ public final class PropertyTemplate {
|
||||
*/
|
||||
private void removeProperties(int row, int col, Set<CellPropertyType> properties) {
|
||||
CellAddress cell = new CellAddress(row, col);
|
||||
Map<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
EnumMap<CellPropertyType, Object> cellProperties = _propertyTemplate.get(cell);
|
||||
if (cellProperties != null) {
|
||||
cellProperties.keySet().removeAll(properties);
|
||||
if (cellProperties.isEmpty()) {
|
||||
@ -946,6 +949,7 @@ public final class PropertyTemplate {
|
||||
* @deprecated See {@link #getTemplateProperty(int, int, CellPropertyType)}
|
||||
*/
|
||||
@Deprecated
|
||||
@Removal(version = "7.0.0")
|
||||
public short getTemplateProperty(int row, int col, String propertyName) {
|
||||
return getTemplateProperty(new CellAddress(row, col), CellUtil.namePropertyMap.get(propertyName));
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.poi.ss.usermodel.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -339,7 +340,7 @@ public abstract class BaseTestCellUtil {
|
||||
|
||||
// Add multiple border properties to cell should create a single new style
|
||||
int styCnt1 = wb.getNumCellStyles();
|
||||
Map<CellPropertyType, Object> props = new HashMap<>();
|
||||
EnumMap<CellPropertyType, Object> props = new EnumMap<>(CellPropertyType.class);
|
||||
props.put(CellPropertyType.BORDER_TOP, BorderStyle.THIN);
|
||||
props.put(CellPropertyType.BORDER_BOTTOM, BorderStyle.THIN);
|
||||
props.put(CellPropertyType.BORDER_LEFT, BorderStyle.THIN);
|
||||
@ -574,7 +575,7 @@ public abstract class BaseTestCellUtil {
|
||||
protected void setFillForegroundColorBeforeFillBackgroundColorEnumByEnum() throws IOException {
|
||||
try (Workbook wb1 = _testDataProvider.createWorkbook()) {
|
||||
Cell A1 = wb1.createSheet().createRow(0).createCell(0);
|
||||
Map<CellPropertyType, Object> properties = new HashMap<>();
|
||||
EnumMap<CellPropertyType, Object> properties = new EnumMap<>(CellPropertyType.class);
|
||||
properties.put(CellPropertyType.FILL_PATTERN, FillPatternType.BRICKS);
|
||||
properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, IndexedColors.BLUE.index);
|
||||
properties.put(CellPropertyType.FILL_BACKGROUND_COLOR, IndexedColors.RED.index);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user