Libraryless. Click here for Pure Java version (2780L/16K).
1 | static <A> Chain<A> toChain(Iterable<A> l) {
|
2 | Iterator<A> it = iterator(l); |
3 | if (!it.hasNext()) null; |
4 | Chain<A> c = new(it.next()); |
5 | Chain<A> last = c; |
6 | int size = 1; |
7 | while (it.hasNext()) {
|
8 | ++size; |
9 | Chain x = new(it.next()); |
10 | last.next = x; |
11 | last = x; |
12 | } |
13 | |
14 | // update sizes and return |
15 | |
16 | Chain<A> x = c; |
17 | while (x != null) {
|
18 | x.size = size--; |
19 | x = x.next; |
20 | } |
21 | ret c; |
22 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1030890 |
| Snippet name: | toChain |
| Eternal ID of this version: | #1030890/2 |
| Text MD5: | 073289eec4dcdc2bfd022f86d8e1728d |
| Transpilation MD5: | 7cfd9b7fdbc6976b606a4178592b6af4 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-04-06 13:14:11 |
| Source code size: | 423 bytes / 22 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 378 / 491 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |