Skip to content

Commit 1ef7673

Browse files
committed
Cleanup Compiler Warnings
hash cleanups compiler warnings addressed. rethrow exceptions excape special chars in xml
1 parent 637b753 commit 1ef7673

23 files changed

Lines changed: 236 additions & 32 deletions

Numerics/Data/Paired Data/OrderedPairedData.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,41 @@ IEnumerator IEnumerable.GetEnumerator()
607607
return !(left == right);
608608
}
609609

610+
/// <summary>
611+
/// Determines whether the specified object is equal to the current object.
612+
/// </summary>
613+
/// <param name="obj">The object to compare with the current object.</param>
614+
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
615+
public override bool Equals(object obj)
616+
{
617+
if (obj is OrderedPairedData other)
618+
{
619+
return this == other;
620+
}
621+
return false;
622+
}
623+
624+
/// <summary>
625+
/// Serves as the default hash function.
626+
/// </summary>
627+
/// <returns>A hash code for the current object.</returns>
628+
public override int GetHashCode()
629+
{
630+
unchecked
631+
{
632+
int hash = 17;
633+
if (_ordinates != null)
634+
{
635+
foreach (var ordinate in _ordinates)
636+
{
637+
hash = hash * 23 + ordinate.X.GetHashCode();
638+
hash = hash * 23 + ordinate.Y.GetHashCode();
639+
}
640+
}
641+
return hash;
642+
}
643+
}
644+
610645
/// <summary>
611646
/// Calculates the area between the Y values and the zero axis using the trapezoidal approximation.
612647
/// </summary>

Numerics/Data/Paired Data/Ordinate.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,29 @@ public Ordinate Transform(Transform xTransform, Transform yTransform)
360360
return !(left == right);
361361
}
362362

363+
/// <summary>
364+
/// Determines whether the specified object is equal to the current object.
365+
/// </summary>
366+
/// <param name="obj">The object to compare with the current object.</param>
367+
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
368+
public override bool Equals(object obj)
369+
{
370+
if (obj is Ordinate other)
371+
{
372+
return this == other;
373+
}
374+
return false;
375+
}
376+
377+
/// <summary>
378+
/// Serves as the default hash function.
379+
/// </summary>
380+
/// <returns>A hash code for the current object.</returns>
381+
public override int GetHashCode()
382+
{
383+
return HashCode.Combine(X.GetHashCode(), Y.GetHashCode());
384+
}
385+
363386
/// <summary>
364387
/// Returns the ordinate as XElement.
365388
/// </summary>

Numerics/Data/Paired Data/UncertainOrderedPairedData.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,40 @@ public List<string> GetErrors()
505505
return !(left == right);
506506
}
507507

508+
/// <summary>
509+
/// Determines whether the specified object is equal to the current object.
510+
/// </summary>
511+
/// <param name="obj">The object to compare with the current object.</param>
512+
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
513+
public override bool Equals(object obj)
514+
{
515+
if (obj is UncertainOrderedPairedData other)
516+
{
517+
return this == other;
518+
}
519+
return false;
520+
}
521+
522+
/// <summary>
523+
/// Serves as the default hash function.
524+
/// </summary>
525+
/// <returns>A hash code for the current object.</returns>
526+
public override int GetHashCode()
527+
{
528+
unchecked
529+
{
530+
int hash = 17;
531+
if (_uncertainOrdinates != null)
532+
{
533+
foreach (var ordinate in _uncertainOrdinates)
534+
{
535+
hash = hash * 23 + ordinate.GetHashCode();
536+
}
537+
}
538+
return hash;
539+
}
540+
}
541+
508542

509543
/// <summary>
510544
/// Get and sets the element at the specific index.

Numerics/Data/Paired Data/UncertainOrdinate.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ public List<string> OrdinateErrors(UncertainOrdinate ordinateToCompare, bool str
216216
var result = new List<string>();
217217
// Validate the target ordinate
218218
result.AddRange(OrdinateErrors());
219-
//
220-
if (ordinateToCompare == null)
221-
return result;
222-
//
219+
//
223220
if (ordinateToCompare.IsValid == false)
224221
{
225222
if (double.IsInfinity(ordinateToCompare.X))
@@ -308,6 +305,35 @@ public List<string> OrdinateErrors()
308305
return !(left == right);
309306
}
310307

308+
/// <summary>
309+
/// Determines whether the specified object is equal to the current object.
310+
/// </summary>
311+
/// <param name="obj">The object to compare with the current object.</param>
312+
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
313+
public override bool Equals(object obj)
314+
{
315+
if (obj is UncertainOrdinate other)
316+
{
317+
return this == other;
318+
}
319+
return false;
320+
}
321+
322+
/// <summary>
323+
/// Serves as the default hash function.
324+
/// </summary>
325+
/// <returns>A hash code for the current object.</returns>
326+
public override int GetHashCode()
327+
{
328+
unchecked
329+
{
330+
int hash = 17;
331+
hash = hash * 23 + X.GetHashCode();
332+
hash = hash * 23 + Y.GetHashCode();
333+
return hash;
334+
}
335+
}
336+
311337
/// <summary>
312338
/// Returns the ordinate as XElement.
313339
/// </summary>

Numerics/Data/Statistics/Histogram.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ public override bool Equals(object obj)
158158
Bin bin = (Bin)obj;
159159
return LowerBound.Equals(bin.LowerBound) && UpperBound.Equals(bin.UpperBound) && Frequency.Equals(bin.Frequency);
160160
}
161+
162+
/// <summary>
163+
/// Serves as the default hash function.
164+
/// </summary>
165+
/// <returns>A hash code for the current object.</returns>
166+
public override int GetHashCode()
167+
{
168+
unchecked
169+
{
170+
int hash = 17;
171+
hash = hash * 23 + LowerBound.GetHashCode();
172+
hash = hash * 23 + UpperBound.GetHashCode();
173+
hash = hash * 23 + Frequency.GetHashCode();
174+
return hash;
175+
}
176+
}
161177
}
162178

