From e89833b23323f2665a6e045218a14936101a3897 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 19 Nov 2024 17:40:51 +0100 Subject: [PATCH] refactor Stringify --- .../HsOfficeCoopAssetsTransactionEntity.java | 9 ++++----- .../net/hostsharing/hsadminng/repr/Stringify.java | 12 +++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java index 0f2a17d8..a0b7da69 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java @@ -50,11 +50,10 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue) .withProp(HsOfficeCoopAssetsTransactionEntity::getReference) .withProp(HsOfficeCoopAssetsTransactionEntity::getComment) - // FIXME: try short form with just method reference - .withProp(at -> ofNullable(at.getRevertedAssetTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) - .withProp(at -> ofNullable(at.getAssetReversalTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) - .withProp(at -> ofNullable(at.getAssetAdoptionAssetTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) - .withProp(at -> ofNullable(at.getAssetTransferTx()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null)) + .withProp(HsOfficeCoopAssetsTransactionEntity::getRevertedAssetTx) + .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetReversalTx) + .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetAdoptionAssetTx) + .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetTransferTx) .quotedValues(false); @Id diff --git a/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java index aaa3ea73..f1e1c709 100644 --- a/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java @@ -80,12 +80,6 @@ public final class Stringify { .map(prop -> PropertyValue.of(prop, prop.getter.apply(object))) .filter(Objects::nonNull) .filter(PropertyValue::nonEmpty) - .map(propVal -> { - if (propVal.rawValue instanceof Stringifyable stringifyable) { - return new PropertyValue<>(propVal.prop, propVal.rawValue, stringifyable.toShortString()); - } - return propVal; - }) .map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal)) .collect(Collectors.joining(separator)); return idProp != null @@ -131,7 +125,11 @@ public final class Stringify { private record PropertyValue(Property prop, Object rawValue, String value) { static PropertyValue of(Property prop, Object rawValue) { - return rawValue != null ? new PropertyValue<>(prop, rawValue, rawValue.toString()) : null; + return rawValue != null ? new PropertyValue<>(prop, rawValue, toStringOrShortString(rawValue)) : null; + } + + private static String toStringOrShortString(final Object rawValue) { + return rawValue instanceof Stringifyable stringifyable ? stringifyable.toShortString() : rawValue.toString(); } boolean nonEmpty() {