Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverted breaking API changes for 2.1.0 so we don't have to bump to 3.0.0 #113

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/J2N/Collections/Generic/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ public bool TryAdd([AllowNull] TKey key, [AllowNull] TValue value) =>
/// <para/>
/// Getting the value of this property is an O(1) operation.
/// </remarks>
public KeyCollection Keys => _keys ??= new KeyCollection(this);
public ICollection<TKey> Keys => _keys ??= new KeyCollection(this);

ICollection<TKey> IDictionary<TKey, TValue>.Keys => Keys;

Expand All @@ -854,7 +854,7 @@ public bool TryAdd([AllowNull] TKey key, [AllowNull] TValue value) =>
/// <para/>
/// Getting the value of this property is an O(1) operation.
/// </remarks>
public ValueCollection Values => _values ??= new ValueCollection(this);
public ICollection<TValue> Values => _values ??= new ValueCollection(this);

ICollection<TValue> IDictionary<TKey, TValue>.Values => Values;

Expand Down Expand Up @@ -1404,7 +1404,7 @@ public bool Remove([AllowNull] TKey key, [MaybeNullWhen(false)] out TValue value
/// <para/>
/// This method is an O(1) operation.
/// </remarks>
public Enumerator GetEnumerator() => new Enumerator(this, Enumerator.KeyValuePair);
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => new Enumerator(this, Enumerator.KeyValuePair);

IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() =>
Count == 0 ? GenericEmptyEnumerator<KeyValuePair<TKey, TValue>>.Instance :
Expand All @@ -1418,9 +1418,9 @@ IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.

bool IDictionary.IsFixedSize => false;

ICollection IDictionary.Keys => Keys;
ICollection IDictionary.Keys => (ICollection)Keys;

ICollection IDictionary.Values => Values;
ICollection IDictionary.Values => (ICollection)Values;

bool IDictionary.IsReadOnly => false;

Expand Down
10 changes: 5 additions & 5 deletions src/J2N/Collections/Generic/SortedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public IComparer<TKey> Comparer
/// <para/>
/// Getting the value of this property is an O(1) operation.
/// </remarks>
public KeyCollection Keys => _keys ??= new KeyCollection(this);
public ICollection<TKey> Keys => _keys ??= new KeyCollection(this);

ICollection<TKey> IDictionary<TKey, TValue>.Keys => Keys;

Expand All @@ -384,7 +384,7 @@ public IComparer<TKey> Comparer
/// <para/>
/// Getting the value of this property is an O(1) operation.
/// </remarks>
public ValueCollection Values => _values ??= new ValueCollection(this);
public ICollection<TValue> Values => _values ??= new ValueCollection(this);

ICollection<TValue> IDictionary<TKey, TValue>.Values => Values;

Expand Down Expand Up @@ -724,12 +724,12 @@ bool IDictionary.IsReadOnly

ICollection IDictionary.Keys
{
get { return Keys; }
get { return (ICollection)Keys; }
}

ICollection IDictionary.Values
{
get { return Values; }
get { return (ICollection)Values; }
}

object? IDictionary.this[object? key]
Expand Down Expand Up @@ -1038,7 +1038,7 @@ public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDictionaryE

internal Enumerator(SortedDictionary<TKey, TValue> dictionary, int getEnumeratorRetType)
{
_treeEnum = dictionary._set.GetEnumerator();
_treeEnum = dictionary._set.GetEnumeratorInternal();
_getEnumeratorRetType = getEnumeratorRetType;
}

Expand Down
16 changes: 9 additions & 7 deletions src/J2N/Collections/Generic/SortedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ void ICollection.CopyTo(Array array, int index)
/// <para/>
/// This method is an <c>O(log n)</c> operation.
/// </remarks>
public Enumerator GetEnumerator() => new Enumerator(this);
public IEnumerator<T> GetEnumerator() => new Enumerator(this);

internal Enumerator GetEnumeratorInternal() => new Enumerator(this);

IEnumerator<T> IEnumerable<T>.GetEnumerator() => GetEnumerator();

Expand Down Expand Up @@ -1203,8 +1205,8 @@ public void UnionWith(IEnumerable<T> other)
// First do a merge sort to an array.
T[] merged = new T[asSorted.Count + this.Count];
int c = 0;
Enumerator mine = this.GetEnumerator();
Enumerator theirs = asSorted.GetEnumerator();
IEnumerator<T> mine = this.GetEnumerator();
IEnumerator<T> theirs = asSorted.GetEnumerator();
bool mineEnded = !mine.MoveNext(), theirsEnded = !theirs.MoveNext();
while (!mineEnded && !theirsEnded)
{
Expand Down Expand Up @@ -1359,8 +1361,8 @@ public virtual void IntersectWith(IEnumerable<T> other)
// First do a merge sort to an array.
T[] merged = new T[this.Count];
int c = 0;
Enumerator mine = this.GetEnumerator();
Enumerator theirs = asSorted.GetEnumerator();
IEnumerator<T> mine = this.GetEnumerator();
IEnumerator<T> theirs = asSorted.GetEnumerator();
bool mineEnded = !mine.MoveNext(), theirsEnded = !theirs.MoveNext();
T? max = Max;

Expand Down Expand Up @@ -1782,8 +1784,8 @@ public bool SetEquals(IEnumerable<T> other)
SortedSet<T>? asSorted = other as SortedSet<T>;
if (asSorted != null && HasEqualComparer(asSorted))
{
Enumerator mine = GetEnumerator();
Enumerator theirs = asSorted.GetEnumerator();
IEnumerator<T> mine = GetEnumerator();
IEnumerator<T> theirs = asSorted.GetEnumerator();
bool mineEnded = !mine.MoveNext();
bool theirsEnded = !theirs.MoveNext();
while (!mineEnded && !theirsEnded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class Dictionary_Generic_Tests_Keys_AsICollection : ICollection_NonGeneri

protected override ICollection NonGenericICollectionFactory()
{
return new JCG.Dictionary<string, string>().Keys;
return (ICollection)new JCG.Dictionary<string, string>().Keys;
}

protected override ICollection NonGenericICollectionFactory(int count)
Expand All @@ -84,7 +84,7 @@ protected override ICollection NonGenericICollectionFactory(int count)
int seed = 13453;
for (int i = 0; i < count; i++)
list.Add(CreateT(seed++), CreateT(seed++));
return list.Keys;
return (ICollection)list.Keys;
}

private string CreateT(int seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Dictionary_Generic_Tests_Values_AsICollection : ICollection_NonGene

protected override ICollection NonGenericICollectionFactory()
{
return new JCG.Dictionary<string, string>().Values;
return (ICollection)new JCG.Dictionary<string, string>().Values;
}

protected override ICollection NonGenericICollectionFactory(int count)
Expand All @@ -88,7 +88,7 @@ protected override ICollection NonGenericICollectionFactory(int count)
int seed = 13453;
for (int i = 0; i < count; i++)
list.Add(CreateT(seed++), CreateT(seed++));
return list.Values;
return (ICollection)list.Values;
}

private string CreateT(int seed)
Expand Down