-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor and improve code readability in Scoring
- Loading branch information
Showing
2 changed files
with
193 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.nulabinc.zxcvbn; | ||
|
||
import com.nulabinc.zxcvbn.matchers.Match; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
class Optimal { | ||
|
||
private final List<Map<Integer, Match>> bestMatches = new ArrayList<>(); | ||
|
||
private final List<Map<Integer, Double>> totalGuesses = new ArrayList<>(); | ||
|
||
private final List<Map<Integer, Double>> overallMetrics = new ArrayList<>(); | ||
|
||
Optimal(int length) { | ||
for (int i = 0; i < length; i++) { | ||
bestMatches.add(new HashMap<Integer, Match>()); | ||
totalGuesses.add(new HashMap<Integer, Double>()); | ||
overallMetrics.add(new HashMap<Integer, Double>()); | ||
} | ||
} | ||
|
||
Match putToBestMatches(int index, Integer key, Match value) { | ||
return bestMatches.get(index).put(key, value); | ||
} | ||
|
||
Double putToTotalGuesses(int index, Integer key, Double value) { | ||
return totalGuesses.get(index).put(key, value); | ||
} | ||
|
||
Double putToOverallMetrics(int index, Integer key, Double value) { | ||
return overallMetrics.get(index).put(key, value); | ||
} | ||
|
||
Map<Integer, Match> getBestMatchesAt(int index) { | ||
return bestMatches.get(index); | ||
} | ||
|
||
Map<Integer, Double> getTotalGuessAt(int index) { | ||
return totalGuesses.get(index); | ||
} | ||
|
||
Map<Integer, Double> getOverallMetricsAt(int index) { | ||
return overallMetrics.get(index); | ||
} | ||
|
||
Match getBestMatch(int index, int key) { | ||
return getBestMatchesAt(index).get(key); | ||
} | ||
|
||
Double getTotalGuess(int index, int key) { | ||
return getTotalGuessAt(index).get(key); | ||
} | ||
|
||
Double getOverallMetric(int index, int key) { | ||
return getOverallMetricsAt(index).get(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters