This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5406d67bab GROOVY-11678: Create DGM#subList(IntRange) method
5406d67bab is described below

commit 5406d67bab9e900998a8524540cd8e7e703a0164
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun May 25 11:53:05 2025 +1000

    GROOVY-11678: Create DGM#subList(IntRange) method
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git 
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index f186ae6c14..6dfc6b2098 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -14007,6 +14007,31 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
         }
     }
 
+    
//--------------------------------------------------------------------------
+    // subList
+
+    /**
+     * Returns a view of the portion of this list given by the specified range.
+     * <pre class="groovyTestCase">
+     * def nums = [0, 1, 2, 3, 4]
+     * assert nums.subList(1..3) == 1..3
+     * assert nums.subList(0<..<-1) == 1..3
+     * nums.subList(1..3).clear()
+     * assert nums == [0, 4]
+     * </pre>
+     *
+     * @param self  a List
+     * @param range a range
+     * @return a view of the specified range within this list
+     * @since 5.0.0
+     */
+    public static <T> List<T> subList(List<T> self, IntRange range) {
+        Objects.requireNonNull(self);
+        RangeInfo info = range.subListBorders(self.size());
+        Objects.checkFromToIndex(info.from, info.to, self.size());
+        return self.subList(info.from, info.to);
+    }
+
     
//--------------------------------------------------------------------------
     // subMap
 

Reply via email to