Copilot commented on code in PR #1066:
URL: https://github.com/apache/lucenenet/pull/1066#discussion_r2354151157


##########
src/Lucene.Net/Support/CastingListAdapter.cs:
##########
@@ -0,0 +1,75 @@
+using System.Collections.Generic;
+using System.Linq;
+
+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.
+     */
+
+    /// <summary>
+    /// LUCENENET specific class used to adapt a <see cref="IList{T}"/> to one 
with a different type parameter
+    /// where the elements are cast to the new type where needed.
+    /// </summary>
+    /// <typeparam name="T">The type of the elements in the original 
list.</typeparam>
+    /// <typeparam name="U">The type of the elements in the adapted 
list.</typeparam>
+    internal class CastingListAdapter<T, U> : IList<U>
+        where T : U
+    {
+        private readonly IList<T> list;
+
+        public CastingListAdapter(IList<T> list)
+        {
+            this.list = list;
+        }
+
+        public U this[int index]
+        {
+            get => list[index];
+            set => list[index] = (T)value;
+        }
+
+        public int Count => list.Count;
+
+        public bool IsReadOnly => list.IsReadOnly;
+
+        public void Add(U item) => list.Add((T)item);
+
+        public void Clear() => list.Clear();
+
+        public bool Contains(U item) => list.Contains((T)item);
+
+        public void CopyTo(U[] array, int arrayIndex)
+        {
+            for (int i = 0; i < list.Count; i++)
+            {
+                array[arrayIndex + i] = list[i];
+            }
+        }
+
+        public IEnumerator<U> GetEnumerator() => 
list.Cast<U>().GetEnumerator();

Review Comment:
   This implementation uses LINQ's `Cast<U>()` method which goes against the 
PR's stated goal of removing LINQ usage. Consider using the 
`CastingEnumeratorAdapter` directly: `new CastingEnumeratorAdapter<T, 
U>(list.GetEnumerator())`



##########
src/Lucene.Net.Tests.Grouping/DistinctValuesCollectorTest.cs:
##########
@@ -417,50 +411,183 @@ private void AddField(Document doc, string field, string 
value, DocValuesType ty
             doc.Add(valuesField);
         }
 
-        private 
IAbstractDistinctValuesCollector<AbstractDistinctValuesCollector.IGroupCount<T>>
 CreateDistinctCountCollector<T>(IAbstractFirstPassGroupingCollector<T> 
firstPassGroupingCollector,
+        // LUCENENET specific - wrapper class to adapt to a collector of 
IComparable group counts
+        private class ComparableDistinctValuesCollector<T, TGroupValue> : 
AbstractDistinctValuesCollector<ComparableGroupCount, IComparable>
+            where T : AbstractDistinctValuesCollector.GroupCount<TGroupValue>
+            where TGroupValue : IComparable
+        {
+            private readonly AbstractDistinctValuesCollector<T, TGroupValue> 
wrapped;
+
+            public 
ComparableDistinctValuesCollector(AbstractDistinctValuesCollector<T, 
TGroupValue> wrapped)
+            {
+                this.wrapped = wrapped;
+            }
+
+            public override IList<ComparableGroupCount> Groups
+                => wrapped.Groups.Select(group => new 
ComparableGroupCount(group.GroupValue, new 
JCG.HashSet<IComparable>(group.UniqueValues.Cast<IComparable>()))).ToList();

Review Comment:
   This method still uses LINQ (Select, Cast, ToList) which contradicts the 
PR's goal of removing LINQ usage. Consider implementing a manual conversion 
loop for consistency with the stated objectives.
   ```suggestion
               {
                   get
                   {
                       var result = new 
List<ComparableGroupCount>(wrapped.Groups.Count);
                       foreach (var group in wrapped.Groups)
                       {
                           var uniqueValues = new JCG.HashSet<IComparable>();
                           foreach (var value in group.UniqueValues)
                           {
                               uniqueValues.Add((IComparable)value);
                           }
                           result.Add(new 
ComparableGroupCount(group.GroupValue, uniqueValues));
                       }
                       return result;
                   }
               }
   ```



##########
src/Lucene.Net.Tests.Grouping/TestGrouping.cs:
##########
@@ -36,9 +36,11 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Linq;

Review Comment:
   This file imports System.Linq which contradicts the PR's goal of removing 
LINQ usage. Consider removing this import if LINQ is no longer needed, or 
replace remaining LINQ calls with manual implementations.
   ```suggestion
   
   ```



##########
src/Lucene.Net.Tests.Grouping/GroupingSearchTest.cs:
##########
@@ -10,6 +10,7 @@
 using NUnit.Framework;
 using System;
 using System.Collections;
+using System.Linq;

Review Comment:
   The PR description states that LINQ should be removed, but this file still 
imports System.Linq. If LINQ usage is being eliminated, consider removing this 
import or replacing LINQ calls with manual implementations.
   ```suggestion
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to