Lots of updates
This commit is contained in:
71
PWAPPv2/Source/DataObjects/NumValList.cs
Normal file
71
PWAPPv2/Source/DataObjects/NumValList.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
class NumValList
|
||||
{
|
||||
private List<NumValPair> Pairs;
|
||||
|
||||
public NumValList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public NumValList(string Content, char Delim)
|
||||
{
|
||||
string[] split = Content.Split(Delim);
|
||||
if((split.Length % 2) != 0)
|
||||
{
|
||||
throw new UnevenValuesException();
|
||||
}
|
||||
for(int i = 0; i < split.Length; i++)
|
||||
{
|
||||
this.Add(int.Parse(split[i]), split[i + 1]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(int Num, string Val)
|
||||
{
|
||||
Pairs.Add(new NumValPair(Num, Val));
|
||||
}
|
||||
|
||||
public string GetValFromNum(int Num)
|
||||
{
|
||||
for (int i = 0; i < Pairs.Count; i++)
|
||||
{
|
||||
if (Pairs[i].Num == Num)
|
||||
{
|
||||
return Pairs[i].Value;
|
||||
}
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
public int GetNumFromVal(string Val)
|
||||
{
|
||||
for (int i = 0; i < Pairs.Count; i++)
|
||||
{
|
||||
if (Pairs[i].Value == Val)
|
||||
{
|
||||
return Pairs[i].Num;
|
||||
}
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NotFoundException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
class UnevenValuesException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user