package net.emaze.dysfunctional.ranges;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.BinaryOperator;
import net.emaze.dysfunctional.order.SequencingPolicy;

/**
 * {@code A ∪ B}.
 *
 * @author rferranti
 */
public class Union<T> implements BinaryOperator<Range<T>> {

    private final SequencingPolicy<T> sequencer;
    private final Comparator<Optional<T>> comparator;
    private final T emptyValue;

    public Union(SequencingPolicy<T> sequencer, Comparator<Optional<T>> comparator, T emptyValue) {
        this.sequencer = sequencer;
        this.comparator = comparator;
        this.emptyValue = emptyValue;
    }

    @Override
    public Range<T> apply(Range<T> lhs, Range<T> rhs) {
        final List<DenseRange<T>> ranges = new ArrayList<DenseRange<T>>();
        ranges.addAll(lhs.densified());
        ranges.addAll(rhs.densified());
        final Densify<T> densifier = new Densify<T>(sequencer, comparator);
        return new MakeRange<T>(sequencer, comparator, emptyValue).apply(densifier.apply(ranges));
    }
}

@@ -55,96 +55,9 @@
 til.
-ArrayList;%0Aimport java.util.Comparator;%0Aimport java.util.List;%0Aimport java.util.Optional
+*
 ;%0Aim
@@ -749,26 +749,13 @@
 ist%3C
-DenseRange%3CT%3E
 %3E();%0A
+
     
@@ -834,84 +834,8 @@
 ));%0A
-        final Densify%3CT%3E densifier = new Densify%3CT%3E(sequencer, comparator);%0A
     
@@ -859,17 +859,16 @@
 keRange%3C
-T
 %3E(sequen
@@ -906,32 +906,15 @@
 ply(
-densifier.apply(
 ranges)
-)
 ;%0A  

remove some useless code