sonatype-lift[bot] commented on code in PR #1834:
URL: https://github.com/apache/groovy/pull/1834#discussion_r1053074864


##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -4005,6 +3998,405 @@ public static <K, V, E> Map<K, V> 
collectEntries(Iterator<E> self, Map<K, V> col
         return collector;
     }
 
+    /**
+     * A variant of collectEntries for Iterators with separate functions for 
transforming the keys and values.
+     * The supplied collector map is used as the destination for transformed 
entries.
+     *
+     * @param self           an Iterator
+     * @param collector      the Map into which the transformed entries are put
+     * @param keyTransform   a function for transforming Iterator elements 
into keys
+     * @param valueTransform a function for transforming Iterator elements 
into values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(Iterator<E> self, Map<K, 
V> collector, Function<? super E, K> keyTransform, Function<? super E, V> 
valueTransform) {
+        while (self.hasNext()) {
+            E element = self.next();
+            addEntry(collector, Tuple2.tuple(keyTransform.apply(element), 
valueTransform.apply(element)));
+        }
+        return collector;
+    }
+
+    /**
+     * A variant of collectEntries for Iterators with separate functions for 
transforming the keys and values.
+     *
+     * @param self           an Iterator
+     * @param keyTransform   a function for transforming Iterator elements 
into keys
+     * @param valueTransform a function for transforming Iterator elements 
into values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(Iterator<E> self, 
Function<? super E, K> keyTransform, Function<? super E, V> valueTransform) {
+        return collectEntries(self, new LinkedHashMap<>(), keyTransform, 
valueTransform);
+    }
+
+    /**
+     * A variant of collectEntries for Iterables with separate functions for 
transforming the keys and values.
+     * The supplied collector map is used as the destination for transformed 
entries.
+     * <pre class="groovyTestCase">
+     * def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * assert languages.collectEntries([clojure:7], String::toLowerCase, 
String::size) ==
+     *     [clojure:7, groovy:6, java:4, kotlin:6, scala:5]
+     * </pre>
+     *
+     * @param self           an Iterable
+     * @param collector      the Map into which the transformed entries are put
+     * @param keyTransform   a function for transforming Iterable elements 
into keys
+     * @param valueTransform a function for transforming Iterable elements 
into values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(Iterable<E> self, Map<K, 
V> collector, Function<? super E, K> keyTransform, Function<? super E, V> 
valueTransform) {
+        return collectEntries(self.iterator(), collector, keyTransform, 
valueTransform);
+    }
+
+    /**
+     * A variant of collectEntries for Iterables with separate functions for 
transforming the keys and values.
+     * <pre class="groovyTestCase">
+     * def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * assert languages.collectEntries(String::toLowerCase, String::size) ==
+     *     [groovy:6, java:4, kotlin:6, scala:5]
+     * </pre>
+     *
+     * @param self           an Iterable
+     * @param keyTransform   a function for transforming Iterable elements 
into keys
+     * @param valueTransform a function for transforming Iterable elements 
into values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(Iterable<E> self, 
Function<? super E, K> keyTransform, Function<? super E, V> valueTransform) {
+        return collectEntries(self.iterator(), new LinkedHashMap<>(), 
keyTransform, valueTransform);
+    }
+
+    /**
+     * A variant of collectEntries for arrays with separate functions for 
transforming the keys and values.
+     * The supplied collector map is used as the destination for transformed 
entries.
+     *
+     * @param self           an array
+     * @param collector      the Map into which the transformed entries are put
+     * @param keyTransform   a function for transforming array elements into 
keys
+     * @param valueTransform a function for transforming array elements into 
values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(E[] self, Map<K, V> 
collector, Function<? super E, K> keyTransform, Function<? super E, V> 
valueTransform) {
+        return collectEntries(new ArrayIterator<>(self), collector, 
keyTransform, valueTransform);
+    }
+
+    /**
+     * A variant of collectEntries for arrays with separate functions for 
transforming the keys and values.
+     * <pre class="groovyTestCase">
+     * String[] languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * def firstLetter = s -> s[0]
+     * assert languages.collectEntries(firstLetter, String::size) == [G:6, 
J:4, K:6, S:5]
+     * </pre>
+     *
+     * @param self           an array
+     * @param keyTransform   a function for transforming array elements into 
keys
+     * @param valueTransform a function for transforming array elements into 
values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V, E> Map<K, V> collectEntries(E[] self, Function<? 
super E, K> keyTransform, Function<? super E, V> valueTransform) {
+        return collectEntries(new ArrayIterator<>(self), new 
LinkedHashMap<>(), keyTransform, valueTransform);
+    }
+
+    /**
+     * A variant of collectEntries for Maps with separate functions for 
transforming the keys and values.
+     * The supplied collector map is used as the destination for transformed 
entries.
+     *
+     * @param self           a Map
+     * @param collector      the Map into which the transformed entries are put
+     * @param keyTransform   a function for transforming Map keys
+     * @param valueTransform a function for transforming Map values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V, X, Y> Map<K, V> collectEntries(Map<X, Y> self, Map<K, 
V> collector, Function<? super X, K> keyTransform, Function<? super Y, V> 
valueTransform) {
+        for (Map.Entry<X, Y> entry : self.entrySet()) {
+            addEntry(collector, 
Tuple2.tuple(keyTransform.apply(entry.getKey()), 
valueTransform.apply(entry.getValue())));
+        }
+        return collector;
+    }
+
+    /**
+     * A variant of collectEntries for Maps with separate functions for 
transforming the keys and values.
+     *
+     * @param self           a Map
+     * @param keyTransform   a function for transforming Map keys
+     * @param valueTransform a function for transforming Map values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V, X, Y> Map<K, V> collectEntries(Map<X, Y> self, 
Function<? super X, K> keyTransform, Function<? super Y, V> valueTransform) {
+        return collectEntries(self, new LinkedHashMap<>(), keyTransform, 
valueTransform);
+    }
+
+    /**
+     * A variant of withCollectedValues for Iterators.
+     *
+     * @param keys           an Iterator
+     * @param collector      the Map into which the transformed entries are put
+     * @param valueTransform a function for transforming Iterator elements 
into values
+     * @return the collector with all transformed values added to it
+     * @see #withCollectedValues(Iterable, Map, Function)
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(Iterator<K> keys, 
Map<K, V> collector, Function<? super K, V> valueTransform) {
+        return collectEntries(keys, collector, Function.identity(), 
valueTransform);
+    }
+
+    /**
+     * A variant of withCollectedValues for Iterators.
+     *
+     * @param keys           an Iterator
+     * @param valueTransform a function for transforming Iterator elements 
into values
+     * @return a Map of the transformed entries
+     * @see #withCollectedValues(Iterable, Function)
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(Iterator<K> keys, 
Function<? super K, V> valueTransform) {
+        return withCollectedValues(keys, new LinkedHashMap<>(), 
valueTransform);
+    }
+
+    /**
+     * Transform Iterable elements into Map entries with keys unchanged
+     * and values transformed using the supplied function.
+     * The supplied collector map is used as the destination for transformed 
entries.
+     * <pre class="groovyTestCase">
+     * def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * assert languages.withCollectedValues([Clojure:7], String::size) ==
+     *     [Clojure:7, Groovy:6, Java:4, Kotlin:6, Scala:5]
+     * </pre>
+     *
+     * @param keys           an Iterable
+     * @param collector      the Map into which the transformed entries are put
+     * @param valueTransform a function for transforming Iterable elements 
into values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(Iterable<K> keys, 
Map<K, V> collector, Function<? super K, V> valueTransform) {
+        return collectEntries(keys.iterator(), collector, Function.identity(), 
valueTransform);
+    }
+
+    /**
+     * Transform Iterable elements into Map entries with keys unchanged
+     * and values transformed using the supplied function.
+     * <pre class="groovyTestCase">
+     * def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * assert languages.withCollectedValues(String::size) ==
+     *     [Groovy:6, Java:4, Kotlin:6, Scala:5]
+     * </pre>
+     *
+     * @param keys           an Iterable
+     * @param valueTransform a function for transforming Iterable elements 
into values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(Iterable<K> keys, 
Function<? super K, V> valueTransform) {
+        return withCollectedValues(keys.iterator(), new LinkedHashMap<>(), 
valueTransform);
+    }
+
+    /**
+     * A variant of withCollectedValues for arrays.
+     *
+     * @param keys           an array
+     * @param collector      the Map into which the transformed entries are put
+     * @param valueTransform a function for transforming array elements into 
values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(K[] keys, Map<K, V> 
collector, Function<? super K, V> valueTransform) {
+        return collectEntries(new ArrayIterator<>(keys), collector, 
Function.identity(), valueTransform);
+    }
+
+    /**
+     * A variant of withCollectedValues for arrays.
+     *
+     * @param keys           an array
+     * @param valueTransform a function for transforming array elements into 
values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedValues(K[] keys, Function<? 
super K, V> valueTransform) {
+        return withCollectedValues(new ArrayIterator<>(keys), new 
LinkedHashMap<>(), valueTransform);
+    }
+
+    /**
+     * Transform a Maps' values leaving the keys unchanged.
+     * Similar to {@link #withCollectedValues(Iterable, Map, Function)} but 
for Maps.
+     * <pre class="groovyTestCase">
+     * def lengths = [Groovy:6, Java:4, Kotlin:6, Scala:5]
+     * def squared = e -> e ** 2
+     * assert lengths.collectValues([Clojure:49], squared) ==
+     *     [Clojure:49, Groovy:36, Java:16, Kotlin:36, Scala:25]
+     * </pre>
+     *
+     * @param keys           a Map
+     * @param collector      the Map into which the transformed entries are put
+     * @param valueTransform a function for transforming Map values
+     * @return the collector with all transformed values added to it
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> collectValues(Map<K, V> keys, Map<K, V> 
collector, Function<? super V, V> valueTransform) {
+        for (Map.Entry<K, V> entry : keys.entrySet()) {
+            addEntry(collector, Tuple2.tuple(entry.getKey(), 
valueTransform.apply(entry.getValue())));
+        }
+        return collector;
+    }
+
+    /**
+     * Transform a Maps' values leaving the keys unchanged.
+     * Similar to {@link #withCollectedValues(Iterable, Function)} but for 
Maps.
+     * <pre class="groovyTestCase">
+     * def lengths = [Groovy:6, Java:4, Kotlin:6, Scala:5]
+     * def squared = e -> e ** 2
+     * assert lengths.collectValues(squared) == [Groovy:36, Java:16, 
Kotlin:36, Scala:25]
+     * </pre>
+     *
+     * @param keys           a Map
+     * @param valueTransform a function for transforming Map values
+     * @return a Map of the transformed entries
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> collectValues(Map<K, V> keys, Function<? 
super V, V> valueTransform) {
+        return collectValues(keys, new LinkedHashMap<>(), valueTransform);
+    }
+
+    /**
+     * A variant of withCollectedKeys for Iterators.
+     *
+     * @param values       an Iterator
+     * @param collector    the Map into which the transformed entries are put
+     * @param keyTransform a function for transforming Iterator elements into 
values
+     * @return the collector with all transformed values added to it
+     * @see #withCollectedKeys(Iterable, Map, Function)
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedKeys(Iterator<V> values, 
Map<K, V> collector, Function<? super V, K> keyTransform) {
+        return collectEntries(values, collector, keyTransform, 
Function.identity());
+    }
+
+    /**
+     * A variant of withCollectedKeys for Iterators.
+     *
+     * @param values       an Iterator
+     * @param keyTransform a function for transforming Iterator elements into 
values
+     * @return a Map of the transformed entries
+     * @see #withCollectedKeys(Iterable, Function)
+     * @since 5.0.0
+     */
+    public static <K, V> Map<K, V> withCollectedKeys(Iterator<V> values, 
Function<? super V, K> keyTransform) {
+        return withCollectedKeys(values, new LinkedHashMap<>(), keyTransform);
+    }
+
+    /**
+     * Transform Iterable elements into Map entries with values unchanged
+     * and keys transformed using the supplied function.
+     * The supplied map is used as the destination for transformed entries.
+     * <pre class="groovyTestCase">
+     * def languages = ['Groovy', 'Java', 'Kotlin', 'Scala']
+     * def firstLetter = s -> s[0]

Review Comment:
   đŸ’Ŧ 6 similar findings have been found in this PR
   
   ---
   
   *[UnescapedEntity](https://errorprone.info/bugpattern/UnescapedEntity):*  
This HTML entity is invalid. Enclosing the code in this <pre>/<code> tag with a 
{@code } block will force Javadoc to interpret HTML literally.
   
   ---
   
   
   ```suggestion
        * <pre class="groovyTestCase">{@code
   ```
   
   
   ---
   
   <details><summary><b>🔎 Expand here to view all instances of this 
finding</b></summary><br/>
     
     
   <div align=\"center\">
   
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4090](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4090)
 |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4319](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4319)
 |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4387](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4387)
 |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4253](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4253)
 |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4365](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4365)
 |
   | src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 
[4230](https://github.com/apache/groovy/blob/05c6197897c6fa466091a47cb06c79a387bbb17e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L4230)
 |
   <p><a 
href="https://lift.sonatype.com/results/github.com/apache/groovy/01GMQ9Y5JHGVM78AS3N9CE5NWE?t=ErrorProne|UnescapedEntity"
 target="_blank">Visit the Lift Web Console</a> to find more details in your 
report.</p></div></details>
   
   
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=362798465&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=362798465&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=362798465&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=362798465&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=362798465&lift_comment_rating=5)
 ]



-- 
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