Skip to content

Commit d273973

Browse files
committed
Upgraded to J2N 1.0.0-beta-0001
1 parent 01c7990 commit d273973

31 files changed

Lines changed: 227 additions & 326 deletions

build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup Label="NuGet Package Reference Versions">
3-
<J2NPackageReferenceVersion>1.0.0-alpha-0030</J2NPackageReferenceVersion>
3+
<J2NPackageReferenceVersion>1.0.0-beta-0001</J2NPackageReferenceVersion>
44
<MicrosoftCSharpPackageReferenceVersion>4.4.0</MicrosoftCSharpPackageReferenceVersion>
55
<MicrosoftNETTestSdkPackageReferenceVersion>16.1.1</MicrosoftNETTestSdkPackageReferenceVersion>
66
<NerdBankGitVersioningPackageReferenceVersion>[2.3.183]</NerdBankGitVersioningPackageReferenceVersion>

src/ICU4N.Collation/Impl/Coll/CollationDataBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,8 @@ private void BuildFastLatinTable(CollationData data)
13801380
char[] header = fastLatinBuilder.GetHeader();
13811381
char[] table = fastLatinBuilder.GetTable();
13821382
if (base_ != null &&
1383-
Arrays.Equals(header, base_.fastLatinTableHeader) &&
1384-
Arrays.Equals(table, base_.FastLatinTable))
1383+
ArrayEqualityComparer<char>.OneDimensional.Equals(header, base_.fastLatinTableHeader) &&
1384+
ArrayEqualityComparer<char>.OneDimensional.Equals(table, base_.FastLatinTable))
13851385
{
13861386
// Same fast Latin table as in the base, use that one instead.
13871387
fastLatinBuilder = null;

src/ICU4N.Collation/Impl/Coll/CollationDataReader.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using J2N.IO;
66
using J2N.Numerics;
77
using System.Diagnostics;
8-
using Arrays = J2N.Collections.Arrays;
98

109
namespace ICU4N.Impl.Coll
1110
{

src/ICU4N.Collation/Impl/Coll/CollationSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public override bool Equals(object other)
106106
CollationSettings o = (CollationSettings)other;
107107
if (options != o.options) { return false; }
108108
if ((options & AlternateMask) != 0 && variableTop != o.variableTop) { return false; }
109-
if (!Arrays.Equals(reorderCodes, o.reorderCodes)) { return false; }
109+
if (!ArrayEqualityComparer<int>.OneDimensional.Equals(reorderCodes, o.reorderCodes)) { return false; }
110110
return true;
111111
}
112112

src/ICU4N.Collation/Text/RuleBasedCollator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ public override void SetReorderCodes(params int[] order)
935935
}
936936
if (length == 0 ?
937937
settings.ReadOnly.ReorderCodes.Length == 0 :
938-
Arrays.Equals(order, settings.ReadOnly.ReorderCodes))
938+
ArrayEqualityComparer<int>.OneDimensional.Equals(order, settings.ReadOnly.ReorderCodes))
939939
{
940940
return;
941941
}

src/ICU4N.Transliterator/Text/TransliteratorParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ private void ParseRules(RuleBody ruleArray, TransliterationDirection dir)
12761276

12771277
// ICU4N: Catch blocks are using ArgumentException, and we need to
12781278
// aggregate our error messages in order for the tests to pass.
1279-
throw new ArgumentException(CollectionUtil.ToString(errors));
1279+
throw new ArgumentException(string.Format(StringFormatter.CurrentCulture, "{0}", errors));
12801280
}
12811281
}
12821282

src/ICU4N/Impl/IntTrie.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public override bool Equals(Object other)
226226
{
227227
Int32Trie othertrie = (Int32Trie)other;
228228
if (m_initialValue_ != othertrie.m_initialValue_
229-
|| !Arrays.Equals(m_data_, othertrie.m_data_))
229+
|| !ArrayEqualityComparer<int>.OneDimensional.Equals(m_data_, othertrie.m_data_))
230230
{
231231
return false;
232232
}

