Skip to content

Commit 8725916

Browse files
committed
Clean up.
1 parent b0a0cce commit 8725916

15 files changed

+152
-93
lines changed

src/IKVM.Java.Extensions/IKVM.Java.Extensions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
<PropertyGroup>
77
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
8-
<Nullable>true</Nullable>
8+
<Nullable>enable</Nullable>
99
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1010
<PackageReadmeFile>README.md</PackageReadmeFile>
11-
<Description>Various extensions for working against Java types.</Description>
11+
<Description>Various extensions for bridging the gap between .NET and Java.</Description>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

src/IKVM.Java.Extensions/java/util/CollectionWrapper.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace java.util
99
class CollectionWrapper<T> : IterableWrapper<T>, ICollection<T>
1010
{
1111

12-
readonly Collection collection;
12+
internal readonly Collection _collection;
1313

1414
/// <summary>
1515
/// Initializes a new instance.
@@ -18,28 +18,35 @@ class CollectionWrapper<T> : IterableWrapper<T>, ICollection<T>
1818
/// <exception cref="ArgumentNullException"></exception>
1919
public CollectionWrapper(Collection collection) : base(collection)
2020
{
21-
this.collection = collection ?? throw new ArgumentNullException(nameof(collection));
21+
_collection = collection ?? throw new ArgumentNullException(nameof(collection));
2222
}
2323

24-
public int Count => collection.size();
24+
/// <inheritdoc />
25+
public int Count => _collection.size();
2526

27+
/// <inheritdoc />
2628
public bool IsReadOnly => false;
2729

28-
public void Add(T item) => collection.add(item);
30+
/// <inheritdoc />
31+
public void Add(T item) => _collection.add(item);
2932

30-
public void Clear() => collection.clear();
33+
/// <inheritdoc />
34+
public void Clear() => _collection.clear();
3135

32-
public bool Contains(T item) => collection.contains(item);
36+
/// <inheritdoc />
37+
public bool Contains(T item) => _collection.contains(item);
3338

39+
/// <inheritdoc />
3440
public void CopyTo(T[] array, int arrayIndex)
3541
{
3642
foreach (var entry in this)
3743
array[arrayIndex++] = entry;
3844
}
3945

46+
/// <inheritdoc />
4047
public bool Remove(T item)
4148
{
42-
return collection.remove(item);
49+
return _collection.remove(item);
4350
}
4451

4552
}

