diff options
Diffstat (limited to 'product/client/server/domain/payroll/History.cs')
| -rw-r--r-- | product/client/server/domain/payroll/History.cs | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/product/client/server/domain/payroll/History.cs b/product/client/server/domain/payroll/History.cs index 3ad2c3a..7aaaf66 100644 --- a/product/client/server/domain/payroll/History.cs +++ b/product/client/server/domain/payroll/History.cs @@ -1,26 +1,49 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
using Gorilla.Commons.Utility;
namespace presentation.windows.server.domain.payroll
{
- public class History
+ public class History<T>
{
- Date dateOfChange;
- UnitPrice adjustedPrice;
+ Stack<Event<T>> events = new Stack<Event<T>>();
- History() {}
+ public void record(T change)
+ {
+ events.Push(new Event<T>(change));
+ }
- static public History New(UnitPrice newPrice)
+ public T recorded(Date date)
{
- return new History
- {
- dateOfChange = Calendar.now(),
- adjustedPrice = newPrice,
- };
+ return events.Where(x => x.occurred_on_or_before(date)).Max();
}
- public UnitPrice Adjustment()
+ class Event<K> : IComparable<Event<K>>
{
- return adjustedPrice;
+ public Event(K adjustment)
+ {
+ date_of_change = Calendar.now();
+ this.adjustment = adjustment;
+ }
+
+ K adjustment;
+ Date date_of_change;
+
+ public int CompareTo(Event<K> other)
+ {
+ return date_of_change.CompareTo(other.date_of_change);
+ }
+
+ public bool occurred_on_or_before(Date date)
+ {
+ return date_of_change.Equals(date) || date_of_change.is_before(date);
+ }
+
+ static public implicit operator K(Event<K> eventA)
+ {
+ return eventA.adjustment;
+ }
}
}
}
\ No newline at end of file |
