Skip to content

Commit

Permalink
Merge pull request #148 from nulab/refactoring-OmnibusMatcher
Browse files Browse the repository at this point in the history
refactor: refactoring matchers.OmnibusMatcher
  • Loading branch information
vvatanabe authored Aug 19, 2023
2 parents b5d7482 + a8024dc commit a677ae3
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/main/java/com/nulabinc/zxcvbn/matchers/OmnibusMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,36 @@

import com.nulabinc.zxcvbn.Context;
import com.nulabinc.zxcvbn.Matcher;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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;
}
public OmnibusMatcher(Context context, Map<String, Map<String, Integer>> dictionaries) {
super(context);
if (dictionaries == null) {
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);
@Override
public List<Match> execute(CharSequence password) {
List<Match> matches = new ArrayList<>();
for (Matcher matcher : matchers) {
matches.addAll(matcher.execute(password));
}

return sorted(matches);
}
}

0 comments on commit a677ae3

Please sign in to comment.