paulk-asert commented on code in PR #2215: URL: https://github.com/apache/groovy/pull/2215#discussion_r2077668278
########## 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: Since Groovy 5 is JDK11+, I would recommend removing isEmpty() calls from the javadoc test. They could be placed in separate test with an appropriate version guard. -- 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