diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs index d7ae442dde..ff3b1bc379 100644 --- a/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs +++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs @@ -6,6 +6,7 @@ using Spatial4n.Core.Context; using Spatial4n.Core.Shapes; using System; +using System.Collections; using System.Collections.Generic; using Console = Lucene.Net.Util.SystemConsole; @@ -70,14 +71,21 @@ protected virtual SpatialStrategy MakeSpatialStrategy(Config config) //A Map view of Config that prefixes keys with "spatial." var configMap = new DictionaryAnonymousClass(config); - SpatialContext ctx = SpatialContextFactory.MakeSpatialContext(configMap /*, null*/); // LUCENENET TODO: What is this extra param? + // LUCENENET: The second argument was ClassLoader in Java, which should be made into + // Assembly in .NET. However, Spatial4n currently doesn't support it. + // In .NET it makes more logical sense to make 2 overloads and throw NullReferenceException + // if the second argument is null, anyway. So no need to change this once support has been added. + // See: https://github.com/NightOwl888/Spatial4n/issues/1 + SpatialContext ctx = SpatialContextFactory.MakeSpatialContext(configMap /*, assembly: null*/); //Some day the strategy might be initialized with a factory but such a factory // is non-existent. return MakeSpatialStrategy(config, configMap, ctx); } - private class DictionaryAnonymousClass : Dictionary + // LUCENENET specific: since this[string] is not virtual in .NET, this full implementation + // of IDictionary is required to override methods to get a value by key + private class DictionaryAnonymousClass : IDictionary { private readonly Config config; public DictionaryAnonymousClass(Config config) @@ -85,16 +93,60 @@ public DictionaryAnonymousClass(Config config) this.config = config; } - // LUCENENET TODO: EntrySet not supported. Should we throw on GetEnumerator()? + public string this[string key] + { + get => config.Get("spatial." + key, null); + set => throw new NotSupportedException(); + } + + public bool TryGetValue(string key, out string value) + { + value = config.Get("spatial." + key, null); + return value != null; + } + + public bool ContainsKey(string key) + { + const string notSupported = "notsupported"; + var value = config.Get("spatial." + key, notSupported); + return !value.Equals(notSupported, StringComparison.Ordinal); + } + + #region IDictionary members + + ICollection IDictionary.Keys => throw new NotSupportedException(); + + ICollection IDictionary.Values => throw new NotSupportedException(); + + int ICollection>.Count => throw new NotSupportedException(); + + public bool IsReadOnly => true; + + void IDictionary.Add(string key, string value) => throw new NotSupportedException(); + void ICollection>.Add(KeyValuePair item) => throw new NotSupportedException(); + void ICollection>.Clear() => throw new NotSupportedException(); + bool ICollection>.Contains(KeyValuePair item) => throw new NotSupportedException(); + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) => throw new NotSupportedException(); + IEnumerator> IEnumerable>.GetEnumerator() => throw new NotSupportedException(); + bool IDictionary.Remove(string key) => throw new NotSupportedException(); + bool ICollection>.Remove(KeyValuePair item) => throw new NotSupportedException(); + + IEnumerator IEnumerable.GetEnumerator() => throw new NotSupportedException(); - new public string this[string key] => config.Get("spatial." + key, null); + #endregion IDictionary members } protected virtual SpatialStrategy MakeSpatialStrategy(Config config, IDictionary configMap, SpatialContext ctx) { //A factory for the prefix tree grid - SpatialPrefixTree grid = SpatialPrefixTreeFactory.MakeSPT(configMap, /*null,*/ ctx); // LUCENENET TODO: What is this extra param? + // LUCENENET: The second argument was ClassLoader in Java, which should be made into + // Assembly in .NET. However, Spatial4n currently doesn't support it. + // In .NET it makes more logical sense to make 2 overloads and throw NullReferenceException + // if the second argument is null, anyway. So no need to change this once support has been added. + // See: https://github.com/NightOwl888/Spatial4n/issues/1 + SpatialPrefixTree grid = SpatialPrefixTreeFactory.MakeSPT(configMap/*, assembly: null*/, ctx); RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategyAnonymousClass(grid, SPATIAL_FIELD, config);