예제 #1
0
        public void NotifyObservers()
        {
            if (WaitList.Count > 0)
            {
                Queue <Person2> temp = new Queue <Person2>();
                while (WaitList.Count > 0)
                {
                    Person2 nextInLine = WaitList.Dequeue();
                    if (!nextInLine.HasBook)
                    {
                        nextInLine.Update();
                        RemoveObserver(nextInLine);
                        break;
                    }
                    else
                    {
                        temp.Enqueue(nextInLine);
                    }
                }

                if (temp.Count > 0)
                {
                    while (WaitList.Count > 0)
                    {
                        temp.Enqueue(WaitList.Dequeue());
                    }
                    WaitList = temp;
                }
            }
        }
예제 #2
0
        public void RemoveObserver(object person)
        {
            Queue <Person2> temp = new Queue <Person2>();
            Person2         p    = person as Person2;

            while (WaitList.Count > 0 && p != null)
            {
                Person2 next = WaitList.Dequeue();
                if (next.Equals(p))
                {
                    break;
                }
                else
                {
                    temp.Enqueue(p);
                }
            }

            if (temp.Count > 0)
            {
                while (WaitList.Count > 0)
                {
                    temp.Enqueue(WaitList.Dequeue());
                }
                WaitList = temp;
            }
        }
예제 #3
0
 public void CheckInBook(Person2 p)
 {
     p.ReturnBook();
 }
예제 #4
0
        public void HandleBookRequest(Person2 p, string bookName)
        {
            Book2 b = bookList.Find(bk => bk.Title == bookName);

            p.RequestBook(b);
        }
예제 #5
0
 public void AddUser(Person2 p)
 {
     users.Add(p);
 }
예제 #6
0
        public override bool Equals(object obj)
        {
            Person2 p = obj as Person2;

            return(!(p == null || p.ID != this.ID));
        }