lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject lucenenet git commit: use nullable int to matche Lucene
Date Mon, 18 May 2015 06:22:22 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master e3833d6cc -> d00a4262b


use nullable int to matche Lucene


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/d00a4262
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/d00a4262
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/d00a4262

Branch: refs/heads/master
Commit: d00a4262bd7a10596cbb1fd6a62292a14f397019
Parents: e3833d6
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sat May 16 22:02:53 2015 -0400
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Sat May 16 22:02:53 2015 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Search/LiveFieldValues.cs   |  9 +++---
 .../core/Search/TestLiveFieldValues.cs          | 33 ++++++--------------
 2 files changed, 14 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d00a4262/src/Lucene.Net.Core/Search/LiveFieldValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/LiveFieldValues.cs b/src/Lucene.Net.Core/Search/LiveFieldValues.cs
index 1e3920d..277987c 100644
--- a/src/Lucene.Net.Core/Search/LiveFieldValues.cs
+++ b/src/Lucene.Net.Core/Search/LiveFieldValues.cs
@@ -36,7 +36,6 @@ namespace Lucene.Net.Search
 
     public abstract class LiveFieldValues<S, T> : ReferenceManager.RefreshListener,
IDisposable
         where S : class
-        where T : struct
     {
         private volatile IDictionary<string, T> Current = new ConcurrentDictionary<string,
T>();
         private volatile IDictionary<string, T> Old = new ConcurrentDictionary<string,
T>();
@@ -113,26 +112,26 @@ namespace Lucene.Net.Search
             // First try to get the "live" value:
             T value;
             Current.TryGetValue(id, out value);
-            if ((object)value == (object)MissingValue)
+            if (EqualityComparer<T>.Default.Equals(value, MissingValue))
             {
                 // Deleted but the deletion is not yet reflected in
                 // the reader:
                 return default(T);
             }
-            else if ((object)value != (object)default(T))
+            else if (!EqualityComparer<T>.Default.Equals(value, default(T)))
             {
                 return value;
             }
             else
             {
                 Old.TryGetValue(id, out value);
-                if ((object)value == (object)MissingValue)
+                if (EqualityComparer<T>.Default.Equals(value, MissingValue))
                 {
                     // Deleted but the deletion is not yet reflected in
                     // the reader:
                     return default(T);
                 }
-                else if ((object)value != (object)default(T))
+                else if (!EqualityComparer<T>.Default.Equals(value, default(T)))
                 {
                     return value;
                 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d00a4262/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs b/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
index b0b6e0d..6c3cc7d 100644
--- a/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
@@ -50,11 +50,11 @@ namespace Lucene.Net.Search
 
             IndexWriter w = new IndexWriter(dir, iwc);
 
-            SearcherManager mgr = new SearcherManager(w, true, new SearcherFactoryAnonymousInnerClassHelper(this));
+            SearcherManager mgr = new SearcherManager(w, true, new SearcherFactoryAnonymousInnerClassHelper());
 
             const int missing = -1;
 
-            LiveFieldValues<IndexSearcher, int> rt = new LiveFieldValuesAnonymousInnerClassHelper(this,
mgr, missing);
+            LiveFieldValues<IndexSearcher, int?> rt = new LiveFieldValuesAnonymousInnerClassHelper(mgr,
missing);
 
             int numThreads = TestUtil.NextInt(Random(), 2, 5);
             if (VERBOSE)
@@ -76,7 +76,7 @@ namespace Lucene.Net.Search
             {
                 int threadID = t;
                 Random threadRandom = new Random(Random().Next());
-                ThreadClass thread = new ThreadAnonymousInnerClassHelper(this, w, mgr, missing,
rt, startingGun, iters, idCount, reopenChance, deleteChance, addChance, t, threadID, threadRandom);
+                ThreadClass thread = new ThreadAnonymousInnerClassHelper(w, mgr, missing,
rt, startingGun, iters, idCount, reopenChance, deleteChance, addChance, t, threadID, threadRandom);
                 threads.Add(thread);
                 thread.Start();
             }
@@ -98,37 +98,27 @@ namespace Lucene.Net.Search
 
         private class SearcherFactoryAnonymousInnerClassHelper : SearcherFactory
         {
-            private readonly TestLiveFieldValues OuterInstance;
-
-            public SearcherFactoryAnonymousInnerClassHelper(TestLiveFieldValues outerInstance)
-            {
-                this.OuterInstance = outerInstance;
-            }
-
             public override IndexSearcher NewSearcher(IndexReader r)
             {
                 return new IndexSearcher(r);
             }
         }
 
-        private class LiveFieldValuesAnonymousInnerClassHelper : LiveFieldValues<IndexSearcher,
int>
+        private class LiveFieldValuesAnonymousInnerClassHelper : LiveFieldValues<IndexSearcher,
int?>
         {
-            private readonly TestLiveFieldValues OuterInstance;
-
-            public LiveFieldValuesAnonymousInnerClassHelper(TestLiveFieldValues outerInstance,
SearcherManager mgr, int missing)
+            public LiveFieldValuesAnonymousInnerClassHelper(SearcherManager mgr, int missing)
                 : base(mgr, missing)
             {
-                this.OuterInstance = outerInstance;
             }
 
-            protected override int LookupFromSearcher(IndexSearcher s, string id)
+            protected override int? LookupFromSearcher(IndexSearcher s, string id)
             {
                 TermQuery tq = new TermQuery(new Term("id", id));
                 TopDocs hits = s.Search(tq, 1);
                 Assert.IsTrue(hits.TotalHits <= 1);
                 if (hits.TotalHits == 0)
                 {
-                    return default(int);
+                    return null;
                 }
                 else
                 {
@@ -140,12 +130,10 @@ namespace Lucene.Net.Search
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
-            private readonly TestLiveFieldValues OuterInstance;
-
             private IndexWriter w;
             private SearcherManager Mgr;
             private int? Missing;
-            private LiveFieldValues<IndexSearcher, int> Rt;
+            private LiveFieldValues<IndexSearcher, int?> Rt;
             private CountDownLatch StartingGun;
             private int Iters;
             private int IdCount;
@@ -156,9 +144,8 @@ namespace Lucene.Net.Search
             private int ThreadID;
             private Random ThreadRandom;
 
-            public ThreadAnonymousInnerClassHelper(TestLiveFieldValues outerInstance, IndexWriter
w, SearcherManager mgr, int? missing, LiveFieldValues<IndexSearcher, int> rt, CountDownLatch
startingGun, int iters, int idCount, double reopenChance, double deleteChance, double addChance,
int t, int threadID, Random threadRandom)
+            public ThreadAnonymousInnerClassHelper(IndexWriter w, SearcherManager mgr, int?
missing, LiveFieldValues<IndexSearcher, int?> rt, CountDownLatch startingGun, int iters,
int idCount, double reopenChance, double deleteChance, double addChance, int t, int threadID,
Random threadRandom)
             {
-                this.OuterInstance = outerInstance;
                 this.w = w;
                 this.Mgr = mgr;
                 this.Missing = missing;
@@ -190,7 +177,7 @@ namespace Lucene.Net.Search
                         // same time:
                         if (ThreadRandom.NextDouble() <= AddChance)
                         {
-                            string id = string.Format(CultureInfo.InvariantCulture, "%d_%04x",
ThreadID, ThreadRandom.Next(IdCount));
+                            string id = string.Format(CultureInfo.InvariantCulture, "{0}_{1:X4}",
ThreadID, ThreadRandom.Next(IdCount));
                             int field = ThreadRandom.Next(int.MaxValue);
                             doc.Add(new StringField("id", id, Field.Store.YES));
                             doc.Add(new IntField("field", (int)field, Field.Store.YES));


Mime
View raw message