using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
namespace Model
{
///
/// Define a collection of .
///
This class is derived from
/// and implement and .
///
public class RecipeCollection : ObservableCollection, IEquatable, ICloneable
{
#region Attributes
private string _description = "";
#endregion
#region Properties
///
/// A short description of what this collection contain.
/// Set to "No description." when the value passed is null, empty or contain white spaces.
///
public string Description
{
get => _description;
set
{
if (string.IsNullOrWhiteSpace(value))
_description = "No description.";
else
_description = value;
OnPropertyChanged(new PropertyChangedEventArgs("Description"));
}
}
#endregion
#region Constructors
///
/// Construct a new collection of recipes.
///
/// A short description of what this list will contain.
/// Recipes to add in this new collection.
public RecipeCollection(string description, ICollection recipes)
: base(recipes)
{
Description = description;
}
///
public RecipeCollection(string description)
: base()
{
}
#endregion
#region Methods
public virtual bool Equals(RecipeCollection? other)
{
if (other == null) return false;
if (other == this) return true;
return this.Description.Equals(other.Description);
}
public override bool Equals(object? obj)
{
var item = obj as RecipeCollection;
if (item == null) return false;
return Equals(obj);
}
public override int GetHashCode()
{
return Description.GetHashCode();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
foreach (Recipe r in this)
{
sb.AppendFormat("\t - {0}\n", r.ToString());
}
return sb.ToString();
}
public object Clone()
{
return new RecipeCollection(
description: this.Description,
recipes: this.ToArray());
}
#endregion
}
}