paulk-asert commented on code in PR #2215:
URL: https://github.com/apache/groovy/pull/2215#discussion_r2076523276


##########
src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java:
##########
@@ -1877,6 +1878,77 @@ public static StringBuilder leftShift(final 
StringBuilder self, final Object val
         return self;
     }
 
+    
//--------------------------------------------------------------------------
+    // make StringBuilder behaves like a stack of chars
+
+    /**
+     * Since StringBuilder is a basic dynamic container of chars, sometimes it 
should
+     * behave like a stack of chars at the same time.
+     * stack's methods should have: push(), peek(), pop(), size(), isEmpty()
+     * <pre class="groovyTestCase">
+     * def st = new StringBuilder()
+     * // stack in cases:
+     * st.push('B')
+     * assert st.toString() == 'B'
+     * st.push('a')
+     * assert st.toString() == 'Ba'
+     * st.push('r')
+     * assert st.toString() == 'Bar'
+     * assert st.size() == 3
+     * assert st.isEmpty() == false
+     * // stack out cases:
+     * assert st.peek() == 'r' as char
+     * assert st.pop() == 'r' as char
+     * assert st.toString() == 'Ba'
+     * assert st.peek() == 'a' as char
+     * assert st.pop() == 'a' as char
+     * assert st.toString() == 'B'
+     * assert st.size() == 1
+     * assert st.isEmpty() == false

Review Comment:
   StringBuilder#isEmpty comes with JDK15.



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