IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ModuleExports.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Immutable;
3using System.Linq;
4
5using IKVM.ByteCode;
7
9{
10
11
15 internal readonly struct ModuleExports : IComparable<ModuleExports>
16 {
17
18 readonly ModuleExportsFlag _modifiers;
19 readonly string _source;
20 readonly ImmutableHashSet<string> _targets;
21
28 public ModuleExports(ModuleExportsFlag modifiers, string source, ImmutableHashSet<string> targets)
29 {
30 _modifiers = modifiers;
31 _source = source ?? throw new ArgumentNullException(nameof(source));
32 _targets = targets ?? throw new ArgumentNullException(nameof(targets));
33 }
34
38 public readonly ModuleExportsFlag Modifiers => _modifiers;
39
43 public readonly string Source => _source;
44
49 public readonly ImmutableHashSet<string> Targets => _targets;
50
54 public readonly bool IsQualified => _targets.IsEmpty == false;
55
57 public readonly int CompareTo(ModuleExports other)
58 {
59 int c = _source.CompareTo(other._source);
60 if (c != 0)
61 return c;
62
63 // modifiers
64 c = _modifiers.CompareTo(other.Modifiers);
65 if (c != 0)
66 return c;
67
68 // targets
69 var t1 = _targets.ToArray();
70 var t2 = other._targets.ToArray();
71 Array.Sort(t1);
72 Array.Sort(t2);
74 }
75
77 public override bool Equals(object? obj)
78 {
79 return obj is ModuleExports other && Equals(other);
80 }
81
83 public bool Equals(ModuleExports other)
84 {
85 return _modifiers == other._modifiers && _source == other._source && _targets.SetEquals(other._targets);
86 }
87
89 public override int GetHashCode()
90 {
91 var hc = new HashCode();
92 hc.Add(_modifiers);
93 hc.Add(_source);
94
95 foreach (var t in _targets)
96 hc.Add(t);
97
98 return hc.ToHashCode();
99 }
100
101 }
102
103}
Implements an IComparer<T> which lexicographically compares a two lists.
static new readonly LexicographicListComparer< T > Default
Returns a default LexicographicListComparer<T> instance.