|
|
@ -10,10 +10,9 @@ namespace Model
|
|
|
|
/// Define a collection of <see cref="Recipe"/>.
|
|
|
|
/// Define a collection of <see cref="Recipe"/>.
|
|
|
|
/// <br/>This class implement <see cref="IList"/> and <see cref="IEquatable{T}"/>.
|
|
|
|
/// <br/>This class implement <see cref="IList"/> and <see cref="IEquatable{T}"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
|
|
|
|
public class RecipeCollection : List<Recipe>, IEquatable<RecipeCollection>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
#region Attributes
|
|
|
|
private readonly List<Recipe> _recipes;
|
|
|
|
|
|
|
|
private string _description = "";
|
|
|
|
private string _description = "";
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
@ -33,12 +32,6 @@ namespace Model
|
|
|
|
_description = value;
|
|
|
|
_description = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region IList Prperties
|
|
|
|
|
|
|
|
public int Count => _recipes.Count;
|
|
|
|
|
|
|
|
public bool IsReadOnly => false;
|
|
|
|
|
|
|
|
public Recipe this[int index] { get => _recipes[index]; set => _recipes[index] = value; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
#region Constructors
|
|
|
@ -48,8 +41,8 @@ namespace Model
|
|
|
|
/// <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, params Recipe[] recipes)
|
|
|
|
public RecipeCollection(string description, params Recipe[] recipes)
|
|
|
|
|
|
|
|
: base(recipes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_recipes = new List<Recipe>(recipes);
|
|
|
|
|
|
|
|
Description = description;
|
|
|
|
Description = description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
@ -63,7 +56,7 @@ 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 = this.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,66 +70,14 @@ namespace Model
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new RecipeCollection(
|
|
|
|
return new RecipeCollection(
|
|
|
|
description: $"Results of the research: {str}",
|
|
|
|
description: $"Results of the research: {str}",
|
|
|
|
recipes: _recipes.FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray());
|
|
|
|
recipes: this.FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region IList Methods
|
|
|
|
|
|
|
|
public int IndexOf(Recipe item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _recipes.IndexOf(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Insert(int index, Recipe item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_recipes.Insert(index, item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_recipes.RemoveAt(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Add(Recipe item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_recipes.Add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_recipes.Clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Contains(Recipe item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _recipes.Contains(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CopyTo(Recipe[] array, int arrayIndex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_recipes.CopyTo(array, arrayIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool Remove(Recipe item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _recipes.Remove(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator<Recipe> GetEnumerator()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _recipes.GetEnumerator();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#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 this.Description.Equals(other.Description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
public override bool Equals(object? obj)
|
|
|
@ -148,13 +89,13 @@ namespace Model
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _recipes.GetHashCode();
|
|
|
|
return Description.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 this)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sb.AppendFormat("\t - {0}\n", r.ToString());
|
|
|
|
sb.AppendFormat("\t - {0}\n", r.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|