From 085335d39396bcc3d2dd232ea2db2b981a00bcb8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 20 Jan 2020 11:18:21 +0100 Subject: [PATCH] [New] Added orderBy*() methods without need for BAG_PARAMETERS, or reverse flag --- .../search/RootElementSearchResult.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/li.strolch.agent/src/main/java/li/strolch/search/RootElementSearchResult.java b/li.strolch.agent/src/main/java/li/strolch/search/RootElementSearchResult.java index e5fb9b30f..9728d9811 100644 --- a/li.strolch.agent/src/main/java/li/strolch/search/RootElementSearchResult.java +++ b/li.strolch.agent/src/main/java/li/strolch/search/RootElementSearchResult.java @@ -1,9 +1,13 @@ package li.strolch.search; +import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS; + import java.util.Comparator; import java.util.stream.Stream; +import li.strolch.model.ParameterBag; import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchModelConstants; import li.strolch.model.StrolchRootElement; import li.strolch.model.parameter.Parameter; import li.strolch.model.visitor.StrolchRootElementVisitor; @@ -19,6 +23,16 @@ public class RootElementSearchResult extends Searc super(stream); } + /** + * Appends a comparator to the stream of elements to compare by ID + * + * @return this for chaining + */ + public RootElementSearchResult orderById() { + orderById(false); + return this; + } + /** * Appends a comparator to the stream of elements to compare by ID * @@ -60,6 +74,36 @@ public class RootElementSearchResult extends Searc return this; } + /** + * Appends a comparator to the stream of elements to compare by a parameter on the {@link ParameterBag} with the ID + * {@link StrolchModelConstants#BAG_PARAMETERS} + * + * @param paramId + * the ID of the parameter to use for comparing + * + * @return this for chaining + */ + public RootElementSearchResult orderByParam(String paramId) { + orderByParam(BAG_PARAMETERS, paramId, false); + return this; + } + + /** + * Appends a comparator to the stream of elements to compare by a parameter on the {@link ParameterBag} with the ID + * {@link StrolchModelConstants#BAG_PARAMETERS} + * + * @param paramId + * the ID of the parameter to use for comparing + * @param reversed + * flag to reverse the comparison + * + * @return this for chaining + */ + public RootElementSearchResult orderByParam(String paramId, boolean reversed) { + orderByParam(BAG_PARAMETERS, paramId, reversed); + return this; + } + /** * Appends a comparator to the stream of elements to compare by a parameter *