Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Nov 8, 2024
1 parent 7076e25 commit 7e509c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
44 changes: 24 additions & 20 deletions meja-poi/src/main/java/com/dua3/meja/model/poi/PoiCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,15 @@ public boolean isEmpty() {

@Override
public PoiCell set(@Nullable Boolean arg) {
arg = getWorkbook().cache(arg);
Object old = getOrDefault(null);
if (arg == null) {
clear();
} else {
poiCell.setCellValue(arg);
setCellStylePlain();
return this;
}

Object old = getOrDefault(null);
arg = getWorkbook().cache(arg);
poiCell.setCellValue(arg);
setCellStylePlain();
updateRow();
valueChanged(old, arg);
return this;
Expand Down Expand Up @@ -393,52 +394,55 @@ public PoiCell set(@Nullable LocalDateTime arg) {

@Override
public PoiCell set(@Nullable Number arg) {
arg = getWorkbook().cache(arg);
Object old = getOrDefault(null);
if (arg == null) {
clear();
} else {
poiCell.setCellValue(arg.doubleValue());
setCellStylePlain();
return this;
}

arg = getWorkbook().cache(arg);
Object old = getOrDefault(null);
poiCell.setCellValue(arg.doubleValue());
setCellStylePlain();
updateRow();
valueChanged(old, null);
return this;
}

@Override
public Cell set(@Nullable RichText s) {
if (s == null) {
public Cell set(@Nullable RichText arg) {
if (arg == null) {
clear();
return this;
}

s = getWorkbook().cache(s);
arg = getWorkbook().cache(arg);
Object old = getOrDefault(null);

RichTextString richText = getWorkbook().createRichTextString(s.toString());
for (Run run : s) {
RichTextString richText = getWorkbook().createRichTextString(arg.toString());
for (Run run : arg) {
PoiFont font = getWorkbook().getPoiFont(getCellStyle().getFont().deriveFont(run.getFontDef()));
richText.applyFont(run.getStart(), run.getEnd(), font.getPoiFont());
}
poiCell.setCellValue(richText);
setCellStylePlain();

updateRow();

valueChanged(old, s);
valueChanged(old, arg);

return this;
}

@Override
public PoiCell set(@Nullable String arg) {
if (arg == null) {
clear();
return this;
}

arg = getWorkbook().cache(arg);
Object old = getOrDefault(null);
poiCell.setCellValue(arg);
setCellStylePlain();
updateRow();
valueChanged(old, null);
valueChanged(old, arg);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions meja/src/main/java/com/dua3/meja/model/AbstractWorkbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void subscribe(Flow.Subscriber<WorkbookEvent> subscriber) {
}

@Override
public <T extends @Nullable Object> T cache(T obj) {
return objectCache != null && obj != null ? objectCache.get(obj) : obj;
public <T> T cache(T obj) {
return objectCache != null ? objectCache.get(obj) : obj;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions meja/src/main/java/com/dua3/meja/model/Workbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,9 @@ default void write(FileType<?> fileType, OutputStream out, Arguments options) th
*
* @param <T> object type
* @param obj the object to lookup
* @return the cached instance, if an instance equal to {@code obj} is present
* in the cache, {@code obj} otherwise
* @return the cached instance, if caching is enabled, otherwise {@code obj}
*/
<T extends @Nullable Object> T cache(T obj);
<T> T cache(T obj);

/**
* Create a stream of the rows in this sheet.
Expand Down

0 comments on commit 7e509c4

Please sign in to comment.