You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
3.6 KiB
165 lines
3.6 KiB
package data;
|
|
|
|
import static data.Filter.filterName.*;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Map;
|
|
import java.util.regex.Pattern;
|
|
|
|
import gui.ValidationUtil;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public class Filter {
|
|
private HashMap<filterName, Object> filter;
|
|
|
|
public enum filterName {
|
|
ANALYSIS_LEVEL,
|
|
CALCULATE_FOR,
|
|
NGRAM_VALUE,
|
|
SKIP_VALUE,
|
|
IS_CVV,
|
|
STRING_LENGTH,
|
|
TAXONOMY,
|
|
MSD,
|
|
HAS_MSD,
|
|
SOLAR_FILTERS,
|
|
MULTIPLE_KEYS
|
|
}
|
|
|
|
public Filter() {
|
|
filter = new HashMap<>();
|
|
}
|
|
|
|
public Filter(AnalysisLevel al, CalculateFor cf) {
|
|
filter = new HashMap<>();
|
|
|
|
filter.put(ANALYSIS_LEVEL, al);
|
|
filter.put(CALCULATE_FOR, cf);
|
|
}
|
|
|
|
public void setAl(AnalysisLevel al) {
|
|
filter.put(ANALYSIS_LEVEL, al);
|
|
}
|
|
|
|
public AnalysisLevel getAl() {
|
|
return (AnalysisLevel) filter.get(ANALYSIS_LEVEL);
|
|
}
|
|
|
|
public void setCalculateFor(CalculateFor cf) {
|
|
filter.put(CALCULATE_FOR, cf);
|
|
}
|
|
|
|
public CalculateFor getCalculateFor() {
|
|
return (CalculateFor) filter.get(CALCULATE_FOR);
|
|
}
|
|
|
|
public void setNgramValue(Integer ngramValue) {
|
|
filter.put(NGRAM_VALUE, ngramValue);
|
|
}
|
|
|
|
public Integer getNgramValue() {
|
|
return (Integer) filter.get(NGRAM_VALUE);
|
|
}
|
|
|
|
public void setSkipValue(Integer skipValue) {
|
|
filter.put(SKIP_VALUE, skipValue);
|
|
}
|
|
|
|
public Integer getSkipValue() {
|
|
return (Integer) filter.get(SKIP_VALUE);
|
|
}
|
|
|
|
public void setIsCvv(boolean isCvv) {
|
|
filter.put(IS_CVV, isCvv);
|
|
}
|
|
|
|
public boolean isCvv() {
|
|
return filter.containsKey(IS_CVV) && (boolean) filter.get(IS_CVV);
|
|
}
|
|
|
|
public void setStringLength(int stringLength) {
|
|
filter.put(STRING_LENGTH, stringLength);
|
|
}
|
|
|
|
public Integer getStringLength() {
|
|
return (Integer) filter.get(STRING_LENGTH);
|
|
}
|
|
|
|
public void setTaxonomy(ArrayList<String> taxonomy) {
|
|
filter.put(TAXONOMY, taxonomy);
|
|
}
|
|
|
|
public ArrayList<String> getTaxonomy() {
|
|
if (filter.containsKey(TAXONOMY) && filter.get(TAXONOMY) != null) {
|
|
return (ArrayList<String>) filter.get(TAXONOMY);
|
|
} else {
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
|
|
public void setMsd(ArrayList<Pattern> msd) {
|
|
filter.put(MSD, msd);
|
|
if (!ValidationUtil.isEmpty(msd)) {
|
|
setHasMsd(true);
|
|
} else {
|
|
setHasMsd(false);
|
|
}
|
|
}
|
|
|
|
public ArrayList<Pattern> getMsd() {
|
|
return (ArrayList<Pattern>) filter.get(MSD);
|
|
}
|
|
|
|
public void setHasMsd(boolean hasMsd) {
|
|
filter.put(HAS_MSD, hasMsd);
|
|
}
|
|
|
|
public boolean hasMsd() {
|
|
return filter.containsKey(HAS_MSD) && (boolean) filter.get(HAS_MSD);
|
|
}
|
|
|
|
public String toString() {
|
|
String newLine = "\n\t- ";
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(newLine).append("Filter:");
|
|
for (Map.Entry<filterName, Object> entry : filter.entrySet()) {
|
|
sb.append(newLine)
|
|
.append(entry.getKey().toString())
|
|
.append(": ")
|
|
.append(entry.getValue() != null ? entry.getValue().toString() : "null");
|
|
}
|
|
|
|
return sb.toString();
|
|
}
|
|
|
|
public void setSolarFilters(HashMap<String, HashSet<String>> filters) {
|
|
filter.put(SOLAR_FILTERS, filters);
|
|
}
|
|
|
|
public HashMap<String, HashSet<String>> getSolarFilters() {
|
|
return (HashMap<String, HashSet<String>>) filter.get(SOLAR_FILTERS);
|
|
}
|
|
|
|
public void setMultipleKeys(ArrayList<String> keys) {
|
|
ArrayList<CalculateFor> newKeys = new ArrayList<>();
|
|
if (keys != null) {
|
|
for (String key : keys) {
|
|
newKeys.add(CalculateFor.factory(key));
|
|
}
|
|
}
|
|
|
|
filter.put(MULTIPLE_KEYS, newKeys);
|
|
}
|
|
|
|
public ArrayList<CalculateFor> getMultipleKeys() {
|
|
if (filter.containsKey(MULTIPLE_KEYS) && filter.get(MULTIPLE_KEYS) != null) {
|
|
return (ArrayList<CalculateFor>) filter.get(MULTIPLE_KEYS);
|
|
} else {
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
}
|