instanceof 관련 수정

master
mjkhan21 7 months ago
parent c41590f080
commit a6f2689cc1

@ -64,8 +64,7 @@ public class Format implements Convert.Support {
return convert.apply(obj); return convert.apply(obj);
} }
if (key != null && obj instanceof Map) { if (key != null && obj instanceof Map<?, ?> map) {
Map<?, ?> map = (Map<?, ?>)obj;
return map.get(key); return map.get(key);
} }
@ -93,8 +92,7 @@ public class Format implements Convert.Support {
return false; return false;
if (obj instanceof Style) if (obj instanceof Style)
return false; return false;
if (obj instanceof Format) { if (obj instanceof Format format) {
Format format = (Format)obj;
return format.hasValue(); return format.hasValue();
} }
return true; return true;
@ -112,8 +110,7 @@ public class Format implements Convert.Support {
return null; return null;
if (obj instanceof Style) if (obj instanceof Style)
return null; return null;
if (obj instanceof Format) { if (obj instanceof Format format) {
Format format = (Format)obj;
if (format.key != null) if (format.key != null)
return format.key; return format.key;
return null; return null;
@ -133,10 +130,10 @@ public class Format implements Convert.Support {
* @return Format * @return Format
*/ */
public Format style(Object obj) { public Format style(Object obj) {
if (obj instanceof Style) { if (obj instanceof Style style) {
cellStyle = cellStyle((Style)obj); cellStyle = cellStyle(style);
} else if (obj instanceof CellStyle) { } else if (obj instanceof CellStyle style) {
cellStyle = (CellStyle)obj; cellStyle = style;
} else } else
throw new IllegalArgumentException("Unable to get a CellStyle from " + obj); throw new IllegalArgumentException("Unable to get a CellStyle from " + obj);

@ -86,8 +86,7 @@ public class XLSWriter extends XLS {
if (!isEmpty(t)) { if (!isEmpty(t)) {
int c = cell.getColumnIndex(); int c = cell.getColumnIndex();
if (isEmpty(objs)) { if (isEmpty(objs)) {
if (t instanceof Map) { if (t instanceof Map<?, ?> map) {
Map<?, ?> map = (Map<?, ?>)t;
objs = map.keySet().stream().map(v -> (Object)v).toList(); objs = map.keySet().stream().map(v -> (Object)v).toList();
} else if (t instanceof Iterable) { } else if (t instanceof Iterable) {
objs = (Iterable<Object>)t; objs = (Iterable<Object>)t;
@ -103,15 +102,15 @@ public class XLSWriter extends XLS {
Object val = null; Object val = null;
Format format = null; Format format = null;
if (obj instanceof Format) if (obj instanceof Format fmt)
format = (Format)obj; format = fmt;
if (format != null) if (format != null)
val = format.value(t); val = format.value(t);
else { else {
Object key = Format.getKey(obj); Object key = Format.getKey(obj);
if (key != null && t instanceof Map) if (key != null && t instanceof Map<?, ?> map)
val = ((Map<?, ?>)t).get(key); val = map.get(key);
else else
val = obj; val = obj;
} }
@ -253,18 +252,16 @@ public class XLSWriter extends XLS {
} }
boolean setCellValue(Object val) { boolean setCellValue(Object val) {
if (val instanceof String) { if (val instanceof String str) {
cell.setCellValue((String)val); cell.setCellValue(str);
return true; return true;
} else if (val instanceof Number) { } else if (val instanceof Number number) {
Number number = (Number)val;
cell.setCellValue(number.doubleValue()); cell.setCellValue(number.doubleValue());
return true; return true;
} else if (val instanceof Date) { } else if (val instanceof Date date) {
cell.setCellValue((Date)val); cell.setCellValue(date);
return true; return true;
} else if (val instanceof Boolean) { } else if (val instanceof Boolean b) {
Boolean b = (Boolean)val;
cell.setCellValue(b.booleanValue()); cell.setCellValue(b.booleanValue());
return true; return true;
} }
@ -284,12 +281,12 @@ public class XLSWriter extends XLS {
void setCellStyle(Object obj) { void setCellStyle(Object obj) {
CellStyle cellStyle = null; CellStyle cellStyle = null;
if (obj instanceof Format) if (obj instanceof Format format)
cellStyle = ((Format)obj).style(); cellStyle = format.style();
else if (obj instanceof Style) else if (obj instanceof Style style)
cellStyle = cellStyle((Style)obj); cellStyle = cellStyle(style);
else if (obj instanceof CellStyle) else if (obj instanceof CellStyle style)
cellStyle = (CellStyle)obj; cellStyle = style;
if (cellStyle != null) if (cellStyle != null)
cell.setCellStyle(cellStyle); cell.setCellStyle(cellStyle);

Loading…
Cancel
Save