using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RealTimeGraphX
{
///
/// Represents an base class.
///
///
public abstract class GraphDataPoint : 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 >(GraphDataPoint a, GraphDataPoint b)
{
return a.CompareTo(b) == 1;
}
///
/// Implements the operator <.
///
///
/// The result of the operator.
///
public static bool operator <(GraphDataPoint a, GraphDataPoint b)
{
return a.CompareTo(b) == -1;
}
///
/// Implements the operator ==.
///
///
/// The result of the operator.
///
public static bool operator ==(GraphDataPoint a, GraphDataPoint 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 !=(GraphDataPoint a, GraphDataPoint 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 Arithmetic Operators
///
/// Implements the operator -.
///
///
/// The result of the operator.
///
public static GraphDataPoint operator -(GraphDataPoint a, GraphDataPoint b)
{
return (GraphDataPoint)a.Subtract(b);
}
///
/// Implements the operator +.
///
///
/// The result of the operator.
///
public static GraphDataPoint operator +(GraphDataPoint a, GraphDataPoint b)
{
return (GraphDataPoint)a.Add(b);
}
///
/// Implements the operator /.
///
///
/// The result of the operator.
///
public static GraphDataPoint operator /(GraphDataPoint a, GraphDataPoint b)
{
return (GraphDataPoint)a.Divide(b);
}
///
/// Implements the operator *.
///
///
/// The result of the operator.
///
public static GraphDataPoint operator *(GraphDataPoint a, GraphDataPoint b)
{
return (GraphDataPoint)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);
///
/// Parses the specified value.
///
/// The value.
///
public abstract IGraphDataPoint Parse(string value);
#endregion
#region Properties
///
/// Gets the type of this graph data point.
///
public Type Type
{
get { return GetType(); }
}
#endregion
}
///
/// Represents an base class.
///
///
/// The type of the data type.
///
public abstract class GraphDataPoint : GraphDataPoint where T : IComparable where TDataType : GraphDataPoint
{
#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 GraphDataPoint()
{
}
///
/// Initializes a new instance of the class.
///
/// The value.
public GraphDataPoint(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;
GraphDataPoint b = obj as GraphDataPoint;
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 GraphDataPoint;
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 Parsing
///
/// Parses the specified value and returns a new instance of data point.
///
/// The value.
///
public static TDataType ParseFrom(String value)
{
return Activator.CreateInstance().Parse(value) as TDataType;
}
#endregion
#region Implicit Operators
///
/// Performs an implicit conversion from to .
///
/// The value.
///
/// The result of the conversion.
///
public static implicit operator GraphDataPoint(T value)
{
return Activator.CreateInstance(typeof(TDataType), value) as GraphDataPoint;
}
///
/// Performs an implicit conversion from to .
///
/// The instance.
///
/// The result of the conversion.
///
public static implicit operator T(GraphDataPoint instance)
{
return instance.Value;
}
#endregion
}
}