vt-middleware / passay

Password policy enforcement for Java.
http://www.passay.org
Other
282 stars 64 forks source link

Change constructor of a PasswordValidator acording PECS princips. #55

Closed foal closed 7 years ago

foal commented 7 years ago

From

public PasswordValidator(final List<Rule> rules)

to

public PasswordValidator(final List<? super Rule> rules)

see for more information http://stackoverflow.com/questions/2723397/what-is-pecs-producer-extends-consumer-super

dfish3r commented 7 years ago

My reading of that thread lends me to believe that we're got a producer. And the pattern should be List<? extends Rule>.

Is there a specific compile time problem you're trying to solve?

foal commented 7 years ago

Easy :)

private static final List<CharacterRule> RULES = ImmutableList.of(ucimpRule);
//...
validator = new PasswordValidator(StreamEx.of(RULES).map(r -> (Rule) r).toList());
foal commented 7 years ago

And looks like you are right. It is a producer. So List<? extends Rule>.