You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/01/31 17:55:52 UTC
[19/50] [abbrv] lucenenet git commit:
Lucene.Net.Core.Support.Compatibility.Collections: Created
UnmodifiableSetImpl and UnmodifiableListImpl classes and replaced
ImmutableHashSet and ImmutableList, respectively
Lucene.Net.Core.Support.Compatibility.Collections: Created UnmodifiableSetImpl and UnmodifiableListImpl classes and replaced ImmutableHashSet and ImmutableList, respectively
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/7c2e17f2
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/7c2e17f2
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/7c2e17f2
Branch: refs/heads/api-work
Commit: 7c2e17f29568e3175ba0ad6e407f580187e40970
Parents: 152c37e
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Jan 31 13:34:30 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Tue Jan 31 13:45:47 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Index/SegmentInfo.cs | 2 +-
src/Lucene.Net.Core/Store/DataOutput.cs | 2 +-
.../Support/Compatibility/Collections.cs | 177 +++++++++++++++++--
3 files changed, 167 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7c2e17f2/src/Lucene.Net.Core/Index/SegmentInfo.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfo.cs b/src/Lucene.Net.Core/Index/SegmentInfo.cs
index 56188ea..00ad1f8 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfo.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfo.cs
@@ -187,7 +187,7 @@ namespace Lucene.Net.Index
/// <summary>
/// Return all files referenced by this SegmentInfo. </summary>
- public ISet<string> GetFiles()
+ public ICollection<string> GetFiles()
{
if (setFiles == null)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7c2e17f2/src/Lucene.Net.Core/Store/DataOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/DataOutput.cs b/src/Lucene.Net.Core/Store/DataOutput.cs
index 769b5c1..ac51f65 100644
--- a/src/Lucene.Net.Core/Store/DataOutput.cs
+++ b/src/Lucene.Net.Core/Store/DataOutput.cs
@@ -308,7 +308,7 @@ namespace Lucene.Net.Store
/// <seealso cref="#writeString(String) String"/>.
/// </summary>
/// <param name="set"> Input set. May be null (equivalent to an empty set) </param>
- public virtual void WriteStringSet(ISet<string> set)
+ public virtual void WriteStringSet(ICollection<string> set)
{
if (set == null)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7c2e17f2/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
index bf421e9..f52d5d4 100644
--- a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
+++ b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
@@ -87,19 +87,9 @@ namespace Lucene.Net
list[index2] = tmp;
}
- public static IList<T> UnmodifiableList<T>(IEnumerable<T> items)
+ public static IList<T> UnmodifiableList<T>(IList<T> list)
{
- return ImmutableList.Create<T>(items.ToArray()); // LUCENENET TODO: Immutable != Unmodifiable
- }
-
- public static IList<T> UnmodifiableList<T>(List<T> items)
- {
- return items.AsReadOnly();
- }
-
- public static ISet<T> UnmodifiableSet<T>(IEnumerable<T> items)
- {
- return ImmutableHashSet.Create<T>(items.ToArray()); // LUCENENET TODO: Immutable != Unmodifiable
+ return new UnmodifiableListImpl<T>(list);
}
public static IDictionary<TKey, TValue> UnmodifiableMap<TKey, TValue>(IDictionary<TKey, TValue> d)
@@ -107,6 +97,10 @@ namespace Lucene.Net
return new UnmodifiableDictionary<TKey, TValue>(d);
}
+ public static ICollection<T> UnmodifiableSet<T>(ICollection<T> list)
+ {
+ return new UnmodifiableSetImpl<T>(list);
+ }
#region Nested Types
@@ -378,6 +372,100 @@ namespace Lucene.Net
#endregion ReverseComparer2
+ #region UnmodifiableListImpl
+
+ private class UnmodifiableListImpl<T> : IList<T>
+ {
+ private readonly IList<T> list;
+
+ public UnmodifiableListImpl(IList<T> list)
+ {
+ if (list == null)
+ throw new ArgumentNullException("list");
+ this.list = list;
+ }
+
+ public T this[int index]
+ {
+ get
+ {
+ return list[index];
+ }
+ set
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+ }
+
+ public int Count
+ {
+ get
+ {
+ return list.Count;
+ }
+ }
+
+ public bool IsReadOnly
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public void Add(T item)
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+
+ public void Clear()
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+
+ public bool Contains(T item)
+ {
+ return list.Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ list.CopyTo(array, arrayIndex);
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return list.GetEnumerator();
+ }
+
+ public int IndexOf(T item)
+ {
+ return list.IndexOf(item);
+ }
+
+ public void Insert(int index, T item)
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+
+ public bool Remove(T item)
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+
+ public void RemoveAt(int index)
+ {
+ throw new InvalidOperationException("Unable to modify this list.");
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+
+ #endregion UnmodifiableListImpl
+
#region UnmodifiableDictionary
private class UnmodifiableDictionary<TKey, TValue> : IDictionary<TKey, TValue>
@@ -486,6 +574,71 @@ namespace Lucene.Net
#endregion UnmodifiableDictionary
+ #region UnmodifiableSetImpl
+
+ private class UnmodifiableSetImpl<T> : ICollection<T>
+ {
+ private readonly ICollection<T> set;
+ public UnmodifiableSetImpl(ICollection<T> set)
+ {
+ if (set == null)
+ throw new ArgumentNullException("set");
+ this.set = set;
+ }
+ public int Count
+ {
+ get
+ {
+ return set.Count;
+ }
+ }
+
+ public bool IsReadOnly
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public void Add(T item)
+ {
+ throw new InvalidOperationException("Unable to modify this set.");
+ }
+
+ public void Clear()
+ {
+ throw new InvalidOperationException("Unable to modify this set.");
+ }
+
+ public bool Contains(T item)
+ {
+ return set.Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ set.CopyTo(array, arrayIndex);
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return set.GetEnumerator();
+ }
+
+ public bool Remove(T item)
+ {
+ throw new InvalidOperationException("Unable to modify this set.");
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+
+ #endregion
+
#endregion Nested Types
}
}