src/ICU4N/Impl/IntTrieBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Int32TrieBuilder(int[] aliasdata, int maxdatalength,
9393

9494
m_dataLength_ = j;
9595
// reset the initially allocated blocks to the initial value
96-
Arrays.Fill(m_data_, 0, m_dataLength_, initialvalue);
96+
m_data_.Fill(0, m_dataLength_ - 0, initialvalue); // ICU4N: Corrected length
9797
m_initialValue_ = initialvalue;
9898
m_leadUnitValue_ = leadunitvalue;
9999
m_dataCapacity_ = maxdatalength;

src/ICU4N/Impl/Relation.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using ICU4N.Support.Collections;
22
using ICU4N.Util;
33
using J2N.Collections;
4+
using J2N.Collections.Generic;
5+
using J2N.Text;
46
using System;
57
using System.Collections;
68
using System.Collections.Generic;
@@ -34,21 +36,31 @@ public static Relation<TKey, TValue> Of<TKey, TValue>(IDictionary<TKey, ISet<TVa
3436
/// <typeparam name="TKey">Type of key.</typeparam>
3537
/// <typeparam name="TValue">Type of value.</typeparam>
3638
/// <author>medavis</author>
37-
public class Relation<TKey, TValue> : IFreezable<Relation<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>
39+
public class Relation<TKey, TValue> : IFreezable<Relation<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IStructuralEquatable
3840
where TValue : class // ICU4N specific - using only reference types so we don't have to change from null to default(TValue)
3941
{
4042
private IDictionary<TKey, ISet<TValue>> data;
4143

4244
ConstructorInfo setCreator;
4345
object[] setComparerParam;
4446

47+
private readonly DictionaryEqualityComparer<TKey, ISet<TValue>> structuralEqualityComparer;
48+
4549
public Relation(IDictionary<TKey, ISet<TValue>> map, Type setCreator)
46-
: this(map, setCreator, null)
47-
{
48-
}
50+
: this(map, setCreator, null, DictionaryEqualityComparer<TKey, ISet<TValue>>.Aggressive) // ICU4N TODO: Factor out Aggressive mode
51+
{ }
52+
53+
public Relation(IDictionary<TKey, ISet<TValue>> map, Type setCreator, DictionaryEqualityComparer<TKey, ISet<TValue>> structuralEqualityComparer)
54+
: this(map, setCreator, null, structuralEqualityComparer)
55+
{ }
4956

5057
public Relation(IDictionary<TKey, ISet<TValue>> map, Type setCreator, IComparer<TValue> setComparator)
58+
: this(map, setCreator, null, DictionaryEqualityComparer<TKey, ISet<TValue>>.Aggressive) // ICU4N TODO: Factor out Aggressive mode
59+
{ }
60+
61+
public Relation(IDictionary<TKey, ISet<TValue>> map, Type setCreator, IComparer<TValue> setComparator, DictionaryEqualityComparer<TKey, ISet<TValue>> structuralEqualityComparer)
5162
{
63+
this.structuralEqualityComparer = structuralEqualityComparer ?? throw new ArgumentNullException(nameof(structuralEqualityComparer));
5264
try
5365
{
5466
setComparerParam = setComparator == null ? null : new object[] { setComparator };
@@ -178,9 +190,9 @@ public override bool Equals(object o)
178190
{
179191
if (o == null)
180192
return false;
181-
if (o.GetType() != this.GetType())
182-
return false;
183-
return data.Equals(((Relation<TKey, TValue>)o).data);
193+
if (o is Relation<TKey, TValue> otherRelation)
194+
return structuralEqualityComparer.Equals(this.data, otherRelation.data);
195+
return false;
184196
}
185197

186198
// public V get(Object key) {
@@ -202,9 +214,25 @@ public ISet<TValue> Get(TKey key)
202214

203215
public override int GetHashCode()
204216
{
205-
return CollectionUtil.GetHashCode(data);
217+
return structuralEqualityComparer.GetHashCode(data);
218+
}
219+
220+
#region IStructualEquatable Members
221+
222+
public bool Equals(object other, IEqualityComparer comparer)
223+
{
224+
if (other is Relation<TKey, TValue> otherRelation)
225+
return structuralEqualityComparer.Equals(this.data, otherRelation.data);
226+
return false;
227+
}
228+
229+
public int GetHashCode(IEqualityComparer comparer)
230+
{
231+
return structuralEqualityComparer.GetHashCode(data);
206232
}
207233

234+
#endregion
235+
208236
//public virtual bool IsEmpty // ICU4N specific - removed because this is not .NET-like
209237
//{
210238
// get { return data.Count == 0; }
@@ -347,7 +375,7 @@ public virtual C GetValues<C>(C result)
347375

348376
public override string ToString()
349377
{
350-
return CollectionUtil.ToString(data);
378+
return string.Format(StringFormatter.CurrentCulture, "{0}", data);
351379
}
352380

353381
// ICU4N specific - SimpleEntry class not needed, since we have implemented IEnumerator.

src/ICU4N/Impl/Trie.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public override bool Equals(object other)
110110
return m_isLatin1Linear_ == othertrie.m_isLatin1Linear_
111111
&& m_options_ == othertrie.m_options_
112112
&& m_dataLength == othertrie.m_dataLength
113-
&& Arrays.Equals(m_index, othertrie.m_index);
113+
&& ArrayEqualityComparer<char>.OneDimensional.Equals(m_index, othertrie.m_index);
114114
}
115115

116116
public override int GetHashCode()

0 commit comments

Comments
 (0)