Ejemplo n.º 1
0
        public ShelteredAnimal DequeueCat()
        {
            ShelteredAnimal animal = DequeueAnimal(_cats);

            _animals.Remove(animal);
            return(animal);
        }
Ejemplo n.º 2
0
        public ShelteredAnimal DequeueDog()
        {
            ShelteredAnimal animal = DequeueAnimal(_dogs);

            _animals.Remove(animal);
            return(animal);
        }
Ejemplo n.º 3
0
        private ShelteredAnimal DequeueAnimal(LinkedList <ShelteredAnimal> animals)
        {
            ValidateList <ShelteredAnimal>(animals);
            ShelteredAnimal animal = animals.Last.Value;

            animals.RemoveLast();
            return(animal);
        }
Ejemplo n.º 4
0
        public ShelteredAnimal DequeueAny()
        {
            ShelteredAnimal animal = DequeueAnimal(_animals);

            _dogs.Remove(animal);
            _cats.Remove(animal);
            return(animal);
        }
        public void Enqueue(ShelteredAnimal animal)
        {
            animal.Added = DateTime.Now;
            Type type = animal.GetType();

            if (type == typeof(Dog))
            {
                _dogs.AddLast((Dog)animal);
            }

            if (type == typeof(Cat))
            {
                _cats.AddLast((Cat)animal);
            }
        }
        public ShelteredAnimal DequeueAny()
        {
            if (_dogs.Count == 0)
            {
                return(DequeueCat());
            }

            if (_cats.Count == 0)
            {
                return(DequeueDog());
            }

            ShelteredAnimal dog = _dogs.First.Value;
            ShelteredAnimal cat = _cats.First.Value;

            if (dog.IsOlderThan(cat))
            {
                return(DequeueDog());
            }

            return(DequeueCat());
        }
Ejemplo n.º 7
0
 public bool IsOlderThan(ShelteredAnimal animal)
 {
     return(Added < animal.Added);
 }