Files
TextParser/TextParser/Data/DefaultDataSetIndexer.cs
2024-12-05 23:36:23 +01:00

62 lines
2.0 KiB
C#

public class DefaultDataSetIndexer<TDataType> : IDataSetIndexer<TDataType, int>
{
public TDataType Get<TGenericCollectionContentType>(List<TGenericCollectionContentType> collection, IDataIndex<int> index)
{
var indices = index.GetIndices();
return this.GetInternal(collection, indices.ToArray());
}
private TDataType GetInternal<TGenericCollectionContentType>(List<TGenericCollectionContentType> collection, int[] indices)
{
if (indices.Length == 3)
{
return this.GetAtIndex((collection as List<List<List<TDataType>>>), indices[0], indices[1], indices[2]);
}
else if (indices.Length == 2)
{
return this.GetAtIndex((collection as List<List<TDataType>>), indices[0], indices[1]);
}
else if (indices.Length == 1)
{
return this.GetAtIndex((collection as List<TDataType>), indices[0]);
}
else
{
throw new ArgumentException("Invalid Data Set access!");
}
}
public TDataType Get<TGenericCollectionContentType>(List<TGenericCollectionContentType> collection, params int[] indices)
{
return this.GetInternal(collection, indices);
}
public TDataType GetAtIndex(List<TDataType> collection, int index)
{
if (collection == null)
{
throw new ArgumentException("Invalid data set provided for access");
}
return collection[index];
}
public TDataType GetAtIndex(List<List<TDataType>> collection, int x, int y)
{
if (collection == null)
{
throw new ArgumentException("Invalid data set provided for access");
}
return collection[collection.Count - y - 1][x];
}
public TDataType GetAtIndex(List<List<List<TDataType>>> collection, int x, int y, int z)
{
if (collection == null)
{
throw new ArgumentException("Invalid data set provided for access");
}
return collection[z][y][x];
}
}