Skip to content

Commit 82ad2c9

Browse files
committed
Remove unused methods from *Helper classes
1 parent a70af4e commit 82ad2c9

File tree

7 files changed

+8
-143
lines changed

7 files changed

+8
-143
lines changed

releasenotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Build vNext
2525
* ISession.SaveOrUpdateCopy removed: Use Merge instead
2626
* Oracle: The atan2 and power functions now return double (instead of single) for consistency with other dialects.
2727
* Removed FirebirdDriver. It was the same as FirebirdClientDriver since 3.2, and the latter have been the default since then.
28+
* Removed bunch of unused methods on *Helper classes
2829

2930
Build 3.3.3.CR1
3031
=============================

src/NHibernate.Test/UtilityTest/ArrayHelperTests.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using NHibernate.Util;
1+
using NHibernate.Util;
62
using NUnit.Framework;
73

84
namespace NHibernate.Test.UtilityTest
95
{
106
[TestFixture]
117
public class ArrayHelperTests
128
{
13-
[Test]
14-
public void GetHashCodeShouldBeEqual()
15-
{
16-
var a = new[] { 1, 2, 3, 4 };
17-
var b = new[] { 1, 2, 3, 4 };
18-
19-
Assert.That(ArrayHelper.ArrayGetHashCode(a), Is.EqualTo(ArrayHelper.ArrayGetHashCode(b)));
20-
}
21-
22-
239
[Test]
2410
public void NullArraysShouldBeEqual()
2511
{
2612
bool[] a = null, b = null;
2713
Assert.That(ArrayHelper.ArrayEquals(a, b), Is.True);
2814
}
2915

30-
3116
[Test]
3217
public void EitherArrayNullShouldNotBeEqual()
3318
{
@@ -37,7 +22,6 @@ public void EitherArrayNullShouldNotBeEqual()
3722
Assert.That(ArrayHelper.ArrayEquals(b, a), Is.False);
3823
}
3924

40-
4125
[Test]
4226
public void ArraysShouldBeEqual()
4327
{

src/NHibernate/Criterion/ProjectionList.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Linq.Expressions;
54

65
using NHibernate.Engine;
76
using NHibernate.Impl;
87
using NHibernate.SqlCommand;
98
using NHibernate.Type;
10-
using NHibernate.Util;
119

1210
namespace NHibernate.Criterion
1311
{
@@ -127,7 +125,7 @@ public string[] GetColumnAliases(int position, ICriteria criteria, ICriteriaQuer
127125
result.AddRange(colAliases);
128126
position += colAliases.Length;
129127
}
130-
return ArrayHelper.ToStringArray(result);
128+
return result.ToArray();
131129
}
132130

133131
public string[] GetColumnAliases(string alias, int position, ICriteria criteria, ICriteriaQuery criteriaQuery)

src/NHibernate/Util/ArrayHelper.cs

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,9 @@ public static class ArrayHelper
2222

2323
public static bool IsAllNegative(int[] array)
2424
{
25-
for (int i = 0; i < array.Length; i++)
26-
{
27-
if (array[i] >= 0)
28-
{
29-
return false;
30-
}
31-
}
32-
33-
return true;
25+
return array.All(t => t < 0);
3426
}
3527

36-
3728
public static T[] Fill<T>(T value, int length)
3829
{
3930
var result = new T[length];
@@ -49,7 +40,6 @@ public static void Fill<T>(T[] array, T value)
4940
}
5041
}
5142

52-
5343
public static T[] Slice<T>(T[] strings, int begin, int length)
5444
{
5545
var result = new T[length];
@@ -81,33 +71,6 @@ public static bool IsAllFalse(bool[] array)
8171
return Array.IndexOf(array, true) < 0;
8272
}
8373

84-
public static string[][] To2DStringArray(ICollection coll)
85-
{
86-
var result = new string[coll.Count][];
87-
int i = 0;
88-
foreach (object row in coll)
89-
{
90-
var rowAsCollection = row as ICollection;
91-
if (rowAsCollection != null)
92-
{
93-
result[i] = new string[rowAsCollection.Count];
94-
int j = 0;
95-
foreach (object cell in rowAsCollection)
96-
{
97-
result[i][j++] = cell == null ? null : (string)cell;
98-
}
99-
}
100-
else
101-
{
102-
result[i] = new string[1];
103-
result[i][0] = row == null ? null : (string)row;
104-
}
105-
i++;
106-
}
107-
108-
return result;
109-
}
110-
11174
public static string ToString(object[] array)
11275
{
11376
StringBuilder sb = new StringBuilder();
@@ -164,16 +127,6 @@ public static void AddAll(IList to, IList from)
164127
}
165128
}
166129

167-
// NH-specific
168-
public static void AddAll(IDictionary to, IDictionary from)
169-
{
170-
foreach (DictionaryEntry de in from)
171-
{
172-
// we want to override the values from to if they exists
173-
to[de.Key] = de.Value;
174-
}
175-
}
176-
177130
// NH-specific
178131
public static void AddAll<TKey, TValue>(IDictionary<TKey, TValue> to, IDictionary<TKey, TValue> from)
179132
{
@@ -233,38 +186,6 @@ private static int GetNextBatchSize(int batchSize)
233186
}
234187
}
235188

