-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenCollection.cs
More file actions
25 lines (19 loc) · 1.1 KB
/
Copy pathTokenCollection.cs
File metadata and controls
25 lines (19 loc) · 1.1 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
namespace CSharpener;
/// <summary>
/// Typed, queryable collection for Token (IO) work items.
/// Use when you need clean typed access to tokens outside a batch context.
/// </summary>
public sealed class TokenCollection : IReadOnlyList<Token>
{
private readonly List<Token> _items = new();
public Token this[int i] => _items[i];
public int Count => _items.Count;
public IEnumerator<Token> GetEnumerator() => _items.GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
public void Add(Token token) => _items.Add(token);
public IEnumerable<Token> Leads => _items.Where(t => t.Tag.Role == OperationRole.Lead);
public IEnumerable<Token> Children => _items.Where(t => t.Tag.Role == OperationRole.Child);
public IEnumerable<Token> ForGroup(char g) => _items.Where(t => t.Tag.Group == g);
public IEnumerable<Token> OnCore(int coreId) => _items.Where(t => t.Tag.CoreId == coreId);
public bool AllTerminal => _items.All(t => t.State is WorkState.Resolved or WorkState.Failed);
}