From 46b5ec48899ef15081da57f25b16aea57b087eaa Mon Sep 17 00:00:00 2001 From: thevpc Date: Wed, 15 May 2024 00:52:30 +0100 Subject: [PATCH] 20240515 --- .../extension/CoreServiceUtils.java | 3 +- .../nuts/boot/NWorkspaceCmdLineParser.java | 1 + .../java/net/thevpc/nuts/util/NCreated.java | 22 ++++++++++--- .../net/thevpc/nuts/util/NCreatedDto.java | 31 +++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 core/nuts/src/main/java/net/thevpc/nuts/util/NCreatedDto.java diff --git a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/extension/CoreServiceUtils.java b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/extension/CoreServiceUtils.java index b85a20e77..de9ef4304 100644 --- a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/extension/CoreServiceUtils.java +++ b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/extension/CoreServiceUtils.java @@ -31,10 +31,9 @@ import net.thevpc.nuts.runtime.standalone.io.util.ZipUtils; import net.thevpc.nuts.runtime.standalone.repository.impl.maven.pom.URLPart; import net.thevpc.nuts.runtime.standalone.repository.impl.maven.pom.URLParts; -import net.thevpc.nuts.runtime.standalone.util.collections.CoreCollectionUtils; import net.thevpc.nuts.util.NCollections; import net.thevpc.nuts.util.NMsg; -import sun.misc.URLClassPath; + import java.io.*; import java.net.URL; diff --git a/core/nuts/src/main/java/net/thevpc/nuts/boot/NWorkspaceCmdLineParser.java b/core/nuts/src/main/java/net/thevpc/nuts/boot/NWorkspaceCmdLineParser.java index 7129714ec..020a3b6e5 100644 --- a/core/nuts/src/main/java/net/thevpc/nuts/boot/NWorkspaceCmdLineParser.java +++ b/core/nuts/src/main/java/net/thevpc/nuts/boot/NWorkspaceCmdLineParser.java @@ -1425,6 +1425,7 @@ public static NOptional> nextNutsArgument(NCmdLine cmdLine, NWorkspac List showError = options.getErrors().orNull(); if (showError == null) { showError = new ArrayList<>(); + options.setErrors(showError); } showError.add(NMsg.ofC("nuts: invalid option %s", a.asString().orNull())); } diff --git a/core/nuts/src/main/java/net/thevpc/nuts/util/NCreated.java b/core/nuts/src/main/java/net/thevpc/nuts/util/NCreated.java index 0e11db050..92020f12e 100644 --- a/core/nuts/src/main/java/net/thevpc/nuts/util/NCreated.java +++ b/core/nuts/src/main/java/net/thevpc/nuts/util/NCreated.java @@ -1,5 +1,7 @@ package net.thevpc.nuts.util; +import java.util.function.Function; + public class NCreated { private final T value; private final boolean newValue; @@ -10,18 +12,30 @@ public NCreated(T value, boolean newValue) { } public static NCreated ofNew(T item) { - return new NCreated<>(item,true); + return new NCreated<>(item, true); } public static NCreated ofExisting(T item) { - return new NCreated<>(item,false); + return new NCreated<>(item, false); } - public T getValue() { + public T get() { return value; } - public boolean isNewValue() { + public boolean isNew() { return newValue; } + + public boolean isExisting() { + return !newValue; + } + + public NCreated map(Function mapper) { + return new NCreated<>(mapper.apply(value), newValue); + } + + public NCreatedDto toDto() { + return new NCreatedDto<>(value, newValue); + } } diff --git a/core/nuts/src/main/java/net/thevpc/nuts/util/NCreatedDto.java b/core/nuts/src/main/java/net/thevpc/nuts/util/NCreatedDto.java new file mode 100644 index 000000000..89d297ec8 --- /dev/null +++ b/core/nuts/src/main/java/net/thevpc/nuts/util/NCreatedDto.java @@ -0,0 +1,31 @@ +package net.thevpc.nuts.util; + +import net.thevpc.nuts.NDTO; + +import java.util.function.Function; + +/** + * serializable friendly NCreated + * @param + */ +public class NCreatedDto implements NDTO { + private final T value; + private final boolean newValue; + + public NCreatedDto(T value, boolean newValue) { + this.value = value; + this.newValue = newValue; + } + + public T getValue() { + return value; + } + + public boolean isNewValue() { + return newValue; + } + + public NCreatedDto map(Function mapper) { + return new NCreatedDto<>(mapper.apply(value), newValue); + } +}