IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ModuleVersionComponent.cs
Go to the documentation of this file.
1using System;
2
4{
5
9 internal readonly struct ModuleVersionComponent : IComparable<ModuleVersionComponent>
10 {
11
12 public static bool operator ==(ModuleVersionComponent x, ModuleVersionComponent y) => x.Equals(y);
13
14 public static bool operator !=(ModuleVersionComponent x, ModuleVersionComponent y) => x.Equals(y) == false;
15
16 public static bool operator <(ModuleVersionComponent x, ModuleVersionComponent y) => Compare(x, y) < 0;
17
18 public static bool operator >(ModuleVersionComponent x, ModuleVersionComponent y) => Compare(x, y) > 0;
19
20 public static bool operator <=(ModuleVersionComponent x, ModuleVersionComponent y) => Compare(x, y) <= 0;
21
22 public static bool operator >=(ModuleVersionComponent x, ModuleVersionComponent y) => Compare(x, y) >= 0;
23
24 public static int Compare(ModuleVersionComponent x, ModuleVersionComponent y) => x.CompareTo(y);
25
26 readonly int _integer;
27 readonly string? _string;
28
33 public ModuleVersionComponent(int value)
34 {
35 _integer = value;
36 _string = null;
37 }
38
43 public ModuleVersionComponent(string value)
44 {
45 _integer = -1;
46 _string = value;
47 }
48
52 public readonly bool IsInteger => _string is null;
53
57 public readonly int AsInteger() => _string is null ? _integer : throw new InvalidOperationException();
58
62 public readonly string AsString() => _string ?? _integer.ToString();
63
65 public readonly int CompareTo(ModuleVersionComponent other)
66 {
67 if (IsInteger && other.IsInteger)
68 return AsInteger().CompareTo(other.AsInteger());
69 else
70 return AsString().CompareTo(other.AsString());
71 }
72
74 public readonly override bool Equals(object? obj)
75 {
76 return obj is ModuleVersionComponent other && Equals(other);
77 }
78
84 public readonly bool Equals(ModuleVersionComponent other)
85 {
86 return CompareTo(other) == 0;
87 }
88
90 public readonly override int GetHashCode()
91 {
92 if (IsInteger)
93 return AsInteger().GetHashCode();
94 else
95 return AsString().GetHashCode();
96 }
97
98 }
99
100}