1
1
mirror of https://github.com/thma/LtuPatternFactory.git synced 2025-01-05 19:04:46 +03:00

update example

This commit is contained in:
thma 2018-10-28 21:50:08 +01:00
parent 72eb79366d
commit 36ff7c6eb3

View File

@ -657,7 +657,7 @@ http://blog.ploeh.dk/2018/06/25/visitor-as-a-sum-type/
## Iterator -> Traversable
> [...] the iterator pattern is a design pattern in which an iterator is used to traverse a container and access the container's elements. The iterator pattern decouples algorithms from containers; in some cases, algorithms are necessarily container-specific and thus cannot be decoupled.
> [...] the iter pattern is a design pattern in which an iter is used to traverse a container and access the container's elements. The iter pattern decouples algorithms from containers; in some cases, algorithms are necessarily container-specific and thus cannot be decoupled.
> [Quoted from Wikipedia] (https://en.wikipedia.org/wiki/Iterator_pattern)
@ -666,9 +666,8 @@ http://blog.ploeh.dk/2018/06/25/visitor-as-a-sum-type/
private static int[] wordCountIterator(String str) {
int nl=0, nw=0, nc=0;
boolean readingWord = false;
Iterator<Character> iterator = str.chars().mapToObj(c -> (char) c).collect(Collectors.toList()).iterator();
while (iterator.hasNext()) {
Character c = iterator.next();
for (Iterator<Character> iter = getIteratorFor(str); iter.hasNext();) {
Character c = iter.next();
nc++;
if (c == '\n') {
nl++;
@ -682,6 +681,10 @@ private static int[] wordCountIterator(String str) {
}
return new int[]{nl,nw,nc};
}
private static Iterator<Character> getIteratorFor(String str) {
return str.chars().mapToObj(c -> (char) c).collect(Collectors.toList()).iterator();
}
```
```java