common/CordonelPreadjustmentUi/Helper/MultiPathDataLogContainer.cs
2026-04-23 17:50:07 +02:00

79 lines
2.1 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CordonelPreadjustmentUi.Helper
{
public class MultiPathDataLogContainer<T>
{
private ConcurrentDictionary<Int32, T> PathValueDic = new ConcurrentDictionary<Int32, T>();
private int numberOfPaths;
private int v;
public MultiPathDataLogContainer(int NumberOfPaths)
{
for (int i = 0; i < NumberOfPaths; i++)
{
PathValueDic.AddOrUpdate(i, default(T), (oldP, oldLineCont) => default(T));
}
}
public MultiPathDataLogContainer(int NumberOfPaths, T defaultVal)
{
for (int i = 0; i < NumberOfPaths; i++)
{
PathValueDic.AddOrUpdate(i, defaultVal, (oldP, oldLineCont) => defaultVal);
}
}
public void Update(Int32? Path = null, T value = default(T))
{
if (Path.HasValue)
{
PathValueDic.AddOrUpdate(Path.Value, value, (oldKey, oldValue) => value);
}
else
{
foreach (var val in PathValueDic)
{
PathValueDic.AddOrUpdate(val.Key, value, (oldKey, oldValue) => value);
}
}
}
public T Get(Int32 Path)
{
if (PathValueDic.ContainsKey(Path))
{
return PathValueDic.First(f => f.Key == Path).Value;
}
else
{
return PathValueDic.First(f => f.Key == Path).Value;
}
}
public Int32 GetPathCount()
{
return PathValueDic.Count;
}
internal void Clear()
{
var tmpCount = GetPathCount();
PathValueDic.Clear();
for (int i = 0; i < tmpCount; i++)
{
PathValueDic.AddOrUpdate(i, default(T), (oldP, oldLineCont) => oldLineCont = default(T));
}
}
}
}