Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/ReadOnlyArrayList.java @ 22500:fbe1eb7b4172
Providing compatible implementation of List.toString
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 16 Dec 2015 12:31:17 +0100 |
parents | e70b20f4bb00 |
children | c81e7280af42 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/ReadOnlyArrayList.java Mon Dec 14 15:07:19 2015 +0100 +++ b/truffle/com.oracle.truffle.api.interop/src/com/oracle/truffle/api/interop/impl/ReadOnlyArrayList.java Wed Dec 16 12:31:17 2015 +0100 @@ -211,6 +211,25 @@ return new ReadOnlyArrayList<>(arr, first + fromIndex, first + toIndex); } + @Override + public String toString() { + Iterator<T> it = iterator(); + if (!it.hasNext()) { + return "[]"; + } + + StringBuilder sb = new StringBuilder(); + sb.append('['); + for (;;) { + T e = it.next(); + sb.append(e == this ? "(this Collection)" : e); + if (!it.hasNext()) { + return sb.append(']').toString(); + } + sb.append(',').append(' '); + } + } + private final class LI implements ListIterator<T>, Iterator<T> { private int index;