Skip to content

Commit

Permalink
Remove unused methods from *Helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Mar 8, 2013
1 parent a70af4e commit 82ad2c9
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 143 deletions.
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Build vNext
* ISession.SaveOrUpdateCopy removed: Use Merge instead
* Oracle: The atan2 and power functions now return double (instead of single) for consistency with other dialects.
* Removed FirebirdDriver. It was the same as FirebirdClientDriver since 3.2, and the latter have been the default since then.
* Removed bunch of unused methods on *Helper classes

Build 3.3.3.CR1
=============================
Expand Down
18 changes: 1 addition & 17 deletions src/NHibernate.Test/UtilityTest/ArrayHelperTests.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Util;
using NHibernate.Util;
using NUnit.Framework;

namespace NHibernate.Test.UtilityTest
{
[TestFixture]
public class ArrayHelperTests
{
[Test]
public void GetHashCodeShouldBeEqual()
{
var a = new[] { 1, 2, 3, 4 };
var b = new[] { 1, 2, 3, 4 };

Assert.That(ArrayHelper.ArrayGetHashCode(a), Is.EqualTo(ArrayHelper.ArrayGetHashCode(b)));
}


[Test]
public void NullArraysShouldBeEqual()
{
bool[] a = null, b = null;
Assert.That(ArrayHelper.ArrayEquals(a, b), Is.True);
}


[Test]
public void EitherArrayNullShouldNotBeEqual()
{
Expand All @@ -37,7 +22,6 @@ public void EitherArrayNullShouldNotBeEqual()
Assert.That(ArrayHelper.ArrayEquals(b, a), Is.False);
}


[Test]
public void ArraysShouldBeEqual()
{
Expand Down
4 changes: 1 addition & 3 deletions src/NHibernate/Criterion/ProjectionList.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;

namespace NHibernate.Criterion
{
Expand Down Expand Up @@ -127,7 +125,7 @@ public string[] GetColumnAliases(int position, ICriteria criteria, ICriteriaQuer
result.AddRange(colAliases);
position += colAliases.Length;
}
return ArrayHelper.ToStringArray(result);
return result.ToArray();
}

public string[] GetColumnAliases(string alias, int position, ICriteria criteria, ICriteriaQuery criteriaQuery)
Expand Down
100 changes: 1 addition & 99 deletions src/NHibernate/Util/ArrayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@ public static class ArrayHelper

public static bool IsAllNegative(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i] >= 0)
{
return false;
}
}

return true;
return array.All(t => t < 0);
}


public static T[] Fill<T>(T value, int length)
{
var result = new T[length];
Expand All @@ -49,7 +40,6 @@ public static void Fill<T>(T[] array, T value)
}
}


public static T[] Slice<T>(T[] strings, int begin, int length)
{
var result = new T[length];
Expand Down Expand Up @@ -81,33 +71,6 @@ public static bool IsAllFalse(bool[] array)
return Array.IndexOf(array, true) < 0;
}

public static string[][] To2DStringArray(ICollection coll)
{
var result = new string[coll.Count][];
int i = 0;
foreach (object row in coll)
{
var rowAsCollection = row as ICollection;
if (rowAsCollection != null)
{
result[i] = new string[rowAsCollection.Count];
int j = 0;
foreach (object cell in rowAsCollection)
{
result[i][j++] = cell == null ? null : (string)cell;
}
}
else
{
result[i] = new string[1];
result[i][0] = row == null ? null : (string)row;
}
i++;
}

return result;
}

public static string ToString(object[] array)
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -164,16 +127,6 @@ public static void AddAll(IList to, IList from)
}
}

// NH-specific
public static void AddAll(IDictionary to, IDictionary from)
{
foreach (DictionaryEntry de in from)
{
// we want to override the values from to if they exists
to[de.Key] = de.Value;
}
}

// NH-specific
public static void AddAll<TKey, TValue>(IDictionary<TKey, TValue> to, IDictionary<TKey, TValue> from)
{
Expand Down Expand Up @@ -233,38 +186,6 @@ private static int GetNextBatchSize(int batchSize)
}
}


