| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
- namespace Yuuna.Contracts.Patterns
- {
- using System.Collections.Immutable;
- using System.Diagnostics.CodeAnalysis;
- using Yuuna.Contracts.Semantics;
- using System.Linq;
- using System.Diagnostics;
- public sealed class Pattern : IPattern
- {
- public IImmutableList<string> SequentialKeys { get; private set; }
- private IImmutableList<IGroup> _groups;
- private readonly ImmutableArray<string>.Builder _keyBuilder;
- private readonly ImmutableArray<IGroup>.Builder _groupBuilder;
- internal Pattern()
- {
- this._keyBuilder = ImmutableArray.CreateBuilder<string>();
- this._groupBuilder = ImmutableArray.CreateBuilder<IGroup>();
- }
- internal void Add(IGroup g)
- {
- if (g == null)
- return;
- this._keyBuilder.Add(g.Key);
- this._groupBuilder.Add(g);
- }
- internal void Immute()
- {
- this.SequentialKeys = this._keyBuilder.ToImmutable();
- this._groups = this._groupBuilder.ToImmutable();
- }
- public int Count
- {
- get
- {
- Debug.Assert(this._groups != null);
- return this._groups.Count;
- }
- }
- public IImmutableList<IGroup> ToImmutable()
- {
- Debug.Assert(this._groups != null);
- return this._groups;
- }
- public bool Equals( IPattern other)
- {
- Debug.Assert(this.SequentialKeys != null);
- return this.SequentialKeys.SequenceEqual(other.SequentialKeys);
- }
- }
- }
|