src/IKVM.Java.Extensions/java/util/EnumerationWrapper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace java.util
88
class EnumerationWrapper<T> : IEnumerator<T>
99
{
1010

11-
readonly Enumeration enumeration;
12-
T current;
13-
int position = -1;
11+
readonly Enumeration _enumeration;
12+
T? _current;
13+
int _position = -1;
1414

1515
/// <summary>
1616
/// Initializes a new instance.
@@ -19,18 +19,18 @@ class EnumerationWrapper<T> : IEnumerator<T>
1919
/// <exception cref="ArgumentNullException"></exception>
2020
public EnumerationWrapper(Enumeration enumeration)
2121
{
22-
this.enumeration = enumeration ?? throw new ArgumentNullException(nameof(enumeration));
22+
_enumeration = enumeration ?? throw new ArgumentNullException(nameof(enumeration));
2323
}
2424

2525
/// <summary>
2626
/// Gets the current element.
2727
/// </summary>
28-
public T Current => position > -1 ? current : throw new InvalidOperationException();
28+
public T Current => _position > -1 ? _current! : throw new InvalidOperationException();
2929

3030
/// <summary>
3131
/// Gets the current element.
3232
/// </summary>
33-
object IEnumerator.Current => current;
33+
object? IEnumerator.Current => _current;
3434

3535
/// <summary>
3636
/// Moves to the next instance.
@@ -39,10 +39,10 @@ public EnumerationWrapper(Enumeration enumeration)
3939
/// <exception cref="NotImplementedException"></exception>
4040
public bool MoveNext()
4141
{
42-
if (enumeration.hasMoreElements())
42+
if (_enumeration.hasMoreElements())
4343
{
44-
current = (T)enumeration.nextElement();
45-
position++;
44+
_current = (T)_enumeration.nextElement();
45+
_position++;
4646
return true;
4747
}
4848

src/IKVM.Java.Extensions/java/util/IteratorWrapper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace java.util
88
class IteratorWrapper<T> : IEnumerator<T>
99
{
1010

11-
readonly Iterator iterator;
12-
T current;
13-
int position = -1;
11+
readonly Iterator _iterator;
12+
T? _current;
13+
int _position = -1;
1414

1515
/// <summary>
1616
/// Initializes a new instance.
@@ -19,29 +19,29 @@ class IteratorWrapper<T> : IEnumerator<T>
1919
/// <exception cref="ArgumentNullException"></exception>
2020
public IteratorWrapper(Iterator iterator)
2121
{
22-
this.iterator = iterator ?? throw new ArgumentNullException(nameof(iterator));
22+
_iterator = iterator ?? throw new ArgumentNullException(nameof(iterator));
2323
}
2424

2525
/// <summary>
2626
/// Gets the current element.
2727
/// </summary>
28-
public T Current => position > -1 ? current : throw new InvalidOperationException();
28+
public T Current => _position > -1 ? _current! : throw new InvalidOperationException();
2929

3030
/// <summary>
3131
/// Gets the current element.
3232
/// </summary>
33-
object IEnumerator.Current => current;
33+
object? IEnumerator.Current => _current;
3434

3535
/// <summary>
3636
/// Moves to the next instance.
3737
/// </summary>
3838
/// <returns></returns>
3939
public bool MoveNext()
4040
{
41-
if (iterator.hasNext())
41+
if (_iterator.hasNext())
4242
{
43-
current = (T)iterator.next();
44-
position++;
43+
_current = (T)_iterator.next();
44+
_position++;
4545
return true;
4646
}
4747

src/IKVM.Java.Extensions/java/util/ListWrapper.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace java.util
77
class ListWrapper<T> : CollectionWrapper<T>, IList<T>
88
{
99

10-
readonly List list;
10+
readonly List _list;
1111

1212
/// <summary>
1313
/// Initializes a new instance.
@@ -17,19 +17,24 @@ class ListWrapper<T> : CollectionWrapper<T>, IList<T>
1717
public ListWrapper(List list) :
1818
base(list)
1919
{
20-
this.list = list ?? throw new ArgumentNullException(nameof(list));
20+
_list = list ?? throw new ArgumentNullException(nameof(list));
2121
}
2222

23+
/// <inheritdoc />
2324
public T this[int index]
2425
{
25-
get => (T)list.get(index);
26-
set => list.set(index, value); }
26+
get => (T)_list.get(index);
27+
set => _list.set(index, value);
28+
}
2729

28-
public int IndexOf(T item) => list.indexOf(item);
30+
/// <inheritdoc />
31+
public int IndexOf(T item) => _list.indexOf(item);
2932

30-
public void Insert(int index, T item) => list.add(index, item);
33+
/// <inheritdoc />
34+
public void Insert(int index, T item) => _list.add(index, item);
3135

32-
public void RemoveAt(int index) => list.remove(index);
36+
/// <inheritdoc />
37+
public void RemoveAt(int index) => _list.remove(index);
3338

3439
}
3540

src/IKVM.Java.Extensions/java/util/MapWrapper.cs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace java.util
1111
class MapWrapper<TKey, TValue> : IDictionary<TKey, TValue>
1212
{
1313

14-
readonly Map map;
14+
readonly Map _map;
1515

1616
/// <summary>
1717
/// Initializes a new instance.
@@ -20,78 +20,94 @@ class MapWrapper<TKey, TValue> : IDictionary<TKey, TValue>
2020
/// <exception cref="ArgumentNullException"></exception>
2121
public MapWrapper(Map map)
2222
{
23-
this.map = map ?? throw new ArgumentNullException(nameof(map));
23+
this._map = map ?? throw new ArgumentNullException(nameof(map));
2424
}
2525

26+
/// <inheritdoc />
2627
public TValue this[TKey key]
2728
{
28-
get => (TValue)map.get(key);
29-
set => map.put(key, value);
29+
get => (TValue)_map.get(key);
30+
set => _map.put(key, value);
3031
}
3132

32-
public ICollection<TKey> Keys => map.keySet().AsCollection<TKey>();
33+
/// <inheritdoc />
34+
public ICollection<TKey> Keys => _map.keySet().AsCollection<TKey>();
3335

34-
public ICollection<TValue> Values => map.values().AsCollection<TValue>();
36+
/// <inheritdoc />
37+
public ICollection<TValue> Values => _map.values().AsCollection<TValue>();
3538

36-
public int Count => map.size();
39+
/// <inheritdoc />
40+
public int Count => _map.size();
3741

42+
/// <inheritdoc />
3843
public bool IsReadOnly => false;
3944

40-
public void Add(TKey key, TValue value) => map.put(key, value);
45+
/// <inheritdoc />
46+
public void Add(TKey key, TValue value) => _map.put(key, value);
4147

42-
public void Add(KeyValuePair<TKey, TValue> item) => map.put(item.Key, item.Value);
48+
/// <inheritdoc />
49+
public void Add(KeyValuePair<TKey, TValue> item) => _map.put(item.Key, item.Value);
4350

44-
public void Clear() => map.clear();
51+
/// <inheritdoc />
52+
public void Clear() => _map.clear();
4553

54+
/// <inheritdoc />
4655
public bool Contains(KeyValuePair<TKey, TValue> item)
4756
{
48-
return map.containsKey(item.Key) && map.get(item.Key).Equals(item.Value);
57+
return _map.containsKey(item.Key) && _map.get(item.Key).Equals(item.Value);
4958
}
5059

60+
/// <inheritdoc />
5161
public bool ContainsKey(TKey key)
5262
{
53-
return map.containsKey(key);
63+
return _map.containsKey(key);
5464
}
5565

66+
/// <inheritdoc />
5667
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
5768
{
5869
foreach (var entry in this)
5970
array[arrayIndex++] = entry;
6071
}
6172

73+
/// <inheritdoc />
6274
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
6375
{
64-
return map.entrySet().AsEnumerable<Map.Entry>().Select(i => new KeyValuePair<TKey, TValue>((TKey)i.getKey(), (TValue)i.getValue())).GetEnumerator();
76+
return _map.entrySet().AsEnumerable<Map.Entry>().Select(i => new KeyValuePair<TKey, TValue>((TKey)i.getKey(), (TValue)i.getValue())).GetEnumerator();
6577
}
6678

79+
/// <inheritdoc />
6780
public bool Remove(TKey key)
6881
{
69-
if (map.containsKey(key))
82+
if (_map.containsKey(key))
7083
{
71-
map.remove(key);
84+
_map.remove(key);
7285
return true;
7386
}
7487

7588
return false;
7689
}
7790

91+
/// <inheritdoc />
7892
public bool Remove(KeyValuePair<TKey, TValue> item)
7993
{
80-
return map.remove(item.Key, item.Value);
94+
return _map.remove(item.Key, item.Value);
8195
}
8296

97+
/// <inheritdoc />
8398
public bool TryGetValue(TKey key, out TValue value)
8499
{
85-
if (map.containsKey(key))
100+
if (_map.containsKey(key))
86101
{
87-
value = (TValue) map.get(key);
102+
value = (TValue) _map.get(key);
88103
return true;
89104
}
90105

91-
value = default;
106+
value = default!;
92107
return false;
93108
}
94109

110+
/// <inheritdoc />
95111
IEnumerator IEnumerable.GetEnumerator()
96112
{
97113
return GetEnumerator();

0 commit comments

Comments
 (0)