Clone() public method

public Clone ( ) : Object
return Object
コード例 #1
0
            // ICloneable

            public override object Clone()
            {
                lock (host.SyncRoot)
                {
                    return(host.Clone() as SortedList);
                }
            }
コード例 #2
0
ファイル: SortedList.cs プロジェクト: treesportrait/corefx
 public override Object Clone()
 {
     lock (_root)
     {
         return(_list.Clone());
     }
 }
コード例 #3
0
 static public int Clone(IntPtr l)
 {
     try {
         System.Collections.SortedList self = (System.Collections.SortedList)checkSelf(l);
         var ret = self.Clone();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #4
0
ファイル: SortedList.cs プロジェクト: ForNeVeR/pnet
 // Implement the ICloneable interface.
 public override Object Clone()
 {
     return(new SynchronizedSortedList
                ((SortedList)(list.Clone())));
 }
コード例 #5
0
ファイル: SortedListTest.cs プロジェクト: ItsVeryWindy/mono
		public void TestClone ()
		{
			{
				SortedList sl1 = new SortedList (10);
				for (int i = 0; i <= 50; i++)
					sl1.Add ("kala " + i, i);
				SortedList sl2 = (SortedList) sl1.Clone ();
				for (int i = 0; i <= 50; i++)
					Assert.AreEqual (sl1 ["kala " + i], sl2 ["kala " + i], "#A:" + i);
			}
			{
				char [] d10 = { 'a', 'b' };
				char [] d11 = { 'a', 'c' };
				char [] d12 = { 'b', 'c' };
				//char[][] d1 = {d10, d11, d12};
				SortedList sl1 = new SortedList ();
				sl1.Add ("d1", d10);
				sl1.Add ("d2", d11);
				sl1.Add ("d3", d12);
				SortedList sl2 = (SortedList) sl1.Clone ();
				Assert.AreEqual (sl1 ["d1"], sl2 ["d1"], "#B1");
				Assert.AreEqual (sl1 ["d2"], sl2 ["d2"], "#B2");
				Assert.AreEqual (sl1 ["d3"], sl2 ["d3"], "#B3");
				((char []) sl1 ["d1"]) [0] = 'z';
				Assert.AreEqual (sl1 ["d1"], sl2 ["d1"], "#B4");
			}
		}
コード例 #6
0
ファイル: SortedListTest.cs プロジェクト: ItsVeryWindy/mono
		public void IComparer_Null_Clone ()
		{
			SortedList sl = new SortedList ((IComparer) null);
			sl.Add (new object (), new object ());
			SortedList clone = (SortedList) sl.Clone ();
		}
コード例 #7
0
ファイル: SortedListTest.cs プロジェクト: ItsVeryWindy/mono
		public void IComparer_Clone ()
		{
			SortedList sl = new SortedList (new SortedListComparer ());
			sl.Add (new object (), new object ());
			SortedList clone = (SortedList) sl.Clone ();
		}
コード例 #8
0
ファイル: CloneTests.cs プロジェクト: johnhhm/corefx
        public void TestCloneBasic()
        {
            SortedList hsh1;
            SortedList hsh2;

            string strKey;
            string strValue;

            // Vanila test case - Clone should exactly replicate a collection to another object reference
            //afterwards these 2 should not hold the same object references
            hsh1 = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                strKey = "Key_" + i;
                strValue = "String_" + i;
                hsh1.Add(strKey, strValue);
            }

            hsh2 = (SortedList)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                Assert.Equal(strValue, (string)hsh2["Key_" + i]);
            }

            //now we remove an object from the original list
            hsh1.Remove("Key_9");
            Assert.Null(hsh1["Key_9"]);

            Assert.Equal("String_9", (string)hsh2["Key_9"]);

            //now we try other test cases
            //are all the 'other' properties of the SortedList the same?
            hsh1 = new SortedList(1000);
            hsh2 = (SortedList)hsh1.Clone();

            Assert.Equal(hsh1.Count, hsh2.Count);
            Assert.Equal(hsh1.IsReadOnly, hsh2.IsReadOnly);
            Assert.Equal(hsh1.IsSynchronized, hsh2.IsSynchronized);

            //Clone is a shallow copy, so the objects of the objets reference should be the same
            hsh1 = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                hsh1.Add(i, new Foo());
            }

            hsh2 = (SortedList)hsh1.Clone();
            for (int i = 0; i < 10; i++)
            {
                strValue = "Hello World";
                Assert.Equal(strValue, ((Foo)hsh2[i]).strValue);
            }

            strValue = "Good Bye";
            ((Foo)hsh1[0]).strValue = strValue;

            Assert.Equal(strValue, ((Foo)hsh1[0]).strValue);

            //da test
            Assert.Equal(strValue, ((Foo)hsh2[0]).strValue);

            //if we change the object, of course, the previous should not happen
            hsh2[0] = new Foo();
            strValue = "Good Bye";
            Assert.Equal(strValue, ((Foo)hsh1[0]).strValue);

            strValue = "Hello World";
            Assert.Equal(strValue, ((Foo)hsh2[0]).strValue);
        }
