Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RecheckOptionsBuilder more generalized and robust #432

Open
diba1013 opened this issue Sep 17, 2019 · 0 comments
Open

Make RecheckOptionsBuilder more generalized and robust #432

diba1013 opened this issue Sep 17, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@diba1013
Copy link
Contributor

Since, apparently, we extend the RecheckOptionsBuilder by RecheckWebOptionsBuilder we need to make sure, that it can handle such. With the current implementation (as of v1.5.0) the usage of the builder is really restricted, such that one first has to set all specific Recheck*Options and then proceed to the common RecheckOptions.

Example from retest/recheck-web#349:

RecheckWebOptions.builder() //
			.checkNamingStrategy( new CustomCheckNamingStrategy()  ) // returns RecheckWebOptionsBuilder
			.fileNamerStrategy( new CustomNamingStrategy() ) // returns RecheckOptionsBuilder
			.build()

That means that the builder must use generics such that it returns a self and construct the Recheck*Options accordingly.

Generally that means to have something like an abstract builder:

public abstract class AbstractRecheckOptionsBuilder<SELF extends AbstractRecheckOptionsBuilder<SELF, OPTIONS>, OPTIONS extends RecheckOptions> {

	public SELF setOptionX( /* ... */ ) {
		// do stuff
		return self();
	}

	protected abstract SELF self();

	protected abstract OPTIONS construct( RecheckOptions options );

	public OPTIONS build() {
		return construct( new RecheckOptions( /* initialize */ ) );
	}
}

For RecheckOptions:

public final class RecheckOptionsBuilder extends AbstractRecheckOptionsBuilder<RecheckOptionsBuilder, RecheckOptions> {

	@Override
	protected RecheckOptionsBuilder self() {
		return this;
	}

	@Override
	protected RecheckOptions construct( final RecheckOptions options ) {
		return options;
	}
}

For RecheckWebOptions:

public final class RecheckWebOptionsBuilder extends AbstractRecheckOptionsBuilder<RecheckWebOptionsBuilder, RecheckWebOptions> {

	@Override
	protected RecheckWebOptionsBuilder self() {
		return this;
	}

	@Override
	protected RecheckWebOptions construct( final RecheckOptions options ) {
		return new RecheckWebOptions( options, /* initialize */ );
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant