Spaces:
Build error
Build error
File size: 1,406 Bytes
d46f4a3 |
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 |
package com.mojang.math;
import com.google.common.annotations.VisibleForTesting;
import it.unimi.dsi.fastutil.ints.IntIterator;
import java.util.NoSuchElementException;
public class Divisor implements IntIterator {
private final int denominator;
private final int quotient;
private final int mod;
private int returnedParts;
private int remainder;
public Divisor(int p_254018_, int p_254504_) {
this.denominator = p_254504_;
if (p_254504_ > 0) {
this.quotient = p_254018_ / p_254504_;
this.mod = p_254018_ % p_254504_;
} else {
this.quotient = 0;
this.mod = 0;
}
}
@Override
public boolean hasNext() {
return this.returnedParts < this.denominator;
}
@Override
public int nextInt() {
if (!this.hasNext()) {
throw new NoSuchElementException();
} else {
int i = this.quotient;
this.remainder = this.remainder + this.mod;
if (this.remainder >= this.denominator) {
this.remainder = this.remainder - this.denominator;
i++;
}
this.returnedParts++;
return i;
}
}
@VisibleForTesting
public static Iterable<Integer> asIterable(int p_254381_, int p_254129_) {
return () -> new Divisor(p_254381_, p_254129_);
}
} |