recheck icon indicating copy to clipboard operation
recheck copied to clipboard

Make `RecheckOptionsBuilder` more generalized and robust

Open diba1013 opened this issue 5 years ago • 0 comments

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 */ );
	}
}

diba1013 avatar Sep 17 '19 07:09 diba1013