Skip to content

Commit

Permalink
feat(#710): fix the problem with sequence object elements counting
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Sep 19, 2024
1 parent a113da9 commit b4a0586
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.stream.Stream;
import org.cactoos.scalar.LengthOf;
import org.cactoos.scalar.Unchecked;
import org.xembly.Directive;
import org.xembly.Directives;

Expand Down Expand Up @@ -85,19 +88,25 @@ public Iterator<Directive> iterator() {
.attr("base", new EoFqn(String.format("seq%d", this.size())).fqn())
.attr("line", new Random().nextInt(Integer.MAX_VALUE))
.attr("name", this.name)
.append(
this.directives.stream()
.filter(Objects::nonNull)
.map(Directives::new)
.reduce(new Directives(), Directives::append)
).up().iterator();
.append(this.stream().reduce(new Directives(), Directives::append)).up().iterator();
}

/**
* Size of the sequence.
* @return Size.
*/
private int size() {
return this.directives.size();
private long size() {
return this.stream().count();
}

/**
* Stream of directives.
* @return Stream of directives.
*/
private Stream<Directives> stream() {
return this.directives.stream()
.filter(Objects::nonNull)
.filter(dirs -> new Unchecked<>(new LengthOf(dirs)).value() > 0)
.map(Directives::new);
}
}

1 comment on commit b4a0586

@0pdd
Copy link

@0pdd 0pdd commented on b4a0586 Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 710-f1d4fa80 discovered in src/main/java/org/eolang/jeo/representation/directives/JeoFqn.java) and submitted as #714. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.