daniellansun commented on code in PR #2254:
URL: https://github.com/apache/groovy/pull/2254#discussion_r2155691786


##########
src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java:
##########
@@ -1547,6 +1548,146 @@ private static List<String> getGroups(final Matcher 
matcher) {
         return list;
     }
 
+    // stateful matcher API is not very extensible; care should be taken if 
using the matcher directly as it will potentially be mutated
+    // this mostly provides an efficient list delegate but will less 
efficiently recalculates matches for named groups
+    static class GroupList implements List<String> {
+        private final Matcher matcher;
+        private final int count;
+        private final List<String> delegate;
+
+        public GroupList(Matcher matcher, int count) {
+            this.matcher = matcher;
+            this.count = count;
+            this.delegate = getGroups(matcher);
+        }
+
+        @Override
+        public int size() {
+            return delegate.size();
+        }
+
+        @Override
+        public boolean isEmpty() {
+            return delegate.isEmpty();
+        }
+
+        @Override
+        public boolean contains(Object o) {
+            return delegate.contains(o);
+        }
+
+        @Override
+        public Iterator<String> iterator() {
+            return delegate.iterator();
+        }
+
+        @Override
+        public Object[] toArray() {
+            return delegate.toArray();
+        }
+
+        @Override
+        public boolean add(String s) {
+            throw new UnsupportedOperationException("Can't add to a Matcher 
result");
+        }
+
+        @Override
+        public boolean remove(Object o) {
+            throw new UnsupportedOperationException("Can't remove a Matcher 
result");
+        }
+
+        @Override
+        public boolean addAll(Collection c) {
+            throw new UnsupportedOperationException("Can't addAll to a Matcher 
result");
+        }
+
+        @Override
+        public boolean addAll(int index, Collection c) {
+            throw new UnsupportedOperationException("Can't addAll to a Matcher 
result");
+        }
+
+        @Override
+        public void clear() {
+            throw new UnsupportedOperationException("Can't clear a Matcher 
result");
+        }
+
+        @Override
+        public String get(int index) {
+            return delegate.get(index);
+        }
+
+        public String get(String name) {
+            matcher.reset();
+            for (int i = 0; i <= count; i++) {

Review Comment:
   Understood



-- 
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: notifications-unsubscr...@groovy.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to