コード例 #9
0
	public void TestClone() {
		{
			SortedList sl1 = new SortedList(10);
			for (int i = 0; i <= 50; i++) {sl1.Add("kala "+i,i);}
			SortedList sl2 = (SortedList)sl1.Clone();
			for (int i = 0; i <= 50; i++) {
				AssertEquals("sl.Clone: copying failed @"+i, sl1["kala "+i], sl2["kala "+i]);
			}
		}
		{
			char[] d10 = {'a', 'b'};
			char[] d11 = {'a', 'c'};
			char[] d12 = {'b', 'c'};
			//char[][] d1 = {d10, d11, d12};
			SortedList sl1 = new SortedList();
			sl1.Add("d1",d10);
			sl1.Add("d2",d11);
			sl1.Add("d3",d12);
			SortedList sl2 = (SortedList)sl1.Clone();
			AssertEquals("sl.Clone: Array not matching", sl1["d1"], sl2["d1"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d2"], sl2["d2"]);
			AssertEquals("sl.Clone: Array not matching", sl1["d3"], sl2["d3"]);
			
			((char[])sl1["d1"])[0] = 'z';
			AssertEquals("s1.Clone: shallow copy", sl1["d1"], sl2["d1"]);
		}
	}
コード例 #10
0
ファイル: bg.cs プロジェクト: rlittletht/bg.incomplete
	/* C R E A T E  I N T E R P O L A T I O N S */
	/*----------------------------------------------------------------------------
		%%Function: CreateInterpolations
		%%Qualified: bg._bg.CreateInterpolations
		%%Contact: rlittle

		when we calculate weighted averages, we'd like to do it by just walking
		the list of readings and figuring out the weightings based on that list.
		it won't be that simple (since there are times when you weight forward
		and other times you weight backwards (e.g. around meals)), but we don't
		want to be in the business of creating interpolations at the same time.

		to that end, let's create the interpolations now.
	----------------------------------------------------------------------------*/
	SortedList SlbgeCreateInterpolations(SortedList slbge)
	{
		SortedList slbgeStats = (SortedList) slbge.Clone(); // new SortedList();

		int i;

		// note that we check against the real count every time since we are
		// adding items.

		// TAKE CARE not to add items before the current item without carefully
		// accounting for it with i
		i = 0;
		while (i < slbgeStats.Count)
			{
			BGE bge = (BGE)slbgeStats.GetByIndex(i);
			BGE bgePrevReading = BgePrevReading(slbgeStats, i);
			BGE bgePrevEntry = BgePrevEntry(slbgeStats, i);

//			if (bge.Date.Month == 6)
//				Debug.WriteLine(String.Format("Interp {0}", bge.ToString()));

			if (bge.Type == BGE.ReadingType.Control)
				{
				i++;
				continue;
				}

//			if (bge.Date.Month == 6 && bge.Date.Day == 30 && bge.Date.Hour > 22)
//				Debug.WriteLine("here!");

			if (bgePrevEntry.Carbs > 0)
				{
				TimeSpan tsCarb = bge.Date.Subtract(bgePrevEntry.Date);

				// if the reading since the carb were > 1.5 hours, we can 
				// assume we didn't capture the spike.  use a guess of 10 bgc rise
				// for each carb.  we will put this spike at 90 minutes postprandial
				// (this is one of many tunable places)

				if (tsCarb.TotalMinutes > 90)
					{
					// we are now saying that the last reading we have is 90 minutes
					// postprandial (the one we are estimating)

					// calculate an estimate as a 30bgc per carb rise
					int nEst = bgePrevReading.Reading + bgePrevEntry.Carbs * 15;// * 30;
					AddInterpolatedBge(slbgeStats, bgePrevEntry.Date.AddMinutes(90.0), nEst, "PostPrandial");

					// now, do we have to estimate that 4 hours post prandial we go back to 
					// what we were pre-meal?
					if (tsCarb.TotalMinutes > 240)
						{
						// no reading for 4 hours past the meal -- assume we go
						// back to the pre-reading
						AddInterpolatedBge(slbgeStats, bgePrevEntry.Date.AddMinutes(240.0), bgePrevReading.Reading, "PostPostPrandial");
						}

					// now we want to just continue and reevaluate starting from the previous
					// entry (essentially recursing)
					i = slbgeStats.IndexOfKey(bgePrevReading.Key);
					if (i < 0)
						throw(new Exception("bgePrevReading doesn't have a key but it must!"));

					continue;
					}
				}

			// if this entry has a reading, let's decide if we can weight the entire period of time from the last entry
			// to now, or if we need to interpolate some entries.
			if (bge.Reading != 0)
				{
				// if we have a previous reading...
				if (bgePrevReading.Reading != 0)//  && bge.Date < dttmStop)
					{
					TimeSpan ts = bge.Date.Subtract(bgePrevReading.Date);

					// if the current reading is higher than the previous, assume its
					// .75 of the delta, for been that way for 1/2 of the time
					if (bge.Reading > bgePrevReading.Reading && ts.TotalMinutes > 10.0) // bgePrevReading.Reading)
						{
						int nEst = bgePrevReading.Reading + ((bge.Reading - bgePrevReading.Reading)* 1) / 2;
						AddInterpolatedBge(slbgeStats, bgePrevReading.Date.AddMinutes(ts.TotalMinutes * 0.75), nEst, "75% for 0.5");

						// now we want to just continue and reevaluate starting from the previous
						// entry (essentially recursing)
						i = slbgeStats.IndexOfKey(bgePrevReading.Key);
						if (i < 0)
							throw(new Exception("bgePrevReading doesn't have a key but it must!"));

						continue;
						}
					if (bge.Reading < bgePrevReading.Reading && ts.TotalMinutes > 20.0) // bgePrevReading.Reading)
						{
						int nEst = bgePrevReading.Reading + ((bge.Reading - bgePrevReading.Reading)* 1) / 2;
						AddInterpolatedBge(slbgeStats, bgePrevReading.Date.AddMinutes(ts.TotalMinutes * 0.50), nEst, "75% for 0.5");

						// now we want to just continue and reevaluate starting from the previous
						// entry (essentially recursing)
						i = slbgeStats.IndexOfKey(bgePrevReading.Key);
						if (i < 0)
							throw(new Exception("bgePrevReading doesn't have a key but it must!"));

						continue;
						}
					}
				}
			i++;
			}
		return slbgeStats;
	}
コード例 #11
0
ファイル: UCResults.cs プロジェクト: clarencemorse/myzilla
        private BulkUpdateResult BulkUpdateBugs(Bug bugValuesToBeChanged)
        {
            BulkUpdateResult result = new BulkUpdateResult();

            // get the selected bugs
            SortedList bugs = new SortedList(dgvResults.SelectedRows.Count);
            //string result = string.Empty;

            DataGridViewSelectedRowCollection selRows = dgvResults.SelectedRows;

            int countSelectedBugs = 0;

            if (selRows != null)
            {
                countSelectedBugs = selRows.Count;

                for (int i = 0; i < selRows.Count; i++)
                {
                    DataGridViewRow row = selRows[i];

                    int bugID = int.Parse(row.Cells[BUG_ID_COL_NAME].Value.ToString());

                    Bug bug = GetBugFromCache(bugID);

                    if (bug != null)
                    {
                        if (Utils.ValidateBugStateTransition(bug, bugValuesToBeChanged))
                            bugs.Add(bugID, bugID);
                    }
                    else {
                        //MessageBox.Show("Bug(s) details not loaded yet!");
                        result.CountBugs = 0;
                        result.Message = "Bug(s) details not loaded yet!";

                        return result;
                    }
                }
            }

            result.CountBugs = bugs.Count;
            result.BugsList = (SortedList)bugs.Clone();

            if (bugs.Count > 0)
            {

                IBugBSI bugInterface = (IBugBSI)BLControllerFactory.GetRegisteredConcreteFactory(_connectionId);
                string strError = null;

                result.Message = bugInterface.UpdateBugs(bugs, bugValuesToBeChanged, out strError);

                if (!string.IsNullOrEmpty(strError))
                {
                    throw new Exception(strError);
                }
                else {
                    if(countSelectedBugs > bugs.Count){
                        result.Message = "Only bugs that have a valid bug status transition have been updated!" + Environment.NewLine + "Bugs updated: " + result.ListOfBugs;
                    }
                }
            }
            else
            {
                result.Message = Messages.NoBugWithValidStatusTransition;
            }

            #if DEBUG
            (Utils.FormContainer as MainForm).wb.DocumentText = MyZilla.BL.Interfaces.Utils.htmlContents;
            #endif

            return result;
        }