-
Notifications
You must be signed in to change notification settings - Fork 25
/
history.go
52 lines (45 loc) · 1.39 KB
/
history.go
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
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package params
// The params.History interface records history of parameters applied
// to a given object.
type History interface {
// ParamsHistoryReset resets parameter application history
ParamsHistoryReset()
// ParamsApplied is called when a parameter is successfully applied for given selector
ParamsApplied(sel *Sel)
}
// HistoryImpl implements the History interface. Implementing object can
// just pass calls to a HistoryImpl field.
type HistoryImpl []*Sel
// ParamsHistoryReset resets parameter application history
func (hi *HistoryImpl) ParamsHistoryReset() {
*hi = nil
}
// ParamsApplied is called when a parameter is successfully applied for given selector
func (hi *HistoryImpl) ParamsApplied(sel *Sel) {
*hi = append(*hi, sel)
}
// ParamsHistory returns the sequence of params applied for each parameter
// from all Sel's applied, in reverse order
func (hi *HistoryImpl) ParamsHistory() Params {
pr := make(Params)
lastSet := ""
for _, sl := range *hi {
for pt, v := range sl.Params {
nmv := sl.Sel + ": " + v
if sl.SetName != lastSet {
nmv = sl.SetName + ":" + nmv
lastSet = sl.SetName
}
ev, has := pr[pt]
if has {
pr[pt] = nmv + " | " + ev
} else {
pr[pt] = nmv
}
}
}
return pr
}