-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVehicleScheduleCapacity.TransfersPerStationCont.cs
95 lines (85 loc) · 3.36 KB
/
VehicleScheduleCapacity.TransfersPerStationCont.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using VoxelTycoon;
using VoxelTycoon.Tracks;
using VoxelTycoon.Tracks.Tasks;
namespace ScheduleStopwatch
{
public partial class VehicleScheduleCapacity
{
public class TransfersPerStationCont
{
private readonly Dictionary<VehicleStationLocation, TaskTransfers> _transfPerSt;
private readonly bool isReadonly = false;
public TransfersPerStationCont() {
_transfPerSt = new Dictionary<VehicleStationLocation, TaskTransfers>();
}
private TransfersPerStationCont(TransfersPerStationCont asReadonly)
{
_transfPerSt = asReadonly._transfPerSt;
isReadonly = true;
}
public TransfersPerStationCont(Dictionary<RootTask, TaskTransfers> transfersPerTask) : this()
{
if (transfersPerTask != null)
{
foreach (KeyValuePair<RootTask, TaskTransfers> pair in transfersPerTask)
{
Add(pair.Key.Destination.VehicleStationLocation, pair.Value);
}
}
}
public TransfersPerStationCont AsReadonly()
{
return new TransfersPerStationCont(this);
}
public void Add(VehicleStationLocation station, TaskTransfers transfers, float? multiplier = null, bool estimated = false)
{
if (isReadonly)
{
throw new InvalidOperationException("TransfersPerStation is readonly");
}
if (_transfPerSt.TryGetValue(station, out TaskTransfers taskTransf))
{
taskTransf.Add(transfers, multiplier, estimated);
} else
{
_transfPerSt.Add(station, new TaskTransfers(transfers, multiplier, estimated));
}
}
public void Add(TransfersPerStationCont transfPerStation, float? multiplier, bool estimated = false)
{
foreach (KeyValuePair<VehicleStationLocation, TaskTransfers> pair in transfPerStation._transfPerSt)
{
Add(pair.Key, pair.Value, multiplier, estimated);
}
}
public IReadOnlyDictionary<Item, TransferData> this[VehicleStationLocation idx]
{
get
{
if (_transfPerSt.TryGetValue(idx, out TaskTransfers taskTransfers))
{
return taskTransfers.Transfers;
}
return null;
}
}
public IEnumerator<KeyValuePair<VehicleStationLocation, IReadOnlyDictionary<Item, TransferData>>> GetEnumerator()
{
foreach (KeyValuePair<VehicleStationLocation, TaskTransfers> taskTransfer in _transfPerSt)
{
yield return new KeyValuePair<VehicleStationLocation, IReadOnlyDictionary<Item, TransferData>>(taskTransfer.Key, taskTransfer.Value.Transfers);
}
yield break;
}
public int Count
{
get
{
return _transfPerSt.Count;
}
}
}
}
}