Last active
August 29, 2015 14:21
-
-
Save bboyle1234/22cf8a471341a78b339d to your computer and use it in GitHub Desktop.
Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 { | |
class Program { | |
public interface IDataPoint { | |
int Index { get; set; } | |
double Value { get; set; } | |
DateTime TimeStampLocal { get; set; } | |
IDataPoint Clone(); | |
} | |
public sealed class SimpleDataPoint : IDataPoint { | |
public int Index { get; set; } | |
public double Value { get; set; } | |
public DateTime TimeStampLocal { get; set; } | |
public IDataPoint Clone() { | |
return new SimpleDataPoint { | |
Index = Index, | |
Value = Value, | |
TimeStampLocal = TimeStampLocal, | |
}; | |
} | |
} | |
public interface IDataSeries<TDataPoint> where TDataPoint : class, IDataPoint { | |
object Source { get; } | |
int Count { get; } | |
double GetValue(int index); | |
DateTime GetTimeStampLocal(int index); | |
TDataPoint GetDataPoint(int index); | |
TDataPoint GetLastDataPoint(); | |
void Add(TDataPoint dataPoint); | |
IDataSeries<TDataPoint> Branch(object source); | |
} | |
public class DataSeries<TDataPoint> : IDataSeries<TDataPoint> where TDataPoint : class, IDataPoint { | |
readonly List<TDataPoint> _data = new List<TDataPoint>(); | |
public object Source { | |
get; | |
private set; | |
} | |
public DataSeries(object source) { | |
Source = source; | |
} | |
public int Count { | |
get { return _data.Count; } | |
} | |
public TDataPoint GetDataPoint(int index) { | |
return _data[index]; | |
} | |
public TDataPoint GetLastDataPoint() { | |
return _data[_data.Count - 1]; | |
} | |
public DateTime GetTimeStampLocal(int index) { | |
return _data[index].TimeStampLocal; | |
} | |
public double GetValue(int index) { | |
return _data[index].Value; | |
} | |
public void Add(TDataPoint dataPoint) { | |
_data.Add(dataPoint); | |
} | |
public IDataSeries<TDataPoint> Branch(object source) { | |
throw new NotImplementedException(); | |
} | |
} | |
[STAThread] | |
static void Main(string[] args) { | |
var source = new object(); | |
var ds = (IDataSeries<IDataPoint>)new DataSeries<SimpleDataPoint>(source); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment