using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RealTimeGraphX
{
///
/// Represents an base class.
///
///
public abstract class GraphDataPointBase : IGraphDataPoint
{
#region IComparable
///
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
///
/// An object to compare with this instance.
///
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the sort order as . Greater than zero This instance follows in the sort order.
///
public abstract int CompareTo(object obj);
///
/// Determines whether the specified , is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
return base.Equals(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()
{
return base.GetHashCode();
}
#endregion
#region Logical Operators
///
/// Implements the operator >.
///
///
/// The result of the operator.
///
public static bool operator >(GraphDataPointBase a, GraphDataPointBase b)
{
return a.CompareTo(b) == 1;
}
///
/// Implements the operator <.
///
///
/// The result of the operator.
///
public static bool operator <(GraphDataPointBase a, GraphDataPointBase b)
{
return a.CompareTo(b) == -1;
}
///
/// Implements the operator ==.
///
///
/// The result of the operator.
///
public static bool operator ==(GraphDataPointBase a, GraphDataPointBase b)
{
if (Object.ReferenceEquals(a, null) && Object.ReferenceEquals(b, null)) return true;
if (Object.ReferenceEquals(a, null) && !Object.ReferenceEquals(b, null)) return false;
return a.CompareTo(b) == 0;
}
///
/// Implements the operator !=.
///
///
/// The result of the operator.
///
public static bool operator !=(GraphDataPointBase a, GraphDataPointBase b)
{
if (Object.ReferenceEquals(a, null) && Object.ReferenceEquals(b, null)) return false;
if (Object.ReferenceEquals(a, null) && !Object.ReferenceEquals(b, null)) return true;
return a.CompareTo(b) != 0;
}
#endregion
#region Mathematical Operators
///
/// Implements the operator -.
///
///
/// The result of the operator.
///
public static GraphDataPointBase operator -(GraphDataPointBase a, GraphDataPointBase b)
{
return (GraphDataPointBase)a.Subtract(b);
}
///
/// Implements the operator +.
///
///
/// The result of the operator.
///
public static GraphDataPointBase operator +(GraphDataPointBase a, GraphDataPointBase b)
{
return (GraphDataPointBase)a.Add(b);
}
///
/// Implements the operator /.
///
///
/// The result of the operator.
///
public static GraphDataPointBase operator /(GraphDataPointBase a, GraphDataPointBase b)
{
return (GraphDataPointBase)a.Divide(b);
}
///
/// Implements the operator *.
///
///
/// The result of the operator.
///
public static GraphDataPointBase operator *(GraphDataPointBase a, GraphDataPointBase b)
{
return (GraphDataPointBase)a.Multiply(b);
}
#endregion
#region IGraphDataPoint
///
/// Sums the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public abstract IGraphDataPoint Add(IGraphDataPoint other);
///
/// Subtract the value of another instance from this instance and returns the result.
///
/// The other instance.
///
public abstract IGraphDataPoint Subtract(IGraphDataPoint other);
///
/// Multiplies the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public abstract IGraphDataPoint Multiply(IGraphDataPoint other);
///
/// Divides the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public abstract IGraphDataPoint Divide(IGraphDataPoint other);
///
/// Returns the percentage value of this instance between the specified minimum and maximum values.
///
/// The minimum.
/// The maximum.
///
public abstract double ComputeRelativePosition(IGraphDataPoint min, IGraphDataPoint max);
///
/// Returns the absolute value of the specified percentage value between the specified minimum and maximum values.
///
/// The minimum.
/// The maximum.
/// The percentage.
///
public abstract IGraphDataPoint ComputeAbsolutePosition(IGraphDataPoint min, IGraphDataPoint max, double percentage);
///
/// Creates a range of values from the specified minimum and maximum.
///
/// The minimum.
/// The maximum.
/// The count.
///
public abstract IEnumerable CreateRange(IGraphDataPoint min, IGraphDataPoint max, int count);
///
/// Gets the inner value.
///
///
public abstract object GetValue();
///
/// Sets the inner value.
///
/// The value.
public abstract void SetValue(object value);
///
/// Returns a formated string of this data point.
///
/// The format.
///
public abstract string ToString(string format);
#endregion
}
///
/// Represents an base class.
///
///
/// The type of the data type.
///
public abstract class GraphDataTypeBase : GraphDataPointBase where T : IComparable where TDataType : GraphDataTypeBase
{
#region Properties
///
/// Gets or sets the encapsulated data point value.
///
public T Value { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public GraphDataTypeBase()
{
}
///
/// Initializes a new instance of the class.
///
/// The value.
public GraphDataTypeBase(T value)
{
Value = value;
}
#endregion
#region IComparable
///
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
///
/// An object to compare with this instance.
///
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the sort order as . Greater than zero This instance follows in the sort order.
///
public override int CompareTo(object obj)
{
if (Object.ReferenceEquals(obj, null)) return -1;
GraphDataTypeBase b = obj as GraphDataTypeBase;
return Value.CompareTo(b.Value);
}
///
/// Determines whether the specified , is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
var @base = obj as GraphDataTypeBase;
return @base != null &&
EqualityComparer.Default.Equals(Value, @base.Value);
}
///
/// 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()
{
return -1937169414 + EqualityComparer.Default.GetHashCode(Value);
}
#endregion
#region ToString
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return Value.ToString();
}
#endregion
#region IGraphDataPoint
///
/// Gets the inner value.
///
///
public override object GetValue()
{
return Value;
}
///
/// Sets the inner value.
///
/// The value.
public override void SetValue(object value)
{
Value = (T)value;
}
#endregion
#region Implicit Operators
///
/// Performs an implicit conversion from to .
///
/// The value.
///
/// The result of the conversion.
///
public static implicit operator GraphDataTypeBase(T value)
{
return Activator.CreateInstance(typeof(TDataType), value) as GraphDataTypeBase;
}
///
/// Performs an implicit conversion from to .
///
/// The instance.
///
/// The result of the conversion.
///
public static implicit operator T(GraphDataTypeBase instance)
{
return instance.Value;
}
#endregion
}
}