/// <summary> Sets the next node in the queue, and returns it.</summary> //@ requires next != this ; //@ assignable m_Next; //@ ensures m_Next==next && \result==next; public virtual QueueXmlNode next(QueueXmlNode next) { return m_Next = next; } //@ nowarn Invariant; // Because it stupidly checks the Queue invariant!
/// <summary> Appends an object to the back of the queue. /// /// </summary> /// <param name="Item">the object to be appended /// </param> /// <returns> the object appended /// </returns> //@ requires Item != null; //@ assignable m_Head, m_Tail, m_Tail.m_Next, m_Head.m_Next, m_Size; //@ ensures m_Head != null; //@ ensures m_Tail != \old(m_Tail); //@ ensures m_Size == \old(m_Size) + 1; //@ ensures \old(m_Size) == 0 ==> m_Head == m_Tail; //@ ensures \old(m_Size) != 0 ==> m_Head == \old(m_Head); //@ ensures m_Tail.contents() == \old(Item); //@ ensures \result == Item; //UPGRADE_NOTE: Synchronized keyword was removed from method 'push'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'" public virtual System.Object push(System.Object Item) { lock (this) { QueueXmlNode newXmlNode = new QueueXmlNode(this, Item); if (m_Head == null) { m_Head = m_Tail = newXmlNode; } else { m_Tail = m_Tail.next(newXmlNode); } m_Size++; return Item; } }
/// <summary> Pops an object from the front of the queue. /// /// </summary> /// <returns> the object at the front of the queue /// </returns> /// <exception cref="RuntimeException">if the queue is empty /// </exception> //@ assignable m_Head, m_Tail, m_Size; //@ ensures m_Size == \old(m_Size) - 1; //@ ensures m_Head == \old(m_Head.m_Next); //@ ensures m_Head != null ==> m_Tail == \old(m_Tail); //@ ensures \result == \old(m_Head.m_Contents); //@ signals (RuntimeException) \old(m_Head) == null; //UPGRADE_NOTE: Synchronized keyword was removed from method 'pop'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'" public virtual System.Object pop() { lock (this) { if (m_Head == null) { throw new System.SystemException("Queue is empty"); } System.Object retval = m_Head.contents(); m_Size--; m_Head = m_Head.next(); // Here we need to either tell ESC/Java some facts about // the contents of the list after popping off the head, // or turn off the 'invariant' warnings. // //@ assume m_Size == 0 <==> m_Head == null; //@ assume m_Size == 1 <==> m_Head == m_Tail; if (m_Head == null) { m_Tail = null; } return retval; } }
//@ public invariant m_Head == null <==> m_Tail == null; //@public invariant m_Tail != null ==> m_Tail.m_Next == null; //@ public invariant m_Size >= 0; //@ public invariant m_Size == 0 <==> m_Head == null; //@ public invariant m_Size == 1 <==> m_Head != null && m_Head == m_Tail; //@ public invariant m_Size > 1 ==> m_Head != m_Tail; //@ public invariant m_Size > 1 <== m_Head != m_Tail; /// <summary> Removes all objects from the queue m_Tail.m_Next.</summary> //@ assignable m_Size, m_Head, m_Tail; //@ ensures m_Size == 0; //@ ensures m_Head == null; //@ ensures m_Tail == null; //UPGRADE_NOTE: Synchronized keyword was removed from method 'removeAllElements'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'" public void removeAllElements() { lock (this) { m_Size = 0; m_Head = null; m_Tail = null; } }