main
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Gorilla.Commons.Utility;
5
6namespace presentation.windows.server.domain.payroll
7{
8 public class History<T>
9 {
10 Stack<Event<T>> events = new Stack<Event<T>>();
11
12 public void record(T change)
13 {
14 events.Push(new Event<T>(change));
15 }
16
17 public T recorded(Date date)
18 {
19 return events.Where(x => x.occurred_on_or_before(date)).Max();
20 }
21
22 class Event<K> : IComparable<Event<K>>
23 {
24 public Event(K adjustment)
25 {
26 date_of_change = Calendar.now();
27 this.adjustment = adjustment;
28 }
29
30 K adjustment;
31 Date date_of_change;
32
33 public int CompareTo(Event<K> other)
34 {
35 return date_of_change.CompareTo(other.date_of_change);
36 }
37
38 public bool occurred_on_or_before(Date date)
39 {
40 return date_of_change.Equals(date) || date_of_change.is_before(date);
41 }
42
43 static public implicit operator K(Event<K> eventA)
44 {
45 return eventA.adjustment;
46 }
47 }
48 }
49}