2024-06-04 20:46:31 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
|
|
|
|
public class User
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly User Invalid = new User();
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
public string Email { get; set; } = string.Empty;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
public User()
|
|
|
|
|
{
|
|
|
|
|
// Only used by User.Invalid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User(string data)
|
|
|
|
|
{
|
|
|
|
|
var nameEndIdx = data.IndexOf('±', StringComparison.Ordinal);
|
|
|
|
|
|
|
|
|
|
Name = nameEndIdx > 0 ? data.Substring(0, nameEndIdx) : string.Empty;
|
|
|
|
|
Email = data.Substring(nameEndIdx + 1);
|
|
|
|
|
_hash = data.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (obj == null || !(obj is User))
|
|
|
|
|
return false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
var other = obj as User;
|
|
|
|
|
return Name == other.Name && Email == other.Email;
|
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
|
return _hash;
|
2023-10-09 20:25:57 -07:00
|
|
|
|
}
|
2020-07-03 00:24:31 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static User FindOrAdd(string data)
|
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
|
return _caches.GetOrAdd(data, key => new User(key));
|
2020-07-03 00:24:31 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
|
2024-05-11 02:00:35 -07:00
|
|
|
|
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private readonly int _hash;
|
2020-07-03 00:24:31 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|