Exemplo n.º 1
0
        private ILocker GetAvailableLocker(Size size)
        {
            ILocker result = null;

            if (size == Size.Small && SmallLockers.Count > 0)
            {
                result = SmallLockers.Dequeue();
            }

            if (result == null && size == Size.Medium && MediumLockers.Count > 0)
            {
                result = MediumLockers.Dequeue();
            }

            if (result == null && size == Size.Large && LargeLockers.Count > 0)
            {
                result = LargeLockers.Dequeue();
            }

            if (result == null && size == Size.XLarge && XLargeLockers.Count > 0)
            {
                result = XLargeLockers.Dequeue();
            }

            if (result == null)
            {
                throw new Exception("All lockers are full");
            }

            return(result);
        }
Exemplo n.º 2
0
        public void AddLocker(ILocker locker)
        {
            switch (locker.Size)
            {
            case Size.Small:
                SmallLockers.Enqueue((SmallLocker)locker);
                break;

            case Size.Medium:
                MediumLockers.Enqueue((MediumLocker)locker);
                break;

            case Size.Large:
                LargeLockers.Enqueue((LargeLocker)locker);
                break;

            case Size.XLarge:
                XLargeLockers.Enqueue((XLargeLocker)locker);
                break;
            }
        }