-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllergies.cs
79 lines (65 loc) · 1.82 KB
/
Allergies.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
[Flags]
public enum Allergen
{
Eggs = 1,
Peanuts = 2,
Shellfish = 4,
Strawberries = 8,
Tomatoes = 16,
Chocolate = 32,
Pollen = 64,
Cats = 128
}
public class Allergies
{
int allergyScore;
Allergen castedAllergyScore;
Allergen incomingAllergies;
List<Allergen> allergenList = new List<Allergen>();
public Allergies(int mask)
{
if(mask > 255)
{
do
{
mask -= 256;
} while (mask > 255);
}
allergyScore = mask;
}
public bool IsAllergicTo(Allergen allergen)
{
incomingAllergies = allergen;
castedAllergyScore = (Allergen)allergyScore;
if(castedAllergyScore.HasFlag(allergen))
{
return true;
}
else
{
return false;
}
}
public Allergen[] List()
{
castedAllergyScore = (Allergen)allergyScore;
string[] splitList = new string[] { };
if ((castedAllergyScore.HasFlag(incomingAllergies)) && (allergyScore != 0))
{
allergenList.Add(castedAllergyScore);
for (int i = 0; i < allergenList.Count; i++)
{
splitList = allergenList[i].ToString()
.Split(new Char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
allergenList.Clear();
foreach (string s in splitList)
{
allergenList.Add((Allergen)Enum.Parse(typeof(Allergen), s));
}
}
return allergenList.ToArray();
}
}