|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Model
|
|
|
|
|
{
|
|
|
|
@ -9,98 +10,111 @@ namespace Model
|
|
|
|
|
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
|
|
|
|
|
{
|
|
|
|
|
#region Attributes
|
|
|
|
|
private List<Recipe> _recipes;
|
|
|
|
|
private List<Recipe> recipes;
|
|
|
|
|
private string? _description;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public string? Description
|
|
|
|
|
{
|
|
|
|
|
get => _description;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
|
|
|
_description = "No description.";
|
|
|
|
|
else
|
|
|
|
|
_description = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IList Prperties
|
|
|
|
|
public int Count => _recipes.Count;
|
|
|
|
|
public int Count => recipes.Count;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
public RecipeCollection(string description = "No Description.")
|
|
|
|
|
public RecipeCollection(string? description = null, params Recipe[] recipes)
|
|
|
|
|
{
|
|
|
|
|
_recipes = new List<Recipe>();
|
|
|
|
|
this.recipes = new List<Recipe>(recipes);
|
|
|
|
|
Description = description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RecipeCollection(params Recipe[] recipes)
|
|
|
|
|
{
|
|
|
|
|
_recipes = new List<Recipe>(recipes);
|
|
|
|
|
Description = "No Description.";
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
#region IList Methods
|
|
|
|
|
public int IndexOf(Recipe item)
|
|
|
|
|
{
|
|
|
|
|
return _recipes.IndexOf(item);
|
|
|
|
|
return recipes.IndexOf(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Insert(int index, Recipe item)
|
|
|
|
|
{
|
|
|
|
|
_recipes.Insert(index, item);
|
|
|
|
|
recipes.Insert(index, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
|
{
|
|
|
|
|
_recipes.RemoveAt(index);
|
|
|
|
|
recipes.RemoveAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(Recipe item)
|
|
|
|
|
{
|
|
|
|
|
_recipes.Add(item);
|
|
|
|
|
recipes.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
_recipes.Clear();
|
|
|
|
|
recipes.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Contains(Recipe item)
|
|
|
|
|
{
|
|
|
|
|
return _recipes.Contains(item);
|
|
|
|
|
return recipes.Contains(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyTo(Recipe[] array, int arrayIndex)
|
|
|
|
|
{
|
|
|
|
|
_recipes.CopyTo(array, arrayIndex);
|
|
|
|
|
recipes.CopyTo(array, arrayIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Remove(Recipe item)
|
|
|
|
|
{
|
|
|
|
|
return _recipes.Remove(item);
|
|
|
|
|
return recipes.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<Recipe> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
|
return recipes.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
|
return recipes.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEquatable Mathods
|
|
|
|
|
public bool Equals(RecipeCollection? other)
|
|
|
|
|
{
|
|
|
|
|
if (other == null) return false;
|
|
|
|
|
if (other == this) return true;
|
|
|
|
|
return Description.Equals(other.Description) && _recipes.Equals(other._recipes);
|
|
|
|
|
return Description.Equals(other.Description) && recipes.Equals(other.recipes);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return Description.GetHashCode() + _recipes.GetHashCode();
|
|
|
|
|
return Description.GetHashCode() + recipes.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
|
|
|
|
|
foreach (Recipe r in recipes)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("\t - {0}\n", r.ToString());
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|