Example #1
0
        public static void Main()
        {
            var names = new ArrayList <string>
            {
                "Hoover",
                "Roosevelt",
                "Truman",
                "Eisenhower",
                "Kennedy"
            };

            // Print list:
            Console.WriteLine(names);

            // Print item 1 ("Roosevelt") in the list:
            Console.WriteLine(names[1]);

            // Create a list view comprising post-WW2 presidents:
            var postWWII = names.View(2, 3);

            // Print item 2 ("Kennedy") in the view:
            Console.WriteLine(postWWII[2]);

            // Enumerate and print the list view in reverse chronological order:
            foreach (var name in postWWII.Backwards())
            {
                Console.WriteLine(name);
            }
        }
Example #2
0
		public void ChildrenContainsTest()
		{
			var l = new ArrayList<double> {0, 1, 2, 3, 4, 5};
			IList<double> v1 = l.View(1, 3);
			Log.Info(v1.Display());
			v1.Add(4.5);
			Log.Info(l.Display());
		}
Example #3
0
    public static void Main()
    {
        IList <char> lst = new ArrayList <char>();

        lst.AddAll(new char[] { 'a', 'b', 'c', 'd' });
        IList <char> v1 = lst.View(1, 1);

        Console.WriteLine("v1 = {0}", v1);
        InsertBeforeFirst(v1, '<', 'b');
        InsertAfterFirst(v1, '>', 'b');
        Console.WriteLine("v1 = {0}", v1);

        if (SequencePredecessor(v1, 'b', out char x))
        {
            Console.WriteLine("Predecessor of b is " + x);
        }

        if (SequenceSuccessor(v1, 'b', out x))
        {
            Console.WriteLine("Successor of b is " + x);
        }

        if (!SequencePredecessor(v1, 'c', out _))
        {
            Console.WriteLine("c has no predecessor");
        }

        if (!SequenceSuccessor(v1, 'a', out _))
        {
            Console.WriteLine("a has no successor");
        }

        IList <char> lst2 = new ArrayList <char>();

        lst2.AddAll(new char[] { 'a', 'b', 'c', 'A', 'a', 'd', 'a' });

        foreach (var i in IndexesOf(lst2, 'a'))
        {
            Console.Write("{0} ", i);
        }

        Console.WriteLine();

        foreach (var i in ReverseIndexesOf(lst2, 'a'))
        {
            Console.Write("{0} ", i);
        }

        Console.WriteLine();
        Console.WriteLine(lst2);
        IList <char> view = lst2.View(2, 0);

        InsertAtView(lst2, view, 'y');
        Console.WriteLine(lst2);
        InsertIntoView(view, 'x');
        Console.WriteLine(lst2);
    }
Example #4
0
 public static void Main(String[] args) {
   IList<String> names = new ArrayList<String>();
   names.AddAll(new String[] { "Hoover", "Roosevelt", 
                               "Truman", "Eisenhower", "Kennedy" });
   // Print list:
   Console.WriteLine(names);
   // Print item 1 ("Roosevelt") in the list:
   Console.WriteLine(names[1]);
   // Create a list view comprising post-WW2 presidents:
   IList<String> postWWII = names.View(2, 3);
   // Print item 2 ("Kennedy") in the view:
   Console.WriteLine(postWWII[2]);
   // Enumerate and print the list view in reverse chronological order:
   foreach (String name in postWWII.Backwards()) 
     Console.WriteLine(name);
 }
Example #5
0
 public static void Main(String[] args) {
   IList<int> list1 = new ArrayList<int>();
   list1.AddAll(new int[] { 2, 5, 7, 11, 37 });
   IList<int> list2 = new GuardedList<int>(list1);
   IList<int> 
     gv = new GuardedList<int>(list1.View(1,2)),
     vg = list2.View(1,2);
   IList<int> 
     gvu = gv.Underlying, 
     vgu = vg.Underlying;
   Console.WriteLine(gvu);  // Legal 
   Console.WriteLine(vgu);  // Legal 
   // gv.Slide(+1);         // Illegal: guarded view cannot be slid
   vg.Slide(+1);            // Legal: view of guarded can be slid
   // gvu[1] = 9;           // Illegal: list is guarded
   // vgu[1] = 9;           // Illegal: list is guarded
 }
Example #6
0
    public static void Main()
    {
        IList <int> list1 = new ArrayList <int> {
            2, 5, 7, 11, 37
        };
        IList <int> gv  = new GuardedList <int>(list1.View(1, 2));
        IList <int> gvu = gv.Underlying;

        IList <int> list2 = new GuardedList <int>(list1);
        IList <int> vg    = list2.View(1, 2);
        IList <int> vgu   = vg.Underlying;

        Console.WriteLine(gvu);  // Legal
        Console.WriteLine(vgu);  // Legal
                                 // gv.Slide(+1);         // Illegal: guarded view cannot be slid
        vg.Slide(+1);            // Legal: view of guarded can be slid
                                 // gvu[1] = 9;           // Illegal: list is guarded
                                 // vgu[1] = 9;           // Illegal: list is guarded
    }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="start"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public IList <T> View(int start, int count)
 {
     return(new WrappedArray <T> ((ArrayList <T>)innerlist.View(start, count), underlying ?? this));
 }
Example #8
0
 public void Reverse()
 {
     list.Add(4); list.Add(56); list.Add(8);
     listen();
     list.Reverse();
     seen.Check(new CollectionEvent <int>[] {
         new CollectionEvent <int>(EventType.Changed, new EventArgs(), guarded)
     });
     list.View(1, 0).Reverse();
     seen.Check(new CollectionEvent <int>[] { });
 }