-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathematicianName.cs
50 lines (41 loc) · 1.58 KB
/
MathematicianName.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace Mathematicians.Domain
{
public class MathematicianName
{
private Lazy<BigInteger> _hashCodeInt;
private MathematicianName()
{
_hashCodeInt = new Lazy<BigInteger>(ComputeHashCodeInt);
}
internal MathematicianName(IEnumerable<MathematicianName> priorNames, string firstName, string lastName)
{
Prior = priorNames.ToList();
FirstName = firstName;
LastName = lastName;
HashCode = FirstName.Sha256Hash()
.Concatenate(LastName.Sha256Hash())
.Concatenate(Prior.Select(x => x.HashCodeInt).ToArray())
.ToByteArray();
_hashCodeInt = new Lazy<BigInteger>(ComputeHashCodeInt);
}
public int MathematicianNameId { get; private set; }
public int MathematicianId { get; private set; }
public virtual Mathematician Mathematician { get; private set; }
public byte[] HashCode { get; private set; }
public BigInteger HashCodeInt => _hashCodeInt.Value;
public string FirstName { get; private set; }
public string LastName { get; private set; }
public virtual ICollection<MathematicianName> Prior { get; } =
new List<MathematicianName>();
public virtual ICollection<MathematicianName> Next { get; } =
new List<MathematicianName>();
private BigInteger ComputeHashCodeInt()
{
return new BigInteger(HashCode);
}
}
}