You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.0 KiB
122 lines
3.0 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text;
|
|
|
|
namespace Model
|
|
{
|
|
|
|
public class RecipeCollection : IList<Recipe>, IEquatable<RecipeCollection>
|
|
{
|
|
#region Attributes
|
|
private List<Recipe> recipes;
|
|
private string? _description;
|
|
#endregion
|
|
|
|
#region Properties
|
|
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 bool IsReadOnly => false;
|
|
public Recipe this[int index] { get => recipes[index]; set => recipes[index] = value; }
|
|
#endregion
|
|
#endregion
|
|
|
|
#region Constructors
|
|
public RecipeCollection(string? description = null, params Recipe[] recipes)
|
|
{
|
|
this.recipes = new List<Recipe>(recipes);
|
|
Description = description;
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
#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 bool Equals(RecipeCollection? other)
|
|
{
|
|
if (other == null) return false;
|
|
if (other == this) return true;
|
|
return Description.Equals(other.Description) && recipes.Equals(other.recipes);
|
|
}
|
|
|
|
public override int 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
|
|
}
|
|
}
|