23 using System.Collections;
24 using System.Collections.Generic;
28 namespace Lucene.Net.Index.Memory
30 internal static class CollectionsHelper<T>
32 private static readonly T[] EmptyArray =
new T[0];
37 public static IList<T> EmptyList()
43 public static class CollectionsExtensions
45 public static ICollection<T> AsReadOnly<T>(
this ICollection<T> collection)
47 return new ReadOnlyCollection<T>(collection);
50 private sealed
class ReadOnlyCollection<T> : ICollection<T>
52 private readonly ICollection<T> _other;
54 public ReadOnlyCollection(ICollection<T> other)
59 public IEnumerator<T> GetEnumerator()
61 return _other.GetEnumerator();
64 IEnumerator IEnumerable.GetEnumerator()
66 return GetEnumerator();
69 public void Add(T item)
71 throw new NotSupportedException(
"Collection is read only!");
76 throw new NotSupportedException(
"Collection is read only!");
79 public bool Contains(T item)
81 return _other.Contains(item);
84 public void CopyTo(T[] array,
int arrayIndex)
86 _other.CopyTo(array, arrayIndex);
89 public bool Remove(T item)
91 throw new NotSupportedException(
"Collection is read only!");
96 get {
return _other.Count; }
99 public bool IsReadOnly