#modulo java error
18 messages · Page 1 of 1 (latest)
public final class ModuloFilterPipe extends Pipe{
private final int divisor;
private Integer nextInt;
public ModuloFilterPipe(Pipe feedingPipe, int divisor){
super(feedingPipe);
this.divisor = divisor;
this.nextInt = null;
}
public boolean hasNextInteger() {
while(this.getFeedingPipe().hasNextInteger()) {/* delegate the logic to the feeding pipe, because this one would not know */
this.nextInt = this.getFeedingPipe().nextInteger();
if((this.nextInt % this.divisor) == 0) {
return true;
}
}
return false;
}
public Integer nextInteger() {
Integer result = null;
if(this.nextInt != null) {
result = this.nextInt; /* pull the value from the feeding pipe, and apply the operation */
}else {
while(this.getFeedingPipe().hasNextInteger()) {
nextInt = this.getFeedingPipe().nextInteger();
if((nextInt % this.divisor) == 0) {
result = nextInt;
}
}
}
return result;
}
}
hasNextInteger shouldn't modify the state ig
what does that mean
i have to gitve it back in hasNextInteger
I meant hasNextInteger should probably not have side affects/modify anything