Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 250 lines (210 sloc) 5.109 kb
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
1 using System;
2 using System.Collections.Generic;
118573f @nberardi All tests for columns and families are passing.
nberardi authored
3 using System.Collections.Specialized;
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
4 using System.Linq;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
5
6 namespace FluentCassandra
7 {
118573f @nberardi All tests for columns and families are passing.
nberardi authored
8 internal class FluentColumnList<T> : IList<T>, INotifyCollectionChanged
f784bbc @nberardi making some real progress slowly rebuilding project with new cassandr…
nberardi authored
9 where T : IFluentBaseColumn
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
10 {
11 /// <summary>
12 ///
13 /// </summary>
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
14 /// <param name="parent"></param>
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
15 public FluentColumnList(FluentColumnParent parent)
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
16 {
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
17 Parent = parent;
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
18 Columns = new List<T>();
118573f @nberardi All tests for columns and families are passing.
nberardi authored
19 SupressChangeNotification = false;
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
20 }
21
22 /// <summary>
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
23 ///
24 /// </summary>
25 /// <param name="parent"></param>
26 /// <param name="columns"></param>
27 public FluentColumnList(FluentColumnParent parent, IEnumerable<T> columns)
28 {
29 Parent = parent;
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
30 Columns = new List<T>();
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
31
2c77dfc @nberardi refactored mutation handling to better handle super columns which fix…
nberardi authored
32 SupressChangeNotification = true;
33
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
34 // make sure all columns have the same parent
35 foreach (var col in columns)
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
36 {
2c77dfc @nberardi refactored mutation handling to better handle super columns which fix…
nberardi authored
37 if (col is ILoadable)
38 ((ILoadable)col).BeginLoad();
39
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
40 col.SetParent(parent);
41 Columns.Add(col);
2c77dfc @nberardi refactored mutation handling to better handle super columns which fix…
nberardi authored
42
43 if (col is ILoadable)
44 ((ILoadable)col).EndLoad();
fc725a6 @nberardi fixed issues discovered while running sandbox
nberardi authored
45 }
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
46
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
47 SupressChangeNotification = false;
48 }
49
50 /// <summary>
51 /// Lazy loaded columns.
52 /// </summary>
53 private IList<T> Columns
54 {
6b59025 @nberardi fixed a bug where the family wasn't being set for columns after they …
nberardi authored
55 get;
56 set;
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
57 }
58
59 /// <summary>
118573f @nberardi All tests for columns and families are passing.
nberardi authored
60 /// Makes it so the notification change will not fire.
61 /// </summary>
62 internal bool SupressChangeNotification { get; set; }
63
64 /// <summary>
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
65 ///
66 /// </summary>
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
67 public virtual FluentColumnParent Parent { get; internal set; }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
68
118573f @nberardi All tests for columns and families are passing.
nberardi authored
69 #region IList<T> Members
70
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
71 /// <summary>
72 ///
73 /// </summary>
74 /// <param name="item"></param>
75 /// <returns></returns>
76 public int IndexOf(T item)
77 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
78 return Columns.IndexOf(item);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
79 }
80
81 /// <summary>
82 ///
83 /// </summary>
84 /// <param name="index"></param>
85 /// <param name="item"></param>
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
86 public void Insert(int index, T item)
87 {
88 item.SetParent(Parent);
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
89 Columns.Insert(index, item);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
90
91 OnColumnMutated(MutationType.Changed, item);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
92 }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
93
1b28998 @nberardi added some tests for the remove column functionality
nberardi authored
94 public void Set(int index, T item)
95 {
96 if (index >= Columns.Count)
97 throw new ArgumentOutOfRangeException("index");
98
99 var oldItem = Columns[index];
100 var mutationType = MutationType.Added;
101
102 item.SetParent(Parent);
103 Columns[index] = item;
104
105 if (oldItem != null)
106 {
107 if (oldItem.ColumnName == item.ColumnName)
108 mutationType = MutationType.Changed;
109 else
110 OnColumnMutated(MutationType.Removed, oldItem);
111 }
112
113 OnColumnMutated(mutationType, item);
114 }
115
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
116 /// <summary>
117 ///
118 /// </summary>
119 /// <param name="index"></param>
120 public void RemoveAt(int index)
121 {
118573f @nberardi All tests for columns and families are passing.
nberardi authored
122 var col = this[index];
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
123 Columns.RemoveAt(index);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
124
125 OnColumnMutated(MutationType.Removed, col);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
126 }
127
128 /// <summary>
129 ///
130 /// </summary>
131 /// <param name="index"></param>
132 /// <returns></returns>
133 public T this[int index]
134 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
135 get { return Columns[index]; }
1b28998 @nberardi added some tests for the remove column functionality
nberardi authored
136 set { Set(index, value); }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
137 }
138
139 /// <summary>
140 ///
141 /// </summary>
142 /// <param name="item"></param>
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
143 public void Add(T item)
144 {
145 item.SetParent(Parent);
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
146 Columns.Add(item);
118573f @nberardi All tests for columns and families are passing.
nberardi authored
147
148 OnColumnMutated(MutationType.Added, item);
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
149 }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
150
151 /// <summary>
152 ///
153 /// </summary>
154 public void Clear()
155 {
118573f @nberardi All tests for columns and families are passing.
nberardi authored
156 foreach (var col in this)
157 OnColumnMutated(MutationType.Removed, col);
158
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
159 Columns.Clear();
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
160 }
161
162 /// <summary>
163 ///
164 /// </summary>
165 /// <param name="item"></param>
166 /// <returns></returns>
167 public bool Contains(T item)
168 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
169 return Columns.Contains(item);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
170 }
171
172 /// <summary>
173 ///
174 /// </summary>
175 /// <param name="array"></param>
176 /// <param name="arrayIndex"></param>
177 public void CopyTo(T[] array, int arrayIndex)
178 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
179 Columns.CopyTo(array, arrayIndex);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
180 }
181
182 /// <summary>
183 ///
184 /// </summary>
185 public int Count
186 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
187 get { return Columns.Count; }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
188 }
189
190 /// <summary>
191 ///
192 /// </summary>
193 public bool IsReadOnly
194 {
a8f0efa @nberardi added ability to remove column
nberardi authored
195 get { return Columns.IsReadOnly; }
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
196 }
197
198 /// <summary>
199 ///
200 /// </summary>
201 /// <param name="item"></param>
202 /// <returns></returns>
203 public bool Remove(T item)
204 {
118573f @nberardi All tests for columns and families are passing.
nberardi authored
205 OnColumnMutated(MutationType.Removed, item);
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
206 return Columns.Remove(item);
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
207 }
208
209 /// <summary>
210 ///
211 /// </summary>
212 /// <returns></returns>
213 public IEnumerator<T> GetEnumerator()
214 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
215 return Columns.GetEnumerator();
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
216 }
217
218 /// <summary>
219 ///
220 /// </summary>
221 /// <returns></returns>
222 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
223 {
d7df425 @nberardi reformatted the GetSlice a little to return the column family instead…
nberardi authored
224 return Columns.GetEnumerator();
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
225 }
118573f @nberardi All tests for columns and families are passing.
nberardi authored
226
227 #endregion
228
229 #region INotifyCollectionChanged Members
230
231 public event NotifyCollectionChangedEventHandler CollectionChanged;
232
233 protected void OnColumnMutated(MutationType type, IFluentBaseColumn column)
234 {
235 if (SupressChangeNotification)
236 return;
237
238 IFluentRecord record = Parent.SuperColumn == null ? (IFluentRecord)Parent.ColumnFamily : (IFluentRecord)Parent.SuperColumn;
239 record.MutationTracker.ColumnMutated(type, column);
240
241 if (CollectionChanged != null)
242 {
243 var action = type == MutationType.Added ? NotifyCollectionChangedAction.Add : (type == MutationType.Removed ? NotifyCollectionChangedAction.Remove : NotifyCollectionChangedAction.Replace);
244 CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, column));
245 }
246 }
247
248 #endregion
88be638 @nberardi did some clean up and Get is now supported for a single column
nberardi authored
249 }
f27726f @nberardi adding mutation tracking to the fluent objects
nberardi authored
250 }
Something went wrong with that request. Please try again.