1 package jp.satomichan.nucalgen;
3 import java.util.HashMap;
6 import org.apache.poi.ss.usermodel.CellStyle;
7 import org.apache.poi.ss.usermodel.Workbook;
8 import org.apache.poi.xssf.usermodel.XSSFDataFormat;
10 public class CellStylePool {
12 private Workbook workbook;
14 CellStylePool(Workbook workbook){
15 this.workbook = workbook;
19 private Map<CompKey, CellStyle> cellStyleMap = new HashMap<CompKey, CellStyle>();
22 CellStyle getCellStyle(String format) {
23 return this.getCellStyle(format, true);
27 CellStyle getCellStyle(String format, Boolean locked) {
28 CompKey key = new CompKey(format, locked);
29 if(this.cellStyleMap.containsKey(key)) {
30 return this.cellStyleMap.get(key);
32 CellStyle cs = this.workbook.createCellStyle();
33 XSSFDataFormat xssfFormat = (XSSFDataFormat) this.workbook.createDataFormat();
34 cs.setDataFormat(xssfFormat.getFormat(format));
36 this.cellStyleMap.put(key, cs);
38 return this.cellStyleMap.get(key);
44 private String format;
45 private Boolean locked;
47 CompKey(String format, Boolean locked){
48 this.setFormat(format);
49 this.setLocked(locked);
52 public String getFormat() {
55 public void setFormat(String format) {
58 public Boolean getLocked() {
61 public void setLocked(Boolean locked) {
65 public int hashCode() {
68 result = prime * result + getEnclosingInstance().hashCode();
69 result = prime * result + ((format == null) ? 0 : format.hashCode());
70 result = prime * result + ((locked == null) ? 0 : locked.hashCode());
74 public boolean equals(Object obj) {
79 if (getClass() != obj.getClass())
81 CompKey other = (CompKey) obj;
82 if (!getEnclosingInstance().equals(other.getEnclosingInstance()))
85 if (other.format != null)
87 } else if (!format.equals(other.format))
90 if (other.locked != null)
92 } else if (!locked.equals(other.locked))
96 private CellStylePool getEnclosingInstance() {
97 return CellStylePool.this;