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/06/22 05:25:28 UTC
[27/38] lucenenet git commit: API: Lucene.Net.Search.DocIdSet: Added
NewAnonymous() method for easy creation of anonymous classes via delegate
methods.
API: Lucene.Net.Search.DocIdSet: Added NewAnonymous() method for easy creation of anonymous classes via delegate methods.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/bd6a1bec
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/bd6a1bec
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/bd6a1bec
Branch: refs/heads/master
Commit: bd6a1bec42952afbe679719bf0c61a6ff16d4167
Parents: cbb4d3f
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Wed Jun 21 20:21:27 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Thu Jun 22 00:13:00 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Search/DocIdSet.cs | 178 +++++++++++++++++++++++++++++++++
1 file changed, 178 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/bd6a1bec/src/Lucene.Net/Search/DocIdSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Search/DocIdSet.cs b/src/Lucene.Net/Search/DocIdSet.cs
index 7528f20..8f0cc23 100644
--- a/src/Lucene.Net/Search/DocIdSet.cs
+++ b/src/Lucene.Net/Search/DocIdSet.cs
@@ -76,5 +76,183 @@ namespace Lucene.Net.Search
return false;
}
}
+
+ /// <summary>
+ /// Creates a new instance with the ability to specify the body of the <see cref="GetIterator()"/>
+ /// method through the <paramref name="getIterator"/> parameter.
+ /// Simple example:
+ /// <code>
+ /// var docIdSet = DocIdSet.NewAnonymous(getIterator: () =>
+ /// {
+ /// OpenBitSet bitset = new OpenBitSet(5);
+ /// bitset.Set(0, 5);
+ /// return new DocIdBitSet(bitset);
+ /// });
+ /// </code>
+ /// <para/>
+ /// LUCENENET specific
+ /// </summary>
+ /// <param name="getIterator">
+ /// A delegate method that represents (is called by) the <see cref="GetIterator()"/>
+ /// method. It returns the <see cref="DocIdSetIterator"/> for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <returns> A new <see cref="AnonymousDocIdSet"/> instance. </returns>
+ public static DocIdSet NewAnonymous(Func<DocIdSetIterator> getIterator)
+ {
+ return NewAnonymous(getIterator, null, null);
+ }
+
+ /// <summary>
+ /// Creates a new instance with the ability to specify the body of the <see cref="GetIterator()"/>
+ /// method through the <paramref name="getIterator"/> parameter and the body of the <see cref="Bits"/>
+ /// property through the <paramref name="bits"/> parameter.
+ /// Simple example:
+ /// <code>
+ /// var docIdSet = DocIdSet.NewAnonymous(getIterator: () =>
+ /// {
+ /// OpenBitSet bitset = new OpenBitSet(5);
+ /// bitset.Set(0, 5);
+ /// return new DocIdBitSet(bitset);
+ /// }, bits: () =>
+ /// {
+ /// return bits;
+ /// });
+ /// </code>
+ /// <para/>
+ /// LUCENENET specific
+ /// </summary>
+ /// <param name="getIterator">
+ /// A delegate method that represents (is called by) the <see cref="GetIterator()"/>
+ /// method. It returns the <see cref="DocIdSetIterator"/> for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <param name="bits">
+ /// A delegate method that represents (is called by) the <see cref="Bits"/>
+ /// property. It returns the <see cref="IBits"/> instance for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <returns> A new <see cref="AnonymousDocIdSet"/> instance. </returns>
+ public static DocIdSet NewAnonymous(Func<DocIdSetIterator> getIterator, Func<IBits> bits)
+ {
+ return NewAnonymous(getIterator, bits, null);
+ }
+
+ /// <summary>
+ /// Creates a new instance with the ability to specify the body of the <see cref="GetIterator()"/>
+ /// method through the <paramref name="getIterator"/> parameter and the body of the <see cref="Bits"/>
+ /// property through the <paramref name="bits"/> parameter.
+ /// Simple example:
+ /// <code>
+ /// var docIdSet = DocIdSet.NewAnonymous(getIterator: () =>
+ /// {
+ /// OpenBitSet bitset = new OpenBitSet(5);
+ /// bitset.Set(0, 5);
+ /// return new DocIdBitSet(bitset);
+ /// }, isCacheable: () =>
+ /// {
+ /// return true;
+ /// });
+ /// </code>
+ /// <para/>
+ /// LUCENENET specific
+ /// </summary>
+ /// <param name="getIterator">
+ /// A delegate method that represents (is called by) the <see cref="GetIterator()"/>
+ /// method. It returns the <see cref="DocIdSetIterator"/> for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <param name="isCacheable">
+ /// A delegate method that represents (is called by) the <see cref="IsCacheable"/>
+ /// property. It returns a <see cref="bool"/> value.
+ /// </param>
+ /// <returns> A new <see cref="AnonymousDocIdSet"/> instance. </returns>
+ public static DocIdSet NewAnonymous(Func<DocIdSetIterator> getIterator, Func<bool> isCacheable)
+ {
+ return NewAnonymous(getIterator, null, isCacheable);
+ }
+
+ /// <summary>
+ /// Creates a new instance with the ability to specify the body of the <see cref="GetIterator()"/>
+ /// method through the <paramref name="getIterator"/> parameter and the body of the <see cref="Bits"/>
+ /// property through the <paramref name="bits"/> parameter.
+ /// Simple example:
+ /// <code>
+ /// var docIdSet = DocIdSet.NewAnonymous(getIterator: () =>
+ /// {
+ /// OpenBitSet bitset = new OpenBitSet(5);
+ /// bitset.Set(0, 5);
+ /// return new DocIdBitSet(bitset);
+ /// }, bits: () =>
+ /// {
+ /// return bits;
+ /// }, isCacheable: () =>
+ /// {
+ /// return true;
+ /// });
+ /// </code>
+ /// <para/>
+ /// LUCENENET specific
+ /// </summary>
+ /// <param name="getIterator">
+ /// A delegate method that represents (is called by) the <see cref="GetIterator()"/>
+ /// method. It returns the <see cref="DocIdSetIterator"/> for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <param name="bits">
+ /// A delegate method that represents (is called by) the <see cref="Bits"/>
+ /// property. It returns the <see cref="IBits"/> instance for this <see cref="DocIdSet"/>.
+ /// </param>
+ /// <param name="isCacheable">
+ /// A delegate method that represents (is called by) the <see cref="IsCacheable"/>
+ /// property. It returns a <see cref="bool"/> value.
+ /// </param>
+ /// <returns> A new <see cref="AnonymousDocIdSet"/> instance. </returns>
+ public static DocIdSet NewAnonymous(Func<DocIdSetIterator> getIterator, Func<IBits> bits, Func<bool> isCacheable)
+ {
+ return new AnonymousDocIdSet(getIterator, bits, isCacheable);
+ }
+
+ // LUCENENET specific
+ private class AnonymousDocIdSet : DocIdSet
+ {
+ private readonly Func<DocIdSetIterator> getIterator;
+ private readonly Func<IBits> bits;
+ private readonly Func<bool> isCacheable;
+
+ public AnonymousDocIdSet(Func<DocIdSetIterator> getIterator, Func<IBits> bits, Func<bool> isCacheable)
+ {
+ if (getIterator == null)
+ throw new ArgumentNullException("getIterator");
+
+ this.getIterator = getIterator;
+ this.bits = bits;
+ this.isCacheable = isCacheable;
+ }
+
+ public override DocIdSetIterator GetIterator()
+ {
+ return this.getIterator();
+ }
+
+ public override IBits Bits
+ {
+ get
+ {
+ if (this.bits != null)
+ {
+ return this.bits();
+ }
+ return base.Bits;
+ }
+ }
+
+ public override bool IsCacheable
+ {
+ get
+ {
+ if (this.isCacheable != null)
+ {
+ return this.isCacheable();
+ }
+ return base.IsCacheable;
+ }
+ }
+ }
}
}
\ No newline at end of file