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

refactor: refactoring matchers.ReverseDictionaryMatcher #146

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@

import com.nulabinc.zxcvbn.Context;
import com.nulabinc.zxcvbn.WipeableString;

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

public class ReverseDictionaryMatcher extends BaseMatcher {

private final Map<String, Map<String, Integer>> rankedDictionaries;
private final Map<String, Map<String, Integer>> rankedDictionaries;

public ReverseDictionaryMatcher(Context context, Map<String, Map<String, Integer>> rankedDictionaries) {
super(context);
if (rankedDictionaries == null) {
this.rankedDictionaries = new HashMap<>();
} else {
this.rankedDictionaries = rankedDictionaries;
}
public ReverseDictionaryMatcher(
Context context, Map<String, Map<String, Integer>> rankedDictionaries) {
super(context);
if (rankedDictionaries == null) {
this.rankedDictionaries = new HashMap<>();
} else {
this.rankedDictionaries = rankedDictionaries;
}
}

@Override
public List<Match> execute(CharSequence password) {
CharSequence reversedPassword = WipeableString.reversed(password);
List<Match> matches = new ArrayList<>();
for (Match match: new DictionaryMatcher(this.getContext(), this.rankedDictionaries).execute(reversedPassword)) {
matches.add(MatchFactory.createReversedDictionaryMatch(
password.length() - 1 - match.j,
password.length() - 1 - match.i,
WipeableString.reversed(match.token),
match.matchedWord,
match.rank,
match.dictionaryName));
}
return this.sorted(matches);
@Override
public List<Match> execute(CharSequence password) {
CharSequence reversedPassword = WipeableString.reversed(password);
List<Match> matches = new ArrayList<>();
DictionaryMatcher dictionaryMatcher = new DictionaryMatcher(getContext(), rankedDictionaries);
for (Match match : dictionaryMatcher.execute(reversedPassword)) {
int reversedStartIndex = password.length() - 1 - match.j;
int reversedEndIndex = password.length() - 1 - match.i;
matches.add(
MatchFactory.createReversedDictionaryMatch(
reversedStartIndex,
reversedEndIndex,
WipeableString.reversed(match.token),
match.matchedWord,
match.rank,
match.dictionaryName));
}
return this.sorted(matches);
}
}
Loading