Skip to content

Commit 681ae45

Browse files
committed
Move SetSnapShot to separate files.
1 parent 1d77ee5 commit 681ae45

File tree

4 files changed

+117
-103
lines changed

4 files changed

+117
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Collection.Generic.SetHelpers
5+
{
6+
internal interface ISetSnapshot<T> : ICollection<T>, ICollection
7+
{
8+
T this[T element] { get; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace NHibernate.Collection.Generic.SetHelpers
6+
{
7+
[Serializable]
8+
internal class SetSnapShot<T> : ISetSnapshot<T>
9+
{
10+
private readonly List<T> elements;
11+
public SetSnapShot()
12+
{
13+
elements = new List<T>();
14+
}
15+
16+
public SetSnapShot(int capacity)
17+
{
18+
elements = new List<T>(capacity);
19+
}
20+
21+
public SetSnapShot(IEnumerable<T> collection)
22+
{
23+
elements = new List<T>(collection);
24+
}
25+
26+
public IEnumerator<T> GetEnumerator()
27+
{
28+
return elements.GetEnumerator();
29+
}
30+
31+
IEnumerator IEnumerable.GetEnumerator()
32+
{
33+
return GetEnumerator();
34+
}
35+
36+
public void Add(T item)
37+
{
38+
elements.Add(item);
39+
}
40+
41+
public void Clear()
42+
{
43+
throw new InvalidOperationException();
44+
}
45+
46+
public bool Contains(T item)
47+
{
48+
return elements.Contains(item);
49+
}
50+
51+
public void CopyTo(T[] array, int arrayIndex)
52+
{
53+
elements.CopyTo(array, arrayIndex);
54+
}
55+
56+
public bool Remove(T item)
57+
{
58+
throw new InvalidOperationException();
59+
}
60+
61+
public void CopyTo(Array array, int index)
62+
{
63+
((ICollection)elements).CopyTo(array, index);
64+
}
65+
66+
int ICollection.Count
67+
{
68+
get { return elements.Count; }
69+
}
70+
71+
public object SyncRoot
72+
{
73+
get { return ((ICollection)elements).SyncRoot; }
74+
}
75+
76+
public bool IsSynchronized
77+
{
78+
get { return ((ICollection)elements).IsSynchronized; }
79+
}
80+
81+
int ICollection<T>.Count
82+
{
83+
get { return elements.Count; }
84+
}
85+
86+
public bool IsReadOnly
87+
{
88+
get { return ((ICollection<T>)elements).IsReadOnly; }
89+
}
90+
91+
public T this[T element]
92+
{
93+
get
94+
{
95+
var idx = elements.IndexOf(element);
96+
if (idx >= 0)
97+
{
98+
return elements[idx];
99+
}
100+
return default(T);
101+
}
102+
}
103+
}
104+
}

src/NHibernate/Collection/PersistentSet.cs

+1-103
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Data;
55
using System.Diagnostics;
66
using Iesi.Collections;
7+
using NHibernate.Collection.Generic.SetHelpers;
78
using NHibernate.DebugHelpers;
89
using NHibernate.Engine;
910
using NHibernate.Loader;
@@ -13,109 +14,6 @@
1314

1415
namespace NHibernate.Collection
1516
{
16-
internal interface ISetSnapshot<T> : ICollection<T>, ICollection
17-
{
18-
T this[T element] { get; }
19-
}
20-
21-
[Serializable]
22-
internal class SetSnapShot<T> : ISetSnapshot<T>
23-
{
24-
private readonly List<T> elements;
25-
public SetSnapShot()
26-
{
27-
elements = new List<T>();
28-
}
29-
30-
public SetSnapShot(int capacity)
31-
{
32-
elements = new List<T>(capacity);
33-
}
34-
35-
public SetSnapShot(IEnumerable<T> collection)
36-
{
37-
elements = new List<T>(collection);
38-
}
39-
40-
public IEnumerator<T> GetEnumerator()
41-
{
42-
return elements.GetEnumerator();
43-
}
44-
45-
IEnumerator IEnumerable.GetEnumerator()
46-
{
47-
return GetEnumerator();
48-
}
49-
50-
public void Add(T item)
51-
{
52-
elements.Add(item);
53-
}
54-
55-
public void Clear()
56-
{
57-
throw new InvalidOperationException();
58-
}
59-
60-
public bool Contains(T item)
61-
{
62-
return elements.Contains(item);
63-
}
64-
65-
public void CopyTo(T[] array, int arrayIndex)
66-
{
67-
elements.CopyTo(array, arrayIndex);
68-
}
69-
70-
public bool Remove(T item)
71-
{
72-
throw new InvalidOperationException();
73-
}
74-
75-
public void CopyTo(Array array, int index)
76-
{
77-
((ICollection)elements).CopyTo(array, index);
78-
}
79-
80-
int ICollection.Count
81-
{
82-
get { return elements.Count; }
83-
}
84-
85-
public object SyncRoot
86-
{
87-
get { return ((ICollection)elements).SyncRoot; }
88-
}
89-
90-
public bool IsSynchronized
91-
{
92-
get { return ((ICollection)elements).IsSynchronized; }
93-
}
94-
95-
int ICollection<T>.Count
96-
{
97-
get { return elements.Count; }
98-
}
99-
100-
public bool IsReadOnly
101-
{
102-
get { return ((ICollection<T>)elements).IsReadOnly; }
103-
}
104-
105-
public T this[T element]
106-
{
107-
get
108-
{
109-
var idx = elements.IndexOf(element);
110-
if (idx >= 0)
111-
{
112-
return elements[idx];
113-
}
114-
return default(T);
115-
}
116-
}
117-
}
118-
11917
/// <summary>
12018
/// .NET has no design equivalent for Java's Set so we are going to use the
12119
/// Iesi.Collections library. This class is internal to NHibernate and shouldn't

src/NHibernate/NHibernate.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<Compile Include="Cfg\Settings.cs" />
132132
<Compile Include="Cfg\SettingsFactory.cs" />
133133
<Compile Include="Collection\IPersistentCollection.cs" />
134+
<Compile Include="Collection\Generic\SetHelpers\ISetSnapshot.cs" />
135+
<Compile Include="Collection\Generic\SetHelpers\SetSnapShot.cs" />
134136
<Compile Include="Connection\ConnectionProvider.cs" />
135137
<Compile Include="Connection\ConnectionProviderFactory.cs" />
136138
<Compile Include="Connection\DriverConnectionProvider.cs" />

0 commit comments

Comments
 (0)