~matteo-collina/+junk/todo

« back to all changes in this revision

Viewing changes to Todo/OrderedCollection.cs

  • Committer: Matteo Collina
  • Date: 2008-04-14 17:43:54 UTC
  • Revision ID: matteo.collina@gmail.com-20080414174354-ghe1h22412p0f9fs
added OrderedCollection and its test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections;
 
4
using System.Collections.Generic;
 
5
 
 
6
namespace Todo
 
7
{       
 
8
        public class OrderedCollection<T> : ICollection<T> where T : System.IComparable<T>
 
9
        {
 
10
                private List<T> _collection = new List<T>();
 
11
                
 
12
                public OrderedCollection()
 
13
                {
 
14
                }
 
15
                
 
16
                public void Add (T item)
 
17
                {
 
18
                        _collection.Add(item);
 
19
                        _collection.Sort();
 
20
                }
 
21
                
 
22
                
 
23
                public void Clear ()
 
24
                {
 
25
                        _collection.Clear();
 
26
                }
 
27
                
 
28
                public bool Contains (T item)
 
29
                {
 
30
                        return _collection.Contains(item);
 
31
                }
 
32
                
 
33
                
 
34
                public void CopyTo (T[] array, int arrayIndex)
 
35
                {
 
36
                        _collection.CopyTo(array, arrayIndex);
 
37
                }
 
38
                
 
39
                public bool Remove (T item)
 
40
                {
 
41
                        bool result = _collection.Remove(item);
 
42
                        return result;
 
43
                }
 
44
                
 
45
                public int Count { 
 
46
                        get
 
47
                        {
 
48
                                return _collection.Count;
 
49
                        }
 
50
                }
 
51
                
 
52
                public bool IsReadOnly 
 
53
                { 
 
54
                        get
 
55
                        {
 
56
                                return false;
 
57
                        }
 
58
                } 
 
59
                                
 
60
                public IEnumerator<T> GetEnumerator ()
 
61
                {
 
62
                        return _collection.GetEnumerator();
 
63
                }
 
64
                
 
65
                IEnumerator IEnumerable.GetEnumerator ()
 
66
                {
 
67
                        return GetEnumerator();
 
68
                }
 
69
        }
 
70
}