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

Add ExclusionPolicy API for field/type exclusion #349

Closed
fmbenhassine opened this issue Mar 14, 2019 · 1 comment
Closed

Add ExclusionPolicy API for field/type exclusion #349

fmbenhassine opened this issue Mar 14, 2019 · 1 comment
Labels
Milestone

Comments

@fmbenhassine
Copy link
Member

As of v3.9, field/type exclusion was possible through EnhancedRandomBuilder.exclude methods:

  • public EnhancedRandomBuilder excludeField(Predicate<Field> predicate)
  • public EnhancedRandomBuilder excludeType(Predicate<Class<?>> predicate)

Those methods take a predicate which can be something like:

FieldPredicates.named("name").and(ofType(String.class)).and(inClass(Human.class)

This field definition is static and independent from any randomization context.

The idea of this new feature is to introduce a strategy interface that allows for field/type exclusion dynamically depending on the randomization context. This new API could be something like:

/**
 * Strategy interface for field/type exclusion.
 */
public interface ExclusionPolicy {

    /**
     * Given the current randomization context, should the field be excluded?
     *
     * @param field the field to check
     * @param context the current randomization context
     * @return true if the field should be excluded, false otherwise
     */
    boolean shouldBeExcluded(final Field field, final RandomizerContext context);

    /**
     * Given the current randomization context, should the type be excluded?
     *
     * @param type the type to check
     * @param context the current randomization context
     * @return true if the type should be excluded, false otherwise
     */
    boolean shouldBeExcluded(final Class<?> type, final RandomizerContext context);

}
@fmbenhassine fmbenhassine added this to the 4.0.0.RC1 milestone Mar 14, 2019
@fmbenhassine
Copy link
Member Author

Implemented in 8ae7150 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant