-
Notifications
You must be signed in to change notification settings - Fork 0
/
HillSlopeRevegetationCommand.go
77 lines (62 loc) · 2.69 KB
/
HillSlopeRevegetationCommand.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
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
// Copyright (c) 2019 Australian Rivers Institute.
package particulatenitrogen
import (
"github.com/LindsayBradford/crem/internal/pkg/model/planningunit"
"github.com/LindsayBradford/crem/internal/pkg/model/variable"
"github.com/LindsayBradford/crem/pkg/command"
)
type HillSlopeRevegetationCommand struct {
variable.ChangePerPlanningUnitDecisionVariableCommand
undoneHillSlopeContribution float64
doneHillSlopeContribution float64
}
func (c *HillSlopeRevegetationCommand) ForVariable(variable variable.PlanningUnitDecisionVariable) *HillSlopeRevegetationCommand {
c.WithTarget(variable)
return c
}
func (c *HillSlopeRevegetationCommand) InPlanningUnit(planningUnit planningunit.Id) *HillSlopeRevegetationCommand {
c.ChangePerPlanningUnitDecisionVariableCommand.InPlanningUnit(planningUnit)
return c
}
func (c *HillSlopeRevegetationCommand) WithFilteredNitrogenContribution(contribution float64) *HillSlopeRevegetationCommand {
c.undoneHillSlopeContribution = c.hillSlopeNitrogenContribution()
c.doneHillSlopeContribution = contribution
return c
}
func (c *HillSlopeRevegetationCommand) WithChange(changeValue float64) *HillSlopeRevegetationCommand {
c.ChangePerPlanningUnitDecisionVariableCommand.WithChange(changeValue)
return c
}
func (c *HillSlopeRevegetationCommand) variable() *ParticulateNitrogenProduction {
return c.Target().(*ParticulateNitrogenProduction)
}
func (c *HillSlopeRevegetationCommand) Do() command.CommandStatus {
if c.BaseCommand.Do() == command.NoChange {
return command.NoChange
}
c.ChangePerPlanningUnitDecisionVariableCommand.DoUnguarded()
c.setHillSlopeNitrogenContribution(c.doneHillSlopeContribution)
return command.Done
}
func (c *HillSlopeRevegetationCommand) Undo() command.CommandStatus {
if c.BaseCommand.Undo() == command.NoChange {
return command.NoChange
}
c.ChangePerPlanningUnitDecisionVariableCommand.UndoUnguarded()
c.setHillSlopeNitrogenContribution(c.undoneHillSlopeContribution)
return command.UnDone
}
func (c *HillSlopeRevegetationCommand) setHillSlopeNitrogenContribution(nitrogenContribution float64) {
c.variable().subCatchmentAttributes[c.PlanningUnit()] =
c.variable().subCatchmentAttributes[c.PlanningUnit()].Replace(HillSlopeNitrogenContribution, nitrogenContribution)
}
func (c *HillSlopeRevegetationCommand) hillSlopeNitrogenContribution() float64 {
planningUnitAttributes := c.variable().subCatchmentAttributes[c.PlanningUnit()]
return planningUnitAttributes.Value(HillSlopeNitrogenContribution).(float64)
}
func (c *HillSlopeRevegetationCommand) DoneHillSlopeContribution() float64 {
return c.doneHillSlopeContribution
}
func (c *HillSlopeRevegetationCommand) UndoneHillSlopeContribution() float64 {
return c.undoneHillSlopeContribution
}