using com.knapp.KCC2017.entities; using com.knapp.KCC2017.util; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace com.knapp.KCC2017.data { public class Container { /// /// Container code (it's unique name) /// public string Code { get; private set; } /// /// Container type /// public ContainerType ContainerType { get; private set; } private readonly ContainerSlot[] slots; /// /// constructor /// /// code of this container /// type of this container public Container( string code, ContainerType containerType ) { this.Code = code; this.ContainerType = containerType; slots = new ContainerSlot[ ContainerType.NumberOfSlots ]; for( int i = 0; i < slots.Length; ++i ) { slots[ i ] = new ContainerSlot( this, i ); } } /// /// Is container empty (all slots are empty) /// /// true container is empty, false in any other case public bool IsEmpy() { return ! slots.Any( s => !s.IsEmpty() ); } /// /// Return a collection with all slots /// /// public ReadOnlyCollection GetSlots() { return new ReadOnlyCollection( slots ); } /// /// Get a list with all empty slots in the container /// /// a list with empty slots, an empty list if non are empty public List GetEmptySlots() { return slots.Where( s => s.IsEmpty() ).ToList(); } /// /// Stringify this /// /// a human readable string representing this instance public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append( "Container[ code= " ).Append( Code ); sb.Append( ", type = " ).Append( ContainerType ); sb.Append( "] {" ); foreach( var slot in slots ) { if( slot.IsEmpty() ) { sb.Append(", "); } else { sb.Append( slot.Product.Code ).Append( ", #" ).Append(slot.Quantity).Append(","); } } return sb.ToString(); } } }