-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pipinet
committed
Jan 3, 2024
1 parent
c30b6b5
commit 988a420
Showing
6 changed files
with
53 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.qwlabs.excel; | ||
|
||
import com.google.common.collect.Maps; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.BiPredicate; | ||
|
||
public final class ExcelHelper { | ||
private ExcelHelper() { | ||
} | ||
|
||
public static Map<Integer, String> cleanup(Map<Integer, String> data) { | ||
return cleanup(data, (index, value) -> Objects.nonNull(value)); | ||
} | ||
|
||
public static Map<Integer, String> cleanup(Map<Integer, String> data, | ||
BiPredicate<Integer, String> predicate) { | ||
Map<Integer, String> cleanup = Maps.newHashMap(); | ||
Optional.ofNullable(data).orElseGet(Map::of) | ||
.forEach((index, value) -> { | ||
if (predicate.test(index, value)) { | ||
cleanup.put(index, value); | ||
} | ||
}); | ||
return cleanup; | ||
} | ||
|
||
public static Map<Integer, String> lookupHeaders(@NotNull Map<Integer, String> headerData, | ||
@NotNull Map<String, String> lookups) { | ||
Map<Integer, String> headers = Maps.newHashMapWithExpectedSize(headerData.size()); | ||
cleanup(headerData).forEach((index, title) -> { | ||
var newTitle = lookups.get(title); | ||
if (Objects.nonNull(newTitle)) { | ||
headers.put(index, newTitle); | ||
} | ||
}); | ||
headerData.forEach(headers::putIfAbsent); | ||
return headers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.