// 
// Decompiled by Procyon v0.6.0
// 

package org.bson.codecs.pojo;

import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import org.bson.assertions.Assertions;

final class Either<L, R>
{
    private final L left;
    private final R right;
    
    public static <L, R> Either<L, R> left(final L value) {
        return new Either<L, R>(Assertions.notNull("value", value), null);
    }
    
    public static <L, R> Either<L, R> right(final R value) {
        return new Either<L, R>(null, Assertions.notNull("value", value));
    }
    
    private Either(final L l, final R r) {
        this.left = l;
        this.right = r;
    }
    
    public <T> T map(final Function<? super L, ? extends T> lFunc, final Function<? super R, ? extends T> rFunc) {
        return (this.left != null) ? lFunc.apply(this.left) : rFunc.apply(this.right);
    }
    
    public void apply(final Consumer<? super L> lFunc, final Consumer<? super R> rFunc) {
        if (this.left != null) {
            lFunc.accept(this.left);
        }
        if (this.right != null) {
            rFunc.accept(this.right);
        }
    }
    
    @Override
    public String toString() {
        return "Either{left=" + this.left + ", right=" + this.right + '}';
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final Either<?, ?> either = (Either<?, ?>)o;
        return Objects.equals(this.left, either.left) && Objects.equals(this.right, either.right);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.left, this.right);
    }
}
