Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AttendanceClock : Dictionary<Day, List<WorkSession>>
- enum Day
- {
- Sunday = 1,
- Monday,
- Tuesday,
- Wednesday,
- Thursday,
- Friday
- }
- public class WorkSession : IEquatable<WorkSession>
- {
- public Time Entrance { get; private set; }
- public Time Exit { get; private set; }
- public WorkSession(Time entrance, Time exit)
- {
- Entrance = entrance;
- Exit = exit;
- }
- public override bool Equals(object obj)
- {
- return Equals(obj as WorkSession);
- }
- public bool Equals(WorkSession other)
- {
- return other != null
- && Entrance == other.Entrance
- && Exit == other.Exit;
- }
- public override int GetHashCode()
- {
- var hashCode = 1257807568;
- hashCode = hashCode * -1521134295 + EqualityComparer<Time>.Default.GetHashCode(Entrance);
- hashCode = hashCode * -1521134295 + EqualityComparer<Time>.Default.GetHashCode(Exit);
- return hashCode;
- }
- }
- class AttendanceClock : Dictionary<Day, List<WorkSession>>, IEquatable<AttendanceClock>
- {
- public bool Equals(AttendanceClock other)
- {
- foreach(KeyValuePair<Day, List<WorkSession>> keyValuePair in this)
- {
- Day day = keyValuePair.Key;
- List<WorkSession> workSessions = keyValuePair.Value;
- if(other.TryGetValue(day, out var otherWorkSessions))
- {
- // ScrambledEquals is a helper method that compares
- // two IEnumerables by value regardless of the items
- // order, so {1, 2} is equal to {2, 1}
- if(!Helpers.ScrambledEquals(workSessions, otherWorkSessions))
- {
- return false;
- }
- }
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment