Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
Signed-off-by: yongjunhong <[email protected]>
  • Loading branch information
YongGoose committed Dec 6, 2024
1 parent 6e64284 commit 5faa668
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
@SuppressWarnings("unused")
@API(since = "0.4.0", status = Status.MAINTAINED)
public final class FixtureMonkeyBuilder {
private static final int DEFAULT_PRIORITY = Integer.MAX_VALUE;

private final FixtureMonkeyOptionsBuilder fixtureMonkeyOptionsBuilder = FixtureMonkeyOptions.builder();
private final List<PriorityMatcherOperator> registeredArbitraryBuilders = new ArrayList<>();
private ManipulatorOptimizer manipulatorOptimizer = new NoneManipulatorOptimizer();
Expand Down Expand Up @@ -314,7 +316,7 @@ public FixtureMonkeyBuilder register(
Class<?> type,
Function<FixtureMonkey, ? extends ArbitraryBuilder<?>> registeredArbitraryBuilder
) {
return this.register(MatcherOperator.assignableTypeMatchOperator(type, registeredArbitraryBuilder));
return this.register(type, registeredArbitraryBuilder, DEFAULT_PRIORITY);
}

public FixtureMonkeyBuilder register(
Expand Down Expand Up @@ -342,8 +344,7 @@ public FixtureMonkeyBuilder registerAssignableType(
public FixtureMonkeyBuilder register(
MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>> registeredArbitraryBuilder
) {
this.registeredArbitraryBuilders.add(new PriorityMatcherOperator(registeredArbitraryBuilder));
return this;
return this.register(registeredArbitraryBuilder, DEFAULT_PRIORITY);
}

public FixtureMonkeyBuilder register(
Expand Down Expand Up @@ -393,15 +394,7 @@ public FixtureMonkeyBuilder registerGroup(Class<?>... arbitraryBuilderGroups) {

public FixtureMonkeyBuilder registerGroup(ArbitraryBuilderGroup... arbitraryBuilderGroups) {
for (ArbitraryBuilderGroup arbitraryBuilderGroup : arbitraryBuilderGroups) {
List<ArbitraryBuilderCandidate<?>> candidates = arbitraryBuilderGroup.generateCandidateList()
.getCandidates();

for (ArbitraryBuilderCandidate<?> candidate : candidates) {
this.register(
candidate.getClassType(),
candidate.getArbitraryBuilderRegisterer()
);
}
this.registerGroup(arbitraryBuilderGroup, DEFAULT_PRIORITY);
}
return this;
}
Expand All @@ -428,14 +421,7 @@ public FixtureMonkeyBuilder registeredName(
Class<?> type,
Function<FixtureMonkey, ? extends ArbitraryBuilder<?>> arbitraryBuilder
) {
if (registeredArbitraryListByRegisteredName.containsKey(registeredName)) {
throw new IllegalArgumentException("Duplicated ArbitraryBuilder name: " + registeredName);
}
MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>> matcherOperator =
MatcherOperator.assignableTypeMatchOperator(type, arbitraryBuilder);

this.registeredArbitraryListByRegisteredName.put(registeredName, new PriorityMatcherOperator(matcherOperator));
return this;
return this.registeredName(registeredName, type, arbitraryBuilder, DEFAULT_PRIORITY);
}

public FixtureMonkeyBuilder registeredName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public PriorityMatcherOperator(
this.priority = priority;
}

public PriorityMatcherOperator(
final MatcherOperator<Function<FixtureMonkey, ? extends ArbitraryBuilder<?>>> matcherOperator
) {
this.priority = Integer.MAX_VALUE;
this.matcherOperator = matcherOperator;
}

public int getPriority() {
return priority;
}
Expand Down

0 comments on commit 5faa668

Please sign in to comment.