Skip to content

Commit

Permalink
Use primary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBoxyBear committed Jan 4, 2024
1 parent 19bbe9f commit f71cf92
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ChartTools/Chords/Phrase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ChartTools.Lyrics;

public class Phrase : TrackObjectBase, IChord, ILongTrackObject
{
public List<Syllable> Syllables { get; } = new();
public List<Syllable> Syllables { get; } = [];
IReadOnlyCollection<INote> IChord.Notes => Syllables;

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions ChartTools/Exceptions/DesynchronizedAnchorException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
/// <summary>
/// Exception thrown when an invalid operation is performed on a desynchronized anchored <see cref="Tempo"/>.
/// </summary>
public class DesynchronizedAnchorException : Exception
public class DesynchronizedAnchorException(TimeSpan anchor, string message) : Exception(message)
{
public TimeSpan Anchor { get; }
public TimeSpan Anchor { get; } = anchor;

public DesynchronizedAnchorException(TimeSpan anchor) : this(anchor, $"Invalid operation performed with desynchronized anchored tempo at {anchor}.") { }
public DesynchronizedAnchorException(TimeSpan anchor, string message) : base(message) => Anchor = anchor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public class OrderedAlternatingEnumerable<T, TKey> : IEnumerable<T> where TKey :
/// <exception cref="ArgumentNullException"/>
public OrderedAlternatingEnumerable(Func<T, TKey> keyGetter, params IEnumerable<T>?[] enumerables)
{
if (keyGetter is null)
throw new ArgumentNullException(nameof(keyGetter));
if (enumerables is null)
throw new ArgumentNullException(nameof(enumerables));
ArgumentNullException.ThrowIfNull(keyGetter);
ArgumentNullException.ThrowIfNull(enumerables);

if (enumerables.Length == 0)
throw new ArgumentException("No enumerables provided.");

Expand All @@ -48,13 +47,15 @@ public OrderedAlternatingEnumerable(Func<T, TKey> keyGetter, params IEnumerable<
/// <summary>
/// Enumerator that yields <typeparamref name="T"/> items from a set of enumerators in order using a <typeparamref name="TKey"/> key
/// </summary>
private class Enumerator : IInitializable, IEnumerator<T>
/// <param name="keyGetter">Method that retrieves the key from an item</param>
/// <param name="enumerators">Enumerators to alternate between</param>
private class Enumerator(Func<T, TKey> keyGetter, params IEnumerator<T>[] enumerators) : IInitializable, IEnumerator<T>
{
private IEnumerator<T>[] Enumerators { get; }
private IEnumerator<T>[] Enumerators { get; } = enumerators.NonNull().ToArray();
/// <summary>
/// Method that retrieves the key from an item
/// </summary>
private Func<T, TKey> KeyGetter { get; }
private Func<T, TKey> KeyGetter { get; } = keyGetter;
/// <inheritdoc/>
public bool Initialized { get; private set; }

Expand All @@ -66,19 +67,8 @@ private class Enumerator : IInitializable, IEnumerator<T>
/// <summary>
/// <see langword="true"/> for indexes where MoveNext previously returned <see langword="false"/>
/// </summary>
readonly bool[] endsReached;
readonly bool[] endsReached = new bool[enumerators.Length];

/// <summary>
/// Creates a new instance of <see cref="OrderedAlternatingEnumerator{T, TKey}"/>.
/// </summary>
/// <param name="keyGetter">Method that retrieves the key from an item</param>
/// <param name="enumerators">Enumerators to alternate between</param>
public Enumerator(Func<T, TKey> keyGetter, params IEnumerator<T>[] enumerators)
{
Enumerators = enumerators.NonNull().ToArray();
KeyGetter = keyGetter;
endsReached = new bool[enumerators.Length];
}
~Enumerator() => Dispose(false);

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class SerialAlternatingEnumerable<T> : IEnumerable<T>
/// <exception cref="ArgumentNullException"/>
public SerialAlternatingEnumerable(params IEnumerable<T>?[] enumerables)
{
if (enumerables is null)
throw new ArgumentNullException(nameof(enumerables));
ArgumentNullException.ThrowIfNull(enumerables);

if (enumerables.Length == 0)
throw new ArgumentException("No enumerables provided.");

Expand All @@ -37,12 +37,15 @@ public SerialAlternatingEnumerable(params IEnumerable<T>?[] enumerables)
/// <summary>
/// Enumerator that yields <typeparamref name="T"/> items by alternating through a set of enumerators
/// </summary>
private class Enumerator : IEnumerator<T?>
/// <param name="enumerators">Enumerators to alternate between</param>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
private class Enumerator(params IEnumerator<T>[] enumerators) : IEnumerator<T?>
{
/// <summary>
/// Enumerators to alternate between
/// </summary>
private IEnumerator<T>[] Enumerators { get; }
private IEnumerator<T>[] Enumerators { get; } = enumerators.NonNull().ToArray();
/// <summary>
/// Position of the next enumerator to pull from
/// </summary>
Expand All @@ -55,14 +58,6 @@ private class Enumerator : IEnumerator<T?>
/// <inheritdoc/>
object? IEnumerator.Current => Current;

/// <summary>
/// Creates an instance of <see cref="SerialAlternatingEnumerator{T}"/>
/// </summary>
/// <param name="enumerators">Enumerators to alternate between</param>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
public Enumerator(params IEnumerator<T>[] enumerators) => Enumerators = enumerators.NonNull().ToArray();

/// <inheritdoc/>
public void Dispose()
{
Expand Down
5 changes: 2 additions & 3 deletions ChartTools/TrackObjects/TrackObjectBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace ChartTools;

public abstract class TrackObjectBase : ITrackObject
public abstract class TrackObjectBase(uint position) : ITrackObject
{
public virtual uint Position { get; set; }
public virtual uint Position { get; set; } = position;

public TrackObjectBase() : this(0) { }
public TrackObjectBase(uint position) => Position = position;
}

0 comments on commit f71cf92

Please sign in to comment.