Initial Commit
This commit is contained in:
48
iTechSharp/srcbc/util/collections/CollectionUtilities.cs
Normal file
48
iTechSharp/srcbc/util/collections/CollectionUtilities.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.Collections
|
||||
{
|
||||
public sealed class CollectionUtilities
|
||||
{
|
||||
private CollectionUtilities()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool CheckElementsAreOfType(
|
||||
IEnumerable e,
|
||||
Type t)
|
||||
{
|
||||
foreach (object o in e)
|
||||
{
|
||||
if (!t.IsInstanceOfType(o))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string ToString(
|
||||
IEnumerable c)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
|
||||
IEnumerator e = c.GetEnumerator();
|
||||
|
||||
if (e.MoveNext())
|
||||
{
|
||||
sb.Append(e.Current.ToString());
|
||||
|
||||
while (e.MoveNext())
|
||||
{
|
||||
sb.Append(", ");
|
||||
sb.Append(e.Current.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append(']');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
44
iTechSharp/srcbc/util/collections/EmptyEnumerable.cs
Normal file
44
iTechSharp/srcbc/util/collections/EmptyEnumerable.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.Collections
|
||||
{
|
||||
public sealed class EmptyEnumerable
|
||||
: IEnumerable
|
||||
{
|
||||
public static readonly IEnumerable Instance = new EmptyEnumerable();
|
||||
|
||||
private EmptyEnumerable()
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return EmptyEnumerator.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EmptyEnumerator
|
||||
: IEnumerator
|
||||
{
|
||||
public static readonly IEnumerator Instance = new EmptyEnumerator();
|
||||
|
||||
private EmptyEnumerator()
|
||||
{
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public object Current
|
||||
{
|
||||
get { throw new InvalidOperationException("No elements"); }
|
||||
}
|
||||
}
|
||||
}
|
25
iTechSharp/srcbc/util/collections/EnumerableProxy.cs
Normal file
25
iTechSharp/srcbc/util/collections/EnumerableProxy.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.Collections
|
||||
{
|
||||
public sealed class EnumerableProxy
|
||||
: IEnumerable
|
||||
{
|
||||
private readonly IEnumerable inner;
|
||||
|
||||
public EnumerableProxy(
|
||||
IEnumerable inner)
|
||||
{
|
||||
if (inner == null)
|
||||
throw new ArgumentNullException("inner");
|
||||
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return inner.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
63
iTechSharp/srcbc/util/collections/HashSet.cs
Normal file
63
iTechSharp/srcbc/util/collections/HashSet.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.Collections
|
||||
{
|
||||
public class HashSet
|
||||
: ISet
|
||||
{
|
||||
private readonly Hashtable impl = new Hashtable();
|
||||
|
||||
public HashSet()
|
||||
{
|
||||
}
|
||||
|
||||
public HashSet(ISet s)
|
||||
{
|
||||
foreach (object o in s)
|
||||
{
|
||||
Add(o);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(object o)
|
||||
{
|
||||
impl[o] = null;
|
||||
}
|
||||
|
||||
public bool Contains(object o)
|
||||
{
|
||||
return impl.ContainsKey(o);
|
||||
}
|
||||
|
||||
public void CopyTo(Array array, int index)
|
||||
{
|
||||
impl.Keys.CopyTo(array, index);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return impl.Count; }
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return impl.Keys.GetEnumerator();
|
||||
}
|
||||
|
||||
public bool IsSynchronized
|
||||
{
|
||||
get { return impl.IsSynchronized; }
|
||||
}
|
||||
|
||||
public void Remove(object o)
|
||||
{
|
||||
impl.Remove(o);
|
||||
}
|
||||
|
||||
public object SyncRoot
|
||||
{
|
||||
get { return impl.SyncRoot; }
|
||||
}
|
||||
}
|
||||
}
|
13
iTechSharp/srcbc/util/collections/ISet.cs
Normal file
13
iTechSharp/srcbc/util/collections/ISet.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Utilities.Collections
|
||||
{
|
||||
public interface ISet
|
||||
: ICollection
|
||||
{
|
||||
void Add(object o);
|
||||
bool Contains(object o);
|
||||
void Remove(object o);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user