-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rulelist.java
executable file
·103 lines (80 loc) · 3.22 KB
/
Rulelist.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
public class Rulelist {
// private ArrayList<ArrayList<File>> duplicatelist;
// RULE STRATEGY
private HashMap<String,Stringcompare> compMap;
private HashMap<String,Filepart> partMap;
private HashMap<String,Rule> groupRuleMap;
private HashMap<String,Filter> filterMap;
public Rulelist () {
// still would like to automate this even more
compMap = new HashMap<String,Stringcompare>();
compMap.put("Equals", new StringEquals());
compMap.put("Matches", new StringMatches());
compMap.put("Contains", new StringContains());
compMap.put("StartsWith", new StringStartsWith());
partMap = new HashMap<String,Filepart>();
partMap.put("Canonical" , new FilepartCanonical());
partMap.put("Name", new FilepartName());
partMap.put("Parent" , new FilepartParent());
groupRuleMap = new HashMap<String,Rule>();
filterMap = new HashMap<String,Filter>();
for (String partName: partMap.keySet())
{
for (String compName: compMap.keySet())
{
groupRuleMap.put ("Any" + partName + compName, new RuleAny(partMap.get(partName),compMap.get(compName)));
groupRuleMap.put ("One" + partName + compName, new RuleOne(partMap.get(partName),compMap.get(compName)));
groupRuleMap.put ("All" + partName + compName, new RuleAll(partMap.get(partName),compMap.get(compName)));
filterMap.put("Any" + partName + compName, new FilterAny(partMap.get(partName),compMap.get(compName)));
filterMap.put("One" + partName + compName, new FilterOne(partMap.get(partName),compMap.get(compName)));
}
}
}
// maybe return a string instead.
public void printHelp()
{
System.out.println("Group filter commands");
for (String k : groupRuleMap.keySet())
System.out.println("group:"+k+":<argument>");
System.out.println("File filter commands");
for (String k : filterMap.keySet())
System.out.println("filter:"+k+":<argument>");
}
public ArrayList<ArrayList<File>> evalGroup (ArrayList<ArrayList<File>> duplicatelist, String groupCommand, String groupArgument)
{
if (!groupRuleMap.containsKey(groupCommand))
return duplicatelist;
ArrayList<ArrayList<File>> ndl = new ArrayList<ArrayList<File>>();
for (ArrayList<File> al : duplicatelist)
if (groupRuleMap.get(groupCommand).eval(groupArgument,al))
ndl.add(al);
return ndl;
}
public ArrayList<ArrayList<File>> evalIgnore (ArrayList<ArrayList<File>> duplicatelist, String groupCommand, String groupArgument)
{
if (!groupRuleMap.containsKey(groupCommand))
return duplicatelist;
ArrayList<ArrayList<File>> ndl = new ArrayList<ArrayList<File>>();
for (ArrayList<File> al : duplicatelist)
if (!groupRuleMap.get(groupCommand).eval(groupArgument,al))
ndl.add(al);
return ndl;
}
public ArrayList<ArrayList<File>> evalFilter(ArrayList<ArrayList<File>> duplicatelist, String groupCommand, String groupArgument)
{
if (!filterMap.containsKey(groupCommand))
return duplicatelist;
ArrayList<ArrayList<File>> ndl = new ArrayList<ArrayList<File>>();
for (ArrayList<File> al : duplicatelist)
{
ArrayList<File> nl = filterMap.get(groupCommand).eval(groupArgument,al);
if (nl.size() > 0)
ndl.add(nl);
}
// need to check that this doesn't delete all files.
return ndl;
}
}