-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathControllableHashCode.cs
More file actions
44 lines (34 loc) · 1.13 KB
/
ControllableHashCode.cs
File metadata and controls
44 lines (34 loc) · 1.13 KB
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
using System;
using System.Collections.Generic;
using System.Text;
using YellowCounter.FileSystemState.HashCodes;
namespace PathReduxTests.HashCodes
{
public class ControllableHashCode : IHashCode
{
private StringBuilder stringBuilder = new StringBuilder();
private bool dead = false;
public void Add(char value)
{
stringBuilder.Append(value);
}
public int ToHashCode()
{
deadCheck();
string arg = stringBuilder.ToString();
// Use comma as delimiter between desired hash number and remaining text.
int commaPos = arg.IndexOf(',');
if(commaPos == -1)
throw new Exception($"{nameof(ControllableHashCode)} requires , in each string");
if(int.TryParse(arg.Substring(0, commaPos), out int result))
return result;
throw new Exception("Text before , must be an integer");
}
private void deadCheck()
{
if(dead)
throw new Exception("Cannot call ToHashCode() twice");
dead = true;
}
}
}