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