public override object Clone() { lock (stack) { return(Stack.Synchronized((Stack)stack.Clone())); } }
public override Object Clone() { lock (_root) { return(new SyncStack((Stack)_s.Clone())); } }
public void TestCloneBasic() { Stack stk; Stack stkClone; A a1; A a2; //[]vanila stk = new Stack(); for (int i = 0; i < 100; i++) stk.Push(i); stkClone = (Stack)stk.Clone(); Assert.Equal(100, stkClone.Count); for (int i = 0; i < 100; i++) { Assert.True(stkClone.Contains(i)); } //[]making sure that this is shallow stk = new Stack(); stk.Push(new A(10)); stkClone = (Stack)stk.Clone(); Assert.Equal(1, stkClone.Count); a1 = (A)stk.Pop(); a1.I = 50; Assert.Equal(1, stkClone.Count); a2 = (A)stkClone.Pop(); Assert.Equal(50, a2.I); //[]vanila with synchronized stack stk = new Stack(); for (int i = 0; i < 100; i++) stk.Push(i); stkClone = (Stack)(Stack.Synchronized(stk)).Clone(); Assert.Equal(100, stkClone.Count); Assert.True(stkClone.IsSynchronized); for (int i = 0; i < 100; i++) { Assert.True(stkClone.Contains(i)); } }
static public int Clone(IntPtr l) { try { System.Collections.Stack self = (System.Collections.Stack)checkSelf(l); var ret = self.Clone(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static int Clone(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); System.Collections.Stack obj = (System.Collections.Stack)ToLua.CheckObject(L, 1, typeof(System.Collections.Stack)); object o = obj.Clone(); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// Implement the ICloneable interface. public override Object Clone() { return(new SynchronizedStack((Stack)(stack.Clone()))); }
public double totalDue() /* pre: Have list of delegates, possibly empty. * post: Calculate and return total amount outstanding for all delegates. Original list must retain original * ordering. */ { double Total = 0; if (Delegates.Count == 0) return 0; reverseList (); Stack remover = new Stack (); while (Delegates.Count != 0) { Delegate add = (Delegate)Delegates.Pop(); Total += add.getDue (); remover.Push (add); } Delegates = (Stack)remover.Clone(); return Total; }
// OPTIONAL TASKS public bool deleteDelegate(int D) /* pre: Have list of delegates, possibly empty. Have identifier of delegate to remove * post: Remove the specified delegate from the list of delegates and return true. If delegate is not in the list, * return false. If the removed delegate is also a presenter, display an appropriate warning message. * NOTE: The list of delegates must retain the original ordering of the remaining delegates after processing * has been completed. */ { int x = Delegates.Count; if (x == 0) return false; reverseList (); Stack remover = new Stack (); while (Delegates.Count != 0) { Delegate add = (Delegate)Delegates.Pop(); if (add.DelID == D) { if (add.Presenter) Console.WriteLine ("Deleting a Presenter"); } else { remover.Push (add); } } Delegates = (Stack)remover.Clone(); if(remover.Count < x) return true; return false; }
public void makePayment(int D, double Amnt) /* pre: Have list of delegates, possibly empty. Have delegate identifier and amount paid. * post: Modify the relevant property for the given delegate. Retain the original ordering of delegates in the list. */ { if (Delegates.Count == 0) return; Stack remover = new Stack (); while (Delegates.Count != 0) { Delegate add = (Delegate)Delegates.Pop(); if (add.DelID == D) { add.processPayment (Amnt); } remover.Push (add); } Delegates = (Stack)remover.Clone(); }
} // MatchOptionalArgumentList // Return a new Stack with the same entries as the given stack. // // This is used when passing our "loops" or "withs" stack to // the code generator. If we didn't make a clone, then the stack // passed to the code generator would be altered the next time we // push or pop an entry on our stack. // // OPTIMIZATION snewman 8/29/01: it's pretty wasteful to clone the // stack on each use; we should implement a simple cache so as to only // make a new clone after the stack has been changed. private Stack CloneStack(Stack stack) { if (stack.Count == 0) return emptyStack; else return (Stack)(stack.Clone()); } // CloneStack
private void DumpStack(Stack stack, string name) { Stack temp = (Stack)stack.Clone(); string list = null; if( temp.Count == 0 ) { list = "[Empty]"; } else { while( temp.Count > 0 ) { object item = temp.Pop(); string text = null; if( item is Array ) { foreach( object obj in (Array)item ) { if( text != null ) text += ", "; text += "{" + obj.ToString() + "}"; } text = "[" + text + "]"; } else { text = "{" + item.ToString() + "}"; } list = text + " " + list; } } Debug.WriteLine(name + ": " + list); }