Skip to content

Commit

Permalink
Merge pull request #5 from mackysoft/feature/extend-history-builder
Browse files Browse the repository at this point in the history
Extend `ISceneHistoryBuilder`
  • Loading branch information
mackysoft committed Oct 30, 2023
2 parents 496db5d + 78102cf commit bae4d56
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
public interface ISceneHistoryBuilder
{
int Count { get; }
SceneHistoryEntry this[int index] { get; set; }

ISceneHistoryBuilder Add (SceneHistoryEntry entry);
ISceneHistoryBuilder Insert(int index, SceneHistoryEntry entry);
ISceneHistoryBuilder RemoveAt (int index);
ISceneHistoryBuilder RemoveAllExceptCurrent ();
void Build ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ public abstract class SceneHistoryBuilderBase : ISceneHistoryBuilder

public int Count => m_History.Count;

public SceneHistoryEntry this[int index]
{
get => m_History[index];
set {
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if ((index == 0) || (index < 0) || (index >= m_History.Count))
{
throw new ArgumentOutOfRangeException(nameof(index));
}
m_History[index] = value;
}
}

protected SceneHistoryBuilderBase ()
{
m_History = new List<SceneHistoryEntry>();
Expand All @@ -31,6 +47,20 @@ public ISceneHistoryBuilder Add (SceneHistoryEntry entry)
return this;
}

public ISceneHistoryBuilder Insert(int index, SceneHistoryEntry entry)
{
if (entry == null)
{
throw new ArgumentNullException(nameof(entry));
}
if ((index == 0) || (index < 0) || (index > m_History.Count))
{
throw new ArgumentOutOfRangeException(nameof(index));
}
m_History.Insert(index, entry);
return this;
}

public ISceneHistoryBuilder RemoveAt (int index)
{
if ((index == 0) || (index < 0) || (index >= m_History.Count))
Expand Down

0 comments on commit bae4d56

Please sign in to comment.