From 53bb736b6fe1ac02ccba7e05a2ed799d1c1e3193 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Sun, 10 Mar 2024 09:03:48 -0600 Subject: [PATCH] Remove unused ConcurrentDictionaryWrapper type --- .../Support/ConcurrentDictionaryWrapper.cs | 240 ------------------ .../Support/DictionaryExtensions.cs | 23 +- 2 files changed, 1 insertion(+), 262 deletions(-) delete mode 100644 src/Lucene.Net/Support/ConcurrentDictionaryWrapper.cs diff --git a/src/Lucene.Net/Support/ConcurrentDictionaryWrapper.cs b/src/Lucene.Net/Support/ConcurrentDictionaryWrapper.cs deleted file mode 100644 index 278c4aaf19..0000000000 --- a/src/Lucene.Net/Support/ConcurrentDictionaryWrapper.cs +++ /dev/null @@ -1,240 +0,0 @@ -using J2N.Collections.Generic.Extensions; -using System; -using System.Collections.Generic; -using System.Threading; - -namespace Lucene.Net.Support -{ - /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - internal class ConcurrentDictionaryWrapper : IDictionary - { - private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); - private readonly IDictionary _dict; - - public ConcurrentDictionaryWrapper(IDictionary wrapped) - { - this._dict = wrapped; - } - - public void Add(TKey key, TValue value) - { - _lock.EnterWriteLock(); - try - { - _dict.Add(key, value); - } - finally - { - _lock.ExitWriteLock(); - } - } - - public bool ContainsKey(TKey key) - { - _lock.EnterReadLock(); - try - { - return _dict.ContainsKey(key); - } - finally - { - _lock.ExitReadLock(); - } - } - - public ICollection Keys - { - get - { - _lock.EnterReadLock(); - try - { - return _dict.Keys.AsReadOnly(); - } - finally - { - _lock.ExitReadLock(); - } - } - } - - public bool Remove(TKey key) - { - _lock.EnterWriteLock(); - try - { - return _dict.Remove(key); - } - finally - { - _lock.ExitWriteLock(); - } - } - - public bool TryGetValue(TKey key, out TValue value) - { - _lock.EnterReadLock(); - try - { - return _dict.TryGetValue(key, out value); - } - finally - { - _lock.ExitReadLock(); - } - } - - public ICollection Values - { - get - { - _lock.EnterReadLock(); - try - { - return _dict.Values.AsReadOnly(); - } - finally - { - _lock.ExitReadLock(); - } - } - } - - public TValue this[TKey key] - { - get - { - _lock.EnterReadLock(); - try - { - return _dict.TryGetValue(key, out TValue result) ? result : default; - } - finally - { - _lock.ExitReadLock(); - } - } - set - { - _lock.EnterWriteLock(); - try - { - _dict[key] = value; - } - finally - { - _lock.ExitWriteLock(); - } - } - } - - public void Add(KeyValuePair item) - { - _lock.EnterWriteLock(); - try - { - _dict.Add(item); - } - finally - { - _lock.ExitWriteLock(); - } - } - - public void Clear() - { - _lock.EnterWriteLock(); - try - { - _dict.Clear(); - } - finally - { - _lock.ExitWriteLock(); - } - } - - public bool Contains(KeyValuePair item) - { - _lock.EnterReadLock(); - try - { - return _dict.Contains(item); - } - finally - { - _lock.ExitReadLock(); - } - } - - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - _lock.EnterReadLock(); - try - { - _dict.CopyTo(array, arrayIndex); - } - finally - { - _lock.ExitReadLock(); - } - } - - public int Count - { - get - { - _lock.EnterReadLock(); - try - { - return _dict.Count; - } - finally - { - _lock.ExitReadLock(); - } - } - } - - public bool IsReadOnly => _dict.IsReadOnly; - - public bool Remove(KeyValuePair item) - { - _lock.EnterWriteLock(); - try - { - return _dict.Remove(item); - } - finally - { - _lock.ExitWriteLock(); - } - } - - public IEnumerator> GetEnumerator() - { - throw new NotSupportedException(); - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - throw new NotSupportedException(); - } - } -} \ No newline at end of file diff --git a/src/Lucene.Net/Support/DictionaryExtensions.cs b/src/Lucene.Net/Support/DictionaryExtensions.cs index e65fcd4f8b..84cbf33599 100644 --- a/src/Lucene.Net/Support/DictionaryExtensions.cs +++ b/src/Lucene.Net/Support/DictionaryExtensions.cs @@ -88,26 +88,5 @@ public static TValue Put(this IDictionary dictionary dictionary[key] = value; return oldValue; } - - /// - /// Returns a concurrent wrapper for the current . - /// - /// The type of keys in the dictionary. - /// The type of values in the dictionary. - /// The collection to make concurrent (thread-safe). - /// An object that acts as a read-only wrapper around the current . - /// is null. - /// - /// To synchronize any modifications to the object, expose it only through this wrapper. - /// - /// The set returned uses simple locking and may not be the most performant solution, but it provides a quick - /// way to make any set thread-safe. - /// - /// This method is an O(1) operation. - /// - internal static IDictionary AsConcurrent(this IDictionary dictionary) - { - return new ConcurrentDictionaryWrapper(dictionary); - } } -} \ No newline at end of file +}