Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
22499:9bba3a7b34be | 22500:fbe1eb7b4172 |
---|---|
209 @Override | 209 @Override |
210 public List<T> subList(int fromIndex, int toIndex) { | 210 public List<T> subList(int fromIndex, int toIndex) { |
211 return new ReadOnlyArrayList<>(arr, first + fromIndex, first + toIndex); | 211 return new ReadOnlyArrayList<>(arr, first + fromIndex, first + toIndex); |
212 } | 212 } |
213 | 213 |
214 @Override | |
215 public String toString() { | |
216 Iterator<T> it = iterator(); | |
217 if (!it.hasNext()) { | |
218 return "[]"; | |
219 } | |
220 | |
221 StringBuilder sb = new StringBuilder(); | |
222 sb.append('['); | |
223 for (;;) { | |
224 T e = it.next(); | |
225 sb.append(e == this ? "(this Collection)" : e); | |
226 if (!it.hasNext()) { | |
227 return sb.append(']').toString(); | |
228 } | |
229 sb.append(',').append(' '); | |
230 } | |
231 } | |
232 | |
214 private final class LI implements ListIterator<T>, Iterator<T> { | 233 private final class LI implements ListIterator<T>, Iterator<T> { |
215 private int index; | 234 private int index; |
216 | 235 |
217 public LI(int index) { | 236 public LI(int index) { |
218 this.index = index; | 237 this.index = index; |