@@ -17,29 +17,46 @@ type ResultRow struct {
17
17
CandidateSources []string `json:"candidate_sources,omitempty"`
18
18
}
19
19
20
- func CalculateResults (fs Filesystem , source ValueSource ) ([]ResultRow , error ) {
21
- values := source .Values ()
20
+ type positionLookup multimap.MultiMap [string , int ]
21
+
22
+ func duplicatePredicate (a , b int ) bool { return true }
23
+
24
+ type ResultsCalculator struct {
25
+ fs Filesystem
26
+ source ValueSource
27
+ pathsLookup positionLookup
28
+ }
29
+
30
+ func NewResultsCalculator (fs Filesystem , source ValueSource ) * ResultsCalculator {
31
+ return & ResultsCalculator {
32
+ fs : fs ,
33
+ source : source ,
34
+ pathsLookup : multimap.NewMapSet [string ](duplicatePredicate ),
35
+ }
36
+ }
37
+
38
+ func (r * ResultsCalculator ) CalculateResults () ([]ResultRow , error ) {
39
+ values := r .source .Values ()
22
40
23
41
if len (values ) == 0 {
24
- return nil , errors .New (source .Source () + " is empty" )
42
+ return nil , errors .New (r . source .Source () + " is empty" )
25
43
}
26
44
27
- duplicatePredicate := func (a , b int ) bool { return true }
28
- pathsLookup := multimap.NewMapSet [string ](duplicatePredicate )
29
45
for i , path := range values {
30
- pathKey := fs .GetAbsolutePath (path )
31
- pathsLookup .Put (pathKey , i )
46
+ pathKey := r . fs .GetAbsolutePath (path )
47
+ r . pathsLookup .Put (pathKey , i )
32
48
}
33
49
34
- return calculateResultRows (fs , values , pathsLookup ), nil
50
+ return r . calculateResultRows (), nil
35
51
}
36
52
37
- func calculateResultRows (fs Filesystem , paths []string , pathsLookup multimap.MultiMap [string , int ]) []ResultRow {
53
+ func (r * ResultsCalculator ) calculateResultRows () []ResultRow {
54
+ paths := r .source .Values ()
38
55
res := []ResultRow {}
39
56
for index , path := range paths {
40
- pathKey := fs .GetAbsolutePath (path )
41
- dup := getDuplicatesOf (pathsLookup , pathKey , index )
42
- exists , isdir := fs .PathStatus (pathKey )
57
+ pathKey := r . fs .GetAbsolutePath (path )
58
+ dup := getDuplicatesOf (r . pathsLookup , pathKey , index )
59
+ exists , isdir := r . fs .PathStatus (pathKey )
43
60
res = append (res , ResultRow {
44
61
Id : index + 1 ,
45
62
Path : path ,
0 commit comments