-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCIterators.nrx
More file actions
executable file
·117 lines (89 loc) · 2.91 KB
/
Copy pathRCIterators.nrx
File metadata and controls
executable file
·117 lines (89 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env nr
/* NetRexx */
options replace format comments java symbols
import java.util.List
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
daysOfWeek = [ String 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]
coloursAry = [ String 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet' ]
coloursSz = coloursAry.length
coloursLst = LinkedList()
-- items appear to get added to the list if LIFO order
loop ix = coloursSz - 1 to 0 by -1
elmt = String coloursAry[ix]
coloursLst.add(elmt)
end ix
say
say "Show all elements"
show(daysOfWeek)
show(coloursLst)
say
list145 = LinkedList()
list145.add(Rexx 1)
list145.add(Rexx 4)
list145.add(Rexx 5)
dowIter = Arrays.stream(daysOfWeek).iterator
colIter = ColoursLst.iterator
say "Show elements 1, 4, & 5"
showSelected(dowIter, list145)
showSelected(colIter, list145)
say
dowListIter = Arrays.stream(daysOfWeek).toList.listIterator(daysOfWeek.length)
colListIter = ColoursLst.listIterator(ColoursLst.size)
say "Show elements 1, 4, & 5 from the end"
showSelectedReversed(dowListIter, list145)
showSelectedReversed(colListIter, list145)
say
return
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
method show(collection = String[]) private static
--say 'show(String[])'
output = Rexx ''
idx = 0
loop elmt over collection
output = output ''''elmt''''
idx = idx + 1
end elmt
say output
return
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
method show(collection = LinkedList) private static
--say 'show(LinkeList)'
output = Rexx ''
idx = 0
loop elmt over collection
output = output ''''elmt''''
idx = idx + 1
end elmt
say output
return
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
method showSelected(collIter = Iterator, slct = List) private static
--say 'showSelected(Iterator, List)'
output = Rexx ''
itmCt = 1
loop label iter_ while collIter.hasNext
if slct.contains(itmCt) then
output = output ''''collIter.next''''
else
collIter.next
itmCt = itmCt + 1
end iter_
say output
return
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
method showSelectedReversed(collIter = ListIterator, slct = List) private static
--say 'showSelectedReversed(ListIterator, List)'
output = Rexx ''
itmCt = 1
loop label iter_ while collIter.hasPrevious
if slct.contains(itmCt) then
output = output ''''collIter.previous''''
else
collIter.previous
itmCt = itmCt + 1
end iter_
say output
return
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8
-- . ... 1 ... ... 2 ... ... 3 ... ... 4 ... ... 5 ... ... 6 ... ... 7 ... ... 8