Skip to content

Commit

Permalink
refactor: refactoring matchers.OmnibusMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe committed Aug 19, 2023
1 parent d255ace commit a8024dc
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/main/java/com/nulabinc/zxcvbn/matchers/OmnibusMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@

public class OmnibusMatcher extends BaseMatcher {

private final Map<String, Map<String, Integer>> dictionaryMap;
private final List<Matcher> matchers = new ArrayList<>();

public OmnibusMatcher(Context context, Map<String, Map<String, Integer>> dictionaries) {
super(context);
if (dictionaries == null) {
this.dictionaryMap = new HashMap<>();
} else {
this.dictionaryMap = dictionaries;
dictionaries = new HashMap<>();
}
matchers.add(new DictionaryMatcher(getContext(), dictionaries));
matchers.add(new ReverseDictionaryMatcher(getContext(), dictionaries));
matchers.add(new L33tMatcher(getContext(), dictionaries));
matchers.add(new SpatialMatcher(getContext()));
matchers.add(new RepeatMatcher(getContext()));
matchers.add(new SequenceMatcher(getContext()));
matchers.add(new RegexMatcher(getContext()));
matchers.add(new DateMatcher(getContext()));
}

@Override
public List<Match> execute(CharSequence password) {
List<Matcher> matchers = new ArrayList<>();
matchers.add(new DictionaryMatcher(this.getContext(), dictionaryMap));
matchers.add(new ReverseDictionaryMatcher(this.getContext(), dictionaryMap));
matchers.add(new L33tMatcher(this.getContext(), dictionaryMap));
matchers.add(new SpatialMatcher(this.getContext()));
matchers.add(new RepeatMatcher(this.getContext()));
matchers.add(new SequenceMatcher(this.getContext()));
matchers.add(new RegexMatcher(this.getContext()));
matchers.add(new DateMatcher(this.getContext()));
List<Match> matches = new ArrayList<>();
for (Matcher matcher : matchers) matches.addAll(matcher.execute(password));
return this.sorted(matches);
for (Matcher matcher : matchers) {
matches.addAll(matcher.execute(password));
}
return sorted(matches);
}
}

0 comments on commit a8024dc

Please sign in to comment.