001package functions.two;
002class NotDivn implements Predicate {
003        final private int n;
004        NotDivn(int n) {
005                this.n = n;
006        }
007        public boolean evaluate(int m) {
008                return (m%n) != 0;
009        }
010}
011
012class WhatAPain implements Stream{
013        private Stream it;
014
015        public WhatAPain(Stream it) {
016                this.it = it;
017        }
018
019        public int next() {
020                final int n = it.next();
021                final Predicate d = new NotDivn(n);
022                Stream newit = new FilteredStream(it, d);
023                it = newit;
024                return (n);
025        }
026}
027
028class Main2 {
029        public static void main(String[] args) {
030                IntStream I = new IntStream();
031                System.out.println(I.next());   // prints out 0 on the screen
032                System.out.println(I.next());   // prints out 1 on the screen
033
034                WhatAPain w = new WhatAPain(I);
035                System.out.println(w.next());
036                System.out.println(w.next());
037                System.out.println(w.next());
038                System.out.println(w.next());
039                System.out.println(w.next());
040                System.out.println(w.next());
041                System.out.println(w.next());
042                System.out.println(w.next());
043                System.out.println(w.next());
044                System.out.println(w.next());
045        }
046}
047
048