File size: 1,537 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
package net.minecraft.client.searchtree;

import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;
import java.util.Comparator;
import java.util.Iterator;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class MergingUniqueIterator<T> extends AbstractIterator<T> {
    private final PeekingIterator<T> firstIterator;
    private final PeekingIterator<T> secondIterator;
    private final Comparator<T> comparator;

    public MergingUniqueIterator(Iterator<T> p_235186_, Iterator<T> p_235187_, Comparator<T> p_235188_) {
        this.firstIterator = Iterators.peekingIterator(p_235186_);
        this.secondIterator = Iterators.peekingIterator(p_235187_);
        this.comparator = p_235188_;
    }

    @Override
    protected T computeNext() {
        boolean flag = !this.firstIterator.hasNext();
        boolean flag1 = !this.secondIterator.hasNext();
        if (flag && flag1) {
            return this.endOfData();
        } else if (flag) {
            return this.secondIterator.next();
        } else if (flag1) {
            return this.firstIterator.next();
        } else {
            int i = this.comparator.compare(this.firstIterator.peek(), this.secondIterator.peek());
            if (i == 0) {
                this.secondIterator.next();
            }

            return i <= 0 ? this.firstIterator.next() : this.secondIterator.next();
        }
    }
}