From bd9ee6b383c1b2ce665c88974c3fd7f5902d3a26 Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Sun, 3 Apr 2022 19:54:01 -0500 Subject: [PATCH] Reduce complexity and make go return the builder --- .../arrayv/groovyapi/RunSortBuilder.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/arrayv/groovyapi/RunSortBuilder.java b/src/main/java/io/github/arrayv/groovyapi/RunSortBuilder.java index bdacdcfb..bb365d07 100644 --- a/src/main/java/io/github/arrayv/groovyapi/RunSortBuilder.java +++ b/src/main/java/io/github/arrayv/groovyapi/RunSortBuilder.java @@ -103,21 +103,16 @@ public String toString() { /** * Merge the specified options with the options map - * @param optsMap The options to merge, generally using Groovy's keyword argument syntax - * @param optsEntries The options to merge, generally obtained with {@link RunSortInfoExtension} + * @param opts The options to merge, generally using Groovy's named argument syntax * @return {@code this} for chaining * @see RunSortInfoExtension */ - @SafeVarargs - public final RunSortBuilder with(Map optsMap, Map.Entry... optsEntries) { - if (optsMap != null) { - for (Map.Entry opt : optsMap.entrySet()) { + public RunSortBuilder with(Map opts) { + if (opts != null) { + for (Map.Entry opt : opts.entrySet()) { put(opt); } } - for (Map.Entry opt : optsEntries) { - put(opt); - } return this; } @@ -129,18 +124,19 @@ public final RunSortBuilder with(Map optsMap, Map.Entry... opts) { - return with(null, opts); + for (Map.Entry opt : opts) { + put(opt); + } + return this; } /** * Merge the specified options with the options map, and run the sort - * @param optsMap The options to merge, generally using Groovy's keyword argument syntax - * @param optsEntries The options to merge, generally obtained with {@link RunSortInfoExtension} + * @param opts The options to merge, generally using Groovy's named argument syntax * @see RunSortInfoExtension */ - @SafeVarargs - public final void go(Map optsMap, Map.Entry... optsEntries) { - with(optsMap, optsEntries).finish(); + public RunSortBuilder go(Map opts) { + return with(opts).finish(); } /** @@ -149,8 +145,8 @@ public final void go(Map optsMap, Map.Entry... o * @see RunSortInfoExtension */ @SafeVarargs - public final void go(Map.Entry... opts) { - go(null, opts); + public final RunSortBuilder go(Map.Entry... opts) { + return with(opts).finish(); } private void put(Map.Entry opt) { @@ -225,7 +221,7 @@ private void removeClosers() { closed = true; } - private void finish() { + private RunSortBuilder finish() { removeClosers(); if (RunGroupContext.CONTEXT.get() == null) { final ArrayVisualizer arrayVisualizer = ArrayVisualizer.getInstance(); @@ -240,6 +236,7 @@ private void finish() { } else { run0(); } + return this; } private void run0() {