Debian Codegraph @

external/rx/Rx/NET/Source/Microsoft.Reactive.Testing/Recorded.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System;
4 using System.Collections.Generic;
5 using System.Diagnostics;
6 using System.Globalization;
7
8 namespace Microsoft.Reactive.Testing
9 {
10 /// <summary>
11 /// Record of a value including the virtual time it was produced on.
12 /// </summary>
13 /// <typeparam name="T">Type of the value.</typeparam>
14 #if !NO_DEBUGGER_ATTRIBUTES
15 [DebuggerDisplay("{Value}@{Time}")]
16 #endif
17 #if !NO_SERIALIZABLE
18 [Serializable]
19 #endif
20 public struct Recorded<T> : IEquatable<Recorded<T>>
21 {
22 private readonly long _time;
23 private readonly T _value;
24
25 /// <summary>
26 /// Gets the virtual time the value was produced on.
27 /// </summary>
28 public long Time { get { return _time; } }
29
30 /// <summary>
31 /// Gets the recorded value.
32 /// </summary>
33 public T Value { get { return _value; } }
34
35 /// <summary>
36 /// Creates a new object recording the production of the specified value at the given virtual time.
37 /// </summary>
38 /// <param name="time">Virtual time the value was produced on.</param>
39 /// <param name="value">Value that was produced.</param>
40 public Recorded(long time, T value)
41 {
42 _time = time;
43 _value = value;
44 }
45
46 /// <summary>
47 /// Checks whether the given recorded object is equal to the current instance.
48 /// </summary>
49 /// <param name="other">Recorded object to check for equality.</param>
50 /// <returns>true if both objects are equal; false otherwise.</returns>
51 public bool Equals(Recorded<T> other)
52 {
53 return Time == other.Time && EqualityComparer<T>.Default.Equals(Value, other.Value);
54 }
55
56 /// <summary>
57 /// Determines whether the two specified Recorded&lt;T&gt; values have the same Time and Value.
58 /// </summary>
59 /// <param name="left">The first Recorded&lt;T&gt; value to compare.</param>
60 /// <param name="right">The second Recorded&lt;T&gt; value to compare.</param>
61 /// <returns>true if the first Recorded&lt;T&gt; value has the same Time and Value as the second Recorded&lt;T&gt; value; otherwise, false.</returns>
62 public static bool operator ==(Recorded<T> left, Recorded<T> right)
63 {
64 return left.Equals(right);
65 }
66
67 /// <summary>
68 /// Determines whether the two specified Recorded&lt;T&gt; values don't have the same Time and Value.
69 /// </summary>
70 /// <param name="left">The first Recorded&lt;T&gt; value to compare.</param>
71 /// <param name="right">The second Recorded&lt;T&gt; value to compare.</param>
72 /// <returns>true if the first Recorded&lt;T&gt; value has a different Time or Value as the second Recorded&lt;T&gt; value; otherwise, false.</returns>
73 public static bool operator !=(Recorded<T> left, Recorded<T> right)
74 {
75 return !left.Equals(right);
76 }
77
78 /// <summary>
79 /// Determines whether the specified System.Object is equal to the current Recorded&lt;T&gt; value.
80 /// </summary>
81 /// <param name="obj">The System.Object to compare with the current Recorded&lt;T&gt; value.</param>
82 /// <returns>true if the specified System.Object is equal to the current Recorded&lt;T&gt; value; otherwise, false.</returns>
83 public override bool Equals(object obj)
84 {
85 if (obj is Recorded<T>)
86 return Equals((Recorded<T>)obj);
87 return false;
88 }
89
90 /// <summary>
91 /// Returns the hash code for the current Recorded&lt;T&gt; value.
92 /// </summary>
93 /// <returns>A hash code for the current Recorded&lt;T&gt; value.</returns>
94 public override int GetHashCode()
95 {
96 return Time.GetHashCode() + EqualityComparer<T>.Default.GetHashCode(Value);
97 }
98
99 /// <summary>
100 /// Returns a string representation of the current Recorded&lt;T&gt; value.
101 /// </summary>
102 /// <returns>String representation of the current Recorded&lt;T&gt; value.</returns>
103 public override string ToString()
104 {
105 return Value.ToString() + "@" + Time.ToString(CultureInfo.CurrentCulture);
106 }
107 }
108 }