163179
/// <summary>

Numerics/Data/Time Series/Support/TimeSeriesDownload.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ public static async Task<TimeSeries> FromGHCN(string siteNumber, TimeSeriesType
266266
}
267267

268268
}
269-
catch (Exception ex)
269+
catch (Exception)
270270
{
271-
throw ex;
271+
throw;
272272
}
273273
finally
274274
{
@@ -511,9 +511,9 @@ private static string CreateURLForUSGSDownload(string siteNumber, TimeSeriesType
511511
}
512512
}
513513
}
514-
catch (Exception ex)
514+
catch (Exception)
515515
{
516-
throw ex;
516+
throw;
517517
}
518518

519519
return (timeSeries, textDownload);

Numerics/Distributions/Multivariate/MultivariateNormal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ private void COVSRT(int N, double[] LOWER, double[] UPPER, double[] CORREL, int[
15881588
}
15891589

15901590
/// <summary>
1591-
/// Swaps rows and columns P and Q in situ, with P <= Q.
1591+
/// Swaps rows and columns P and Q in situ, with P &lt;= Q.
15921592
/// </summary>
15931593
/// <param name="P">Rows</param>
15941594
/// <param name="Q">Columns</param>

Numerics/Distributions/Univariate/Base/UnivariateDistributionBase.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,59 @@ public virtual XElement ToXElement()
763763
return !(left == right);
764764
}
765765

766+
/// <summary>
767+
/// Determines whether the specified object is equal to the current object.
768+
/// </summary>
769+
/// <param name="obj">The object to compare with the current object.</param>
770+
/// <returns>True if the specified object is equal to the current object; otherwise, False.</returns>
771+
public override bool Equals(object obj)
772+
{
773+
if (obj is UnivariateDistributionBase other)
774+
{
775+
return this == other;
776+
}
777+
return false;
778+
}
779+
780+
/// <summary>
781+
/// Serves as the default hash function.
782+
/// </summary>
783+
/// <returns>A hash code for the current object.</returns>
784+
public override int GetHashCode()
785+
{
786+
unchecked
787+
{
788+
int hash = 17;
789+
hash = hash * 23 + Type.GetHashCode();
790+
791+
if (Type == UnivariateDistributionType.Empirical)
792+
{
793+
var empirical = this as EmpiricalDistribution;
794+
if (empirical != null)
795+
{
796+
foreach (var x in empirical.XValues)
797+
{
798+
hash = hash * 23 + x.GetHashCode();
799+
}
800+
foreach (var p in empirical.ProbabilityValues)
801+
{
802+
hash = hash * 23 + p.GetHashCode();
803+
}
804+
}
805+
}
806+
else if (Type != UnivariateDistributionType.KernelDensity)
807+
{
808+
var parameters = GetParameters;
809+
foreach (var param in parameters)
810+
{
811+
hash = hash * 23 + param.GetHashCode();
812+
}
813+
}
814+
815+
return hash;
816+
}
817+
}
818+
766819
/// <summary>
767820
/// Implementation of IComparable to sort distributions by their Mean.
768821
/// </summary>

Numerics/Distributions/Univariate/EmpiricalDistribution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace Numerics.Distributions
6363
/// <list type="bullet">
6464
/// <item><description>
6565
/// The distribution behaves similarly to the "RiskCumul" function in the Palisade's @Risk software.
66-
/// <see href="http://kb.palisade.com/index.php?pg=kb.page&id=51"/>
66+
/// <see href="http://kb.palisade.com/index.php?pg=kb.page&amp;id=51"/>
6767
/// </description></item>
6868
/// </list>
6969
/// </para>

Numerics/Distributions/Univariate/Gumbel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ public void SetParametersFromMLE(IList<double> sample)
448448
// If the newton method fails to converge, fall back to sample moments
449449
SetParameters(ParametersFromMoments(moments));
450450
}
451-
catch (Exception ex)
451+
catch (Exception)
452452
{
453-
throw ex;
453+
throw;
454454
}
455455
}
456456

0 commit comments

Comments
 (0)