forked from tkellogg/Jump-Location
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.cs
49 lines (40 loc) · 1.11 KB
/
Database.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
using System.Collections.Generic;
using System.Linq;
namespace Jump.Location
{
public interface IDatabase
{
IEnumerable<IRecord> Records { get; }
void Add(string fullPath);
void Add(IRecord record);
bool Remove(IRecord record);
IRecord GetByFullName(string fullName);
}
class Database : IDatabase
{
readonly List<IRecord> records = new List<IRecord>();
public IEnumerable<IRecord> Records { get { return records; } }
public void Add(string fullPath)
{
records.Add(new Record(fullPath));
}
public void Add(IRecord record)
{
records.Add(record);
}
public bool Remove(IRecord record)
{
return records.Remove(record);
}
public IRecord GetByFullName(string fullName)
{
var record = records.FirstOrDefault(x => x.FullName == fullName);
if (record == null)
{
record = new Record(fullName);
Add(record);
}
return record;
}
}
}