Skip to content

Commit 8b8725b

Browse files
Merge pull request #933 from ie3-institute/ms/#828-throw-exception-instead-of-questionable-EntitySource.safeMapGet
JavaDoc cautionary hint for `safeMapGet`.
2 parents ce9c6ce + b4ed298 commit 8b8725b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515
- Changing from comparing strings to comparing uuids in `EntitySource.findFirstEntityByUuid` [#829](https://github.com/ie3-institute/PowerSystemDataModel/issues/829)
16-
16+
- Adding JavaDoc to `EntitySource.safeMapGet` [#828](https://github.com/ie3-institute/PowerSystemDataModel/issues/828)
1717

1818
## [4.1.0] - 2023-11-02
1919

src/main/java/edu/ie3/datamodel/io/source/EntitySource.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ protected String buildSkippingMessage(
5151
+ missingElementsString;
5252
}
5353

54+
/**
55+
* Method for retrieving an element from a map. If the map doesn't contain the key an error
56+
* message is build and returned instead.
57+
*
58+
* <p>Should not be used for other purposes than creating error messages.
59+
*
60+
* @param map with value
61+
* @param key for the value
62+
* @param mapName name of the map used for the error message
63+
* @return either the value or an error message
64+
*/
5465
protected String safeMapGet(Map<String, String> map, String key, String mapName) {
5566
return Optional.ofNullable(map.get(key))
5667
.orElse(
@@ -83,7 +94,7 @@ protected <T extends UniqueEntity> Optional<T> findFirstEntityByUuid(
8394
* the provided fields to values mapping. The provided fields to values mapping needs to have one
8495
* and only one field with key {@link #TYPE} and a corresponding UUID value. If the type can be
8596
* found in the provided collection based on the UUID it is returned wrapped in a {@link Success}.
86-
* Otherwise a {@link Failure} is returned and a warning is logged.
97+
* Otherwise, a {@link Failure} is returned and a warning is logged.
8798
*
8899
* @param types a collection of types that should be used for searching
89100
* @param fieldsToAttributes the field name to value mapping incl. the key {@link #TYPE}

0 commit comments

Comments
 (0)