|
|
@ -13,8 +13,8 @@ namespace Model
|
|
|
|
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
|
|
|
|
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
#region Attributes
|
|
|
|
private readonly List<Recipe> recipes;
|
|
|
|
private readonly List<Recipe> _recipes;
|
|
|
|
private string? _description;
|
|
|
|
private string _description = "";
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
#region Properties
|
|
|
@ -22,7 +22,7 @@ namespace Model
|
|
|
|
/// A short description of what this collection contain. <br/>
|
|
|
|
/// A short description of what this collection contain. <br/>
|
|
|
|
/// Set to "No description." when the value passed is null, empty or contain white spaces.
|
|
|
|
/// Set to "No description." when the value passed is null, empty or contain white spaces.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public string? Description
|
|
|
|
public string Description
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get => _description;
|
|
|
|
get => _description;
|
|
|
|
set
|
|
|
|
set
|
|
|
@ -35,21 +35,21 @@ namespace Model
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region IList Prperties
|
|
|
|
#region IList Prperties
|
|
|
|
public int Count => recipes.Count;
|
|
|
|
public int Count => _recipes.Count;
|
|
|
|
public bool IsReadOnly => false;
|
|
|
|
public bool IsReadOnly => false;
|
|
|
|
public Recipe this[int index] { get => recipes[index]; set => recipes[index] = value; }
|
|
|
|
public Recipe this[int index] { get => _recipes[index]; set => _recipes[index] = value; }
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
#region Constructors
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Construct a new collection of recipes.
|
|
|
|
/// Construct a new collection of _recipes.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="description">A short description of what this list will contain</param>
|
|
|
|
/// <param name="description">A short description of what this list will contain</param>
|
|
|
|
/// <param name="recipes">Recipes to add in this new collection</param>
|
|
|
|
/// <param name="recipes">Recipes to add in this new collection</param>
|
|
|
|
public RecipeCollection(string? description = null, params Recipe[] recipes)
|
|
|
|
public RecipeCollection(string description, params Recipe[] recipes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.recipes = new List<Recipe>(recipes);
|
|
|
|
_recipes = new List<Recipe>(recipes);
|
|
|
|
Description = description;
|
|
|
|
Description = description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
@ -63,79 +63,80 @@ namespace Model
|
|
|
|
/// <exception cref="ArgumentException"/>
|
|
|
|
/// <exception cref="ArgumentException"/>
|
|
|
|
public Recipe? GetRecipeById(int id)
|
|
|
|
public Recipe? GetRecipeById(int id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Recipe? recipe = recipes.Find(r => r.Id == id);
|
|
|
|
Recipe? recipe = _recipes.Find(r => r.Id == id);
|
|
|
|
if (recipe == null) throw new ArgumentException("No recipes match the given id.");
|
|
|
|
if (recipe == null) throw new ArgumentException("No _recipes match the given id.");
|
|
|
|
return recipe;
|
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region IList Methods
|
|
|
|
#region IList Methods
|
|
|
|
public int IndexOf(Recipe item)
|
|
|
|
public int IndexOf(Recipe item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.IndexOf(item);
|
|
|
|
return _recipes.IndexOf(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Insert(int index, Recipe item)
|
|
|
|
public void Insert(int index, Recipe item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
recipes.Insert(index, item);
|
|
|
|
_recipes.Insert(index, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
recipes.RemoveAt(index);
|
|
|
|
_recipes.RemoveAt(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Add(Recipe item)
|
|
|
|
public void Add(Recipe item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
recipes.Add(item);
|
|
|
|
_recipes.Add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
public void Clear()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
recipes.Clear();
|
|
|
|
_recipes.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Contains(Recipe item)
|
|
|
|
public bool Contains(Recipe item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.Contains(item);
|
|
|
|
return _recipes.Contains(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CopyTo(Recipe[] array, int arrayIndex)
|
|
|
|
public void CopyTo(Recipe[] array, int arrayIndex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
recipes.CopyTo(array, arrayIndex);
|
|
|
|
_recipes.CopyTo(array, arrayIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Remove(Recipe item)
|
|
|
|
public bool Remove(Recipe item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.Remove(item);
|
|
|
|
return _recipes.Remove(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator<Recipe> GetEnumerator()
|
|
|
|
public IEnumerator<Recipe> GetEnumerator()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.GetEnumerator();
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.GetEnumerator();
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool Equals(RecipeCollection? other)
|
|
|
|
public virtual bool Equals(RecipeCollection? other)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (other == null) return false;
|
|
|
|
if (other == null) return false;
|
|
|
|
if (other == this) return true;
|
|
|
|
if (other == this) return true;
|
|
|
|
return Description.Equals(other.Description) && recipes.Equals(other.recipes);
|
|
|
|
return _description.Equals(other.Description) && _recipes.Equals(other._recipes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return recipes.GetHashCode();
|
|
|
|
return _recipes.GetHashCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
|
|
|
|
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
|
|
|
|
foreach (Recipe r in recipes)
|
|
|
|
foreach (Recipe r in _recipes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sb.AppendFormat("\t - {0}\n", r.ToString());
|
|
|
|
sb.AppendFormat("\t - {0}\n", r.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|