Skip to content

Commit

Permalink
Reduce complexity and make go return the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Apr 4, 2022
1 parent b4aa443 commit bd9ee6b
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/main/java/io/github/arrayv/groovyapi/RunSortBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> optsMap, Map.Entry<String, Object>... optsEntries) {
if (optsMap != null) {
for (Map.Entry<String, Object> opt : optsMap.entrySet()) {
public RunSortBuilder with(Map<String, Object> opts) {
if (opts != null) {
for (Map.Entry<String, Object> opt : opts.entrySet()) {
put(opt);
}
}
for (Map.Entry<String, Object> opt : optsEntries) {
put(opt);
}
return this;
}

Expand All @@ -129,18 +124,19 @@ public final RunSortBuilder with(Map<String, Object> optsMap, Map.Entry<String,
*/
@SafeVarargs
public final RunSortBuilder with(Map.Entry<String, Object>... opts) {
return with(null, opts);
for (Map.Entry<String, Object> 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<String, Object> optsMap, Map.Entry<String, Object>... optsEntries) {
with(optsMap, optsEntries).finish();
public RunSortBuilder go(Map<String, Object> opts) {
return with(opts).finish();
}

/**
Expand All @@ -149,8 +145,8 @@ public final void go(Map<String, Object> optsMap, Map.Entry<String, Object>... o
* @see RunSortInfoExtension
*/
@SafeVarargs
public final void go(Map.Entry<String, Object>... opts) {
go(null, opts);
public final RunSortBuilder go(Map.Entry<String, Object>... opts) {
return with(opts).finish();
}

private void put(Map.Entry<String, Object> opt) {
Expand Down Expand Up @@ -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();
Expand All @@ -240,6 +236,7 @@ private void finish() {
} else {
run0();
}
return this;
}

private void run0() {
Expand Down

0 comments on commit bd9ee6b

Please sign in to comment.