using System;
namespace BotSharp.Algorithm.Bayesian
{
///
/// Class StringClass. This class cannot be inherited.
///
public sealed class StringClass : ClassBase
{
///
/// Initializes a new instance of the class.
///
/// The name.
/// The probability.
/// name
///
/// probability;Class base probability must be greater than or equal to zero.
/// or
/// probability;Class base probability must be less than or equal to one.
///
public StringClass(string name, double probability)
: base(name, probability)
{
}
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with the current .
/// if the specified is equal to this instance; otherwise, .
public override bool Equals(IClass other)
{
var otherAsObject = (object) other;
return Equals(otherAsObject);
}
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with the current .
/// if the specified is equal to this instance; otherwise, .
private bool Equals(StringClass other)
{
if (ReferenceEquals(other, null)) return false;
if (ReferenceEquals(other, this)) return true;
return String.Equals(Name, other.Name)
&& Math.Abs(Probability - other.Probability) < 0.0001D;
}
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with the current .
/// if the specified is equal to this instance; otherwise, .
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is StringClass && Equals((StringClass) obj);
}
///
/// Returns a hash code for this instance.
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode()
{
var hash = 27;
hash = (13 * hash) + Name.GetHashCode();
hash = (13 * hash) + Probability.GetHashCode();
return hash;
}
///
/// Returns a that represents this instance.
///
/// A that represents this instance.
public override string ToString()
{
return Name;
}
}
}