|
3 | 3 |
|
4 | 4 | namespace UnitsNet
|
5 | 5 | {
|
6 |
| - /// <summary> |
7 |
| - /// A class for representing flow. |
8 |
| - /// </summary> |
9 |
| - public struct Flow : IComparable, IComparable<Flow> |
10 |
| - { |
11 |
| - private const double SecondToMinuteRatio = 60; |
12 |
| - private const double SecondToHourRatio = 3600; |
13 |
| - |
14 |
| - public readonly double CubicMeterPerSecond; |
15 |
| - |
16 |
| - private Flow(double cubicMeterPerSecond) |
17 |
| - : this() |
18 |
| - { |
19 |
| - CubicMeterPerSecond = cubicMeterPerSecond; |
20 |
| - } |
21 |
| - |
22 |
| - public double CubicMeterPerHour |
23 |
| - { |
24 |
| - get { return CubicMeterPerSecond / SecondToHourRatio; } |
25 |
| - } |
26 |
| - |
27 |
| - #region Static |
28 |
| - |
29 |
| - public static Flow Zero |
30 |
| - { |
31 |
| - get { return new Flow(); } |
32 |
| - } |
33 |
| - |
34 |
| - public static Flow FromCubicMeterPerHour(double cmh) |
35 |
| - { |
36 |
| - return new Flow(cmh * SecondToHourRatio); |
37 |
| - } |
38 |
| - |
39 |
| - public static Flow FromCubicMeterPerSecond(double cms) |
40 |
| - { |
41 |
| - return new Flow(cms); |
42 |
| - } |
43 |
| - |
44 |
| - #endregion |
45 |
| - |
46 |
| - #region Equality / IComparable |
47 |
| - |
48 |
| - public int CompareTo(object obj) |
49 |
| - { |
50 |
| - if (obj == null) throw new ArgumentNullException("obj"); |
51 |
| - if (!(obj is Flow)) throw new ArgumentException("Expected type Flow.", "obj"); |
52 |
| - return CompareTo((Flow)obj); |
53 |
| - } |
54 |
| - |
55 |
| - public int CompareTo(Flow other) |
56 |
| - { |
57 |
| - return CubicMeterPerSecond.CompareTo(other.CubicMeterPerSecond); |
58 |
| - } |
59 |
| - |
60 |
| - public static bool operator <=(Flow left, Flow right) |
61 |
| - { |
62 |
| - return left.CubicMeterPerSecond <= right.CubicMeterPerSecond; |
63 |
| - } |
64 |
| - |
65 |
| - public static bool operator >=(Flow left, Flow right) |
66 |
| - { |
67 |
| - return left.CubicMeterPerSecond >= right.CubicMeterPerSecond; |
68 |
| - } |
69 |
| - |
70 |
| - public static bool operator <(Flow left, Flow right) |
71 |
| - { |
72 |
| - return left.CubicMeterPerSecond < right.CubicMeterPerSecond; |
73 |
| - } |
74 |
| - |
75 |
| - public static bool operator >(Flow left, Flow right) |
76 |
| - { |
77 |
| - return left.CubicMeterPerSecond > right.CubicMeterPerSecond; |
78 |
| - } |
79 |
| - |
80 |
| - public static bool operator ==(Flow left, Flow right) |
81 |
| - { |
82 |
| - return left.CubicMeterPerSecond == right.CubicMeterPerSecond; |
83 |
| - } |
84 |
| - |
85 |
| - public static bool operator !=(Flow left, Flow right) |
86 |
| - { |
87 |
| - return left.CubicMeterPerSecond != right.CubicMeterPerSecond; |
88 |
| - } |
89 |
| - |
90 |
| - public override bool Equals(object obj) |
91 |
| - { |
92 |
| - if (obj == null || GetType() != obj.GetType()) |
93 |
| - { |
94 |
| - return false; |
95 |
| - } |
96 |
| - |
97 |
| - return CubicMeterPerSecond.Equals(((Flow)obj).CubicMeterPerSecond); |
98 |
| - } |
99 |
| - |
100 |
| - public override int GetHashCode() |
101 |
| - { |
102 |
| - return CubicMeterPerSecond.GetHashCode(); |
103 |
| - } |
104 |
| - #endregion |
105 |
| - |
106 |
| - #region Arithmetic operators |
107 |
| - |
108 |
| - public static Flow operator -(Flow right) |
109 |
| - { |
110 |
| - return new Flow(-right.CubicMeterPerSecond); |
111 |
| - } |
112 |
| - |
113 |
| - public static Flow operator +(Flow left, Flow right) |
114 |
| - { |
115 |
| - return new Flow(left.CubicMeterPerSecond + right.CubicMeterPerSecond); |
116 |
| - } |
117 |
| - |
118 |
| - public static Flow operator -(Flow left, Flow right) |
119 |
| - { |
120 |
| - return new Flow(left.CubicMeterPerSecond - right.CubicMeterPerSecond); |
121 |
| - } |
122 |
| - |
123 |
| - public static Flow operator *(double left, Flow right) |
124 |
| - { |
125 |
| - return new Flow(left * right.CubicMeterPerSecond); |
126 |
| - } |
127 |
| - |
128 |
| - public static Flow operator *(Flow left, double right) |
129 |
| - { |
130 |
| - return new Flow(left.CubicMeterPerSecond * right); |
131 |
| - } |
132 |
| - |
133 |
| - public static Flow operator /(Flow left, double right) |
134 |
| - { |
135 |
| - return new Flow(left.CubicMeterPerSecond / right); |
136 |
| - } |
137 |
| - |
138 |
| - public static double operator /(Flow left, Flow right) |
139 |
| - { |
140 |
| - return left.CubicMeterPerSecond / right.CubicMeterPerSecond; |
141 |
| - } |
142 |
| - |
143 |
| - #endregion |
144 |
| - |
145 |
| - public override string ToString() |
146 |
| - { |
| 6 | + /// <summary> |
| 7 | + /// A class for representing flow. |
| 8 | + /// </summary> |
| 9 | + public struct Flow : IComparable, IComparable<Flow> |
| 10 | + { |
| 11 | + private const double SecondToMinuteRatio = 60; |
| 12 | + private const double SecondToHourRatio = 3600; |
| 13 | + |
| 14 | + public readonly double CubicMeterPerSecond; |
| 15 | + |
| 16 | + private Flow(double cubicMeterPerSecond) |
| 17 | + : this() |
| 18 | + { |
| 19 | + CubicMeterPerSecond = cubicMeterPerSecond; |
| 20 | + } |
| 21 | + |
| 22 | + public double CubicMeterPerHour |
| 23 | + { |
| 24 | + get { return CubicMeterPerSecond / SecondToHourRatio; } |
| 25 | + } |
| 26 | + |
| 27 | + #region Static |
| 28 | + |
| 29 | + public static Flow Zero |
| 30 | + { |
| 31 | + get { return new Flow(); } |
| 32 | + } |
| 33 | + |
| 34 | + public static Flow FromCubicMeterPerHour(double cmh) |
| 35 | + { |
| 36 | + return new Flow(cmh * SecondToHourRatio); |
| 37 | + } |
| 38 | + |
| 39 | + public static Flow FromCubicMeterPerSecond(double cms) |
| 40 | + { |
| 41 | + return new Flow(cms); |
| 42 | + } |
| 43 | + |
| 44 | + #endregion |
| 45 | + |
| 46 | + #region Equality / IComparable |
| 47 | + |
| 48 | + public int CompareTo(object obj) |
| 49 | + { |
| 50 | + if (obj == null) throw new ArgumentNullException("obj"); |
| 51 | + if (!(obj is Flow)) throw new ArgumentException("Expected type Flow.", "obj"); |
| 52 | + return CompareTo((Flow)obj); |
| 53 | + } |
| 54 | + |
| 55 | + public int CompareTo(Flow other) |
| 56 | + { |
| 57 | + return CubicMeterPerSecond.CompareTo(other.CubicMeterPerSecond); |
| 58 | + } |
| 59 | + |
| 60 | + public static bool operator <=(Flow left, Flow right) |
| 61 | + { |
| 62 | + return left.CubicMeterPerSecond <= right.CubicMeterPerSecond; |
| 63 | + } |
| 64 | + |
| 65 | + public static bool operator >=(Flow left, Flow right) |
| 66 | + { |
| 67 | + return left.CubicMeterPerSecond >= right.CubicMeterPerSecond; |
| 68 | + } |
| 69 | + |
| 70 | + public static bool operator <(Flow left, Flow right) |
| 71 | + { |
| 72 | + return left.CubicMeterPerSecond < right.CubicMeterPerSecond; |
| 73 | + } |
| 74 | + |
| 75 | + public static bool operator >(Flow left, Flow right) |
| 76 | + { |
| 77 | + return left.CubicMeterPerSecond > right.CubicMeterPerSecond; |
| 78 | + } |
| 79 | + |
| 80 | + public static bool operator ==(Flow left, Flow right) |
| 81 | + { |
| 82 | + return left.CubicMeterPerSecond == right.CubicMeterPerSecond; |
| 83 | + } |
| 84 | + |
| 85 | + public static bool operator !=(Flow left, Flow right) |
| 86 | + { |
| 87 | + return left.CubicMeterPerSecond != right.CubicMeterPerSecond; |
| 88 | + } |
| 89 | + |
| 90 | + public override bool Equals(object obj) |
| 91 | + { |
| 92 | + if (obj == null || GetType() != obj.GetType()) |
| 93 | + { |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + return CubicMeterPerSecond.Equals(((Flow)obj).CubicMeterPerSecond); |
| 98 | + } |
| 99 | + |
| 100 | + public override int GetHashCode() |
| 101 | + { |
| 102 | + return CubicMeterPerSecond.GetHashCode(); |
| 103 | + } |
| 104 | + #endregion |
| 105 | + |
| 106 | + #region Arithmetic operators |
| 107 | + |
| 108 | + public static Flow operator -(Flow right) |
| 109 | + { |
| 110 | + return new Flow(-right.CubicMeterPerSecond); |
| 111 | + } |
| 112 | + |
| 113 | + public static Flow operator +(Flow left, Flow right) |
| 114 | + { |
| 115 | + return new Flow(left.CubicMeterPerSecond + right.CubicMeterPerSecond); |
| 116 | + } |
| 117 | + |
| 118 | + public static Flow operator -(Flow left, Flow right) |
| 119 | + { |
| 120 | + return new Flow(left.CubicMeterPerSecond - right.CubicMeterPerSecond); |
| 121 | + } |
| 122 | + |
| 123 | + public static Flow operator *(double left, Flow right) |
| 124 | + { |
| 125 | + return new Flow(left * right.CubicMeterPerSecond); |
| 126 | + } |
| 127 | + |
| 128 | + public static Flow operator *(Flow left, double right) |
| 129 | + { |
| 130 | + return new Flow(left.CubicMeterPerSecond * right); |
| 131 | + } |
| 132 | + |
| 133 | + public static Flow operator /(Flow left, double right) |
| 134 | + { |
| 135 | + return new Flow(left.CubicMeterPerSecond / right); |
| 136 | + } |
| 137 | + |
| 138 | + public static double operator /(Flow left, Flow right) |
| 139 | + { |
| 140 | + return left.CubicMeterPerSecond / right.CubicMeterPerSecond; |
| 141 | + } |
| 142 | + |
| 143 | + #endregion |
| 144 | + |
| 145 | + public override string ToString() |
| 146 | + { |
147 | 147 | return string.Format("≈{0:0.##} {1}", CubicMeterPerSecond, UnitSystem.Create().GetDefaultAbbreviation(Unit.CubicMeterPerSecond));
|
148 |
| - } |
149 |
| - } |
| 148 | + } |
| 149 | + } |
150 | 150 | }
|
0 commit comments