236-
237-
private static void ExpandWithNulls(IList list, int requiredLength)
238-
{
239-
while (list.Count < requiredLength)
240-
{
241-
list.Add(null);
242-
}
243-
}
244-
245-
/// <summary>
246-
/// Sets <paramref name="list" /> item at position <paramref name="index" /> to <paramref name="value" />.
247-
/// Expands the list by adding <see langword="null" /> values, if needed.
248-
/// </summary>
249-
public static void SafeSetValue(IList list, int index, object value)
250-
{
251-
ExpandWithNulls(list, index + 1);
252-
list[index] = value;
253-
}
254-
255-
public static string[] ToStringArray(ICollection coll)
256-
{
257-
return (string[])ToArray(coll, typeof(string));
258-
}
259-
260-
261-
public static Array ToArray(ICollection coll, System.Type elementType)
262-
{
263-
Array result = Array.CreateInstance(elementType, coll.Count);
264-
coll.CopyTo(result, 0);
265-
return result;
266-
}
267-
268189
public static int CountTrue(bool[] array)
269190
{
270191
return array.Count(t => t);
@@ -312,24 +233,5 @@ public static bool ArrayEquals(byte[] a, byte[] b)
312233
}
313234
return true;
314235
}
315-
316-
317-
/// <summary>
318-
/// Calculate a hash code based on the length and contents of the array.
319-
/// The algorithm is such that if ArrayHelper.ArrayEquals(a,b) returns true,
320-
/// then ArrayGetHashCode(a) == ArrayGetHashCode(b).
321-
/// </summary>
322-
/// <typeparam name="T"></typeparam>
323-
/// <param name="array"></param>
324-
/// <returns></returns>
325-
public static int ArrayGetHashCode<T>(T[] array)
326-
{
327-
int hc = array.Length;
328-
329-
for (int i = 0; i < array.Length; ++i)
330-
hc = unchecked(hc * 31 + array[i].GetHashCode());
331-
332-
return hc;
333-
}
334236
}
335237
}

src/NHibernate/Util/IdentityMap.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ namespace NHibernate.Util
2929
[Serializable]
3030
public sealed class IdentityMap : IDictionary, IDeserializationCallback
3131
{
32-
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(IdentityMap));
33-
3432
// key = IdentityKey of the passed in Key
3533
// value = object passed in
3634
private IDictionary map;

src/NHibernate/Util/PropertiesHelper.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43

54
namespace NHibernate.Util
@@ -67,22 +66,5 @@ public static IDictionary<string, string> ToDictionary(string property, string d
6766
}
6867
return map;
6968
}
70-
71-
public static string[] ToStringArray(string property, string delim, IDictionary properties)
72-
{
73-
return ToStringArray((string) properties[property], delim);
74-
}
75-
76-
public static string[] ToStringArray(string propValue, string delim)
77-
{
78-
if (propValue != null)
79-
{
80-
return StringHelper.Split(delim, propValue);
81-
}
82-
else
83-
{
84-
return new string[0];
85-
}
86-
}
8769
}
8870
}

src/NHibernate/Util/ReflectHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static bool OverrideMethod(System.Type clazz, string methodName, System.
5252
{
5353
// make sure that the DeclaringType is not System.Object - if that is the
5454
// declaring type then there is no override.
55-
return !method.DeclaringType.Equals(typeof(object));
55+
return !(method.DeclaringType == typeof(object));
5656
}
5757
}
5858
catch (AmbiguousMatchException)
@@ -717,12 +717,12 @@ public static bool IsMethodOf(this MethodInfo source, System.Type realDeclaringT
717717
throw new ArgumentNullException("realDeclaringType");
718718
}
719719
var methodDeclaringType = source.DeclaringType;
720-
if(realDeclaringType.Equals(methodDeclaringType))
720+
if(realDeclaringType == methodDeclaringType)
721721
{
722722
return true;
723723
}
724724
if (methodDeclaringType.IsGenericType && !methodDeclaringType.IsGenericTypeDefinition &&
725-
realDeclaringType.Equals(methodDeclaringType.GetGenericTypeDefinition()))
725+
realDeclaringType == methodDeclaringType.GetGenericTypeDefinition())
726726
{
727727
return true;
728728
}
@@ -740,7 +740,7 @@ public static bool IsMethodOf(this MethodInfo source, System.Type realDeclaringT
740740
if (realDeclaringType.IsGenericTypeDefinition)
741741
{
742742
bool implements = declaringTypeInterfaces
743-
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition().Equals(realDeclaringType))
743+
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == realDeclaringType)
744744
.Select(implementedGenericInterface => methodDeclaringType.GetInterfaceMap(implementedGenericInterface))
745745
.Any(methodsMap => methodsMap.TargetMethods.Contains(source));
746746
if (implements)

0 commit comments

Comments
 (0)