private static void ExpandWithNulls(IList list, int requiredLength)
{
while (list.Count < requiredLength)
{
list.Add(null);
}
}

/// <summary>
/// Sets <paramref name="list" /> item at position <paramref name="index" /> to <paramref name="value" />.
/// Expands the list by adding <see langword="null" /> values, if needed.
/// </summary>
public static void SafeSetValue(IList list, int index, object value)
{
ExpandWithNulls(list, index + 1);
list[index] = value;
}

public static string[] ToStringArray(ICollection coll)
{
return (string[])ToArray(coll, typeof(string));
}


public static Array ToArray(ICollection coll, System.Type elementType)
{
Array result = Array.CreateInstance(elementType, coll.Count);
coll.CopyTo(result, 0);
return result;
}

public static int CountTrue(bool[] array)
{
return array.Count(t => t);
Expand Down Expand Up @@ -312,24 +233,5 @@ public static bool ArrayEquals(byte[] a, byte[] b)
}
return true;
}


/// <summary>
/// Calculate a hash code based on the length and contents of the array.
/// The algorithm is such that if ArrayHelper.ArrayEquals(a,b) returns true,
/// then ArrayGetHashCode(a) == ArrayGetHashCode(b).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static int ArrayGetHashCode<T>(T[] array)
{
int hc = array.Length;

for (int i = 0; i < array.Length; ++i)
hc = unchecked(hc * 31 + array[i].GetHashCode());

return hc;
}
}
}
2 changes: 0 additions & 2 deletions src/NHibernate/Util/IdentityMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace NHibernate.Util
[Serializable]
public sealed class IdentityMap : IDictionary, IDeserializationCallback
{
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(IdentityMap));

// key = IdentityKey of the passed in Key
// value = object passed in
private IDictionary map;
Expand Down
18 changes: 0 additions & 18 deletions src/NHibernate/Util/PropertiesHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace NHibernate.Util
Expand Down Expand Up @@ -67,22 +66,5 @@ public static IDictionary<string, string> ToDictionary(string property, string d
}
return map;
}

public static string[] ToStringArray(string property, string delim, IDictionary properties)
{
return ToStringArray((string) properties[property], delim);
}

public static string[] ToStringArray(string propValue, string delim)
{
if (propValue != null)
{
return StringHelper.Split(delim, propValue);
}
else
{
return new string[0];
}
}
}
}
8 changes: 4 additions & 4 deletions src/NHibernate/Util/ReflectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static bool OverrideMethod(System.Type clazz, string methodName, System.
{
// make sure that the DeclaringType is not System.Object - if that is the
// declaring type then there is no override.
return !method.DeclaringType.Equals(typeof(object));
return !(method.DeclaringType == typeof(object));
}
}
catch (AmbiguousMatchException)
Expand Down Expand Up @@ -717,12 +717,12 @@ public static bool IsMethodOf(this MethodInfo source, System.Type realDeclaringT
throw new ArgumentNullException("realDeclaringType");
}
var methodDeclaringType = source.DeclaringType;
if(realDeclaringType.Equals(methodDeclaringType))
if(realDeclaringType == methodDeclaringType)
{
return true;
}
if (methodDeclaringType.IsGenericType && !methodDeclaringType.IsGenericTypeDefinition &&
realDeclaringType.Equals(methodDeclaringType.GetGenericTypeDefinition()))
realDeclaringType == methodDeclaringType.GetGenericTypeDefinition())
{
return true;
}
Expand All @@ -740,7 +740,7 @@ public static bool IsMethodOf(this MethodInfo source, System.Type realDeclaringT
if (realDeclaringType.IsGenericTypeDefinition)
{
bool implements = declaringTypeInterfaces
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition().Equals(realDeclaringType))
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == realDeclaringType)
.Select(implementedGenericInterface => methodDeclaringType.GetInterfaceMap(implementedGenericInterface))
.Any(methodsMap => methodsMap.TargetMethods.Contains(source));
if (implements)
Expand Down

0 comments on commit 82ad2c9

Please sign in to comment.