001package org.clafer.collection;
002
003import org.clafer.common.Check;
004
005/**
006 * @param <A> the type of left
007 * @param <B> the type of right
008 * @author jimmy
009 */
010public class Left<A, B> extends Either<A, B> {
011
012    private final A value;
013
014    Left(A value) {
015        this.value = Check.notNull(value);
016    }
017
018    public A getValue() {
019        return value;
020    }
021
022    @Override
023    public boolean isLeft() {
024        return true;
025    }
026
027    @Override
028    public A getLeft() {
029        return value;
030    }
031
032    @Override
033    public boolean isRight() {
034        return false;
035    }
036
037    @Override
038    public B getRight() {
039        throw new UnsupportedOperationException("Left.getRight");
040    }
041
042    @Override
043    public boolean equals(Object obj) {
044        if (obj instanceof Left<?, ?>) {
045            Left<?, ?> other = (Left<?, ?>) obj;
046            return value.equals(other.value);
047        }
048        return false;
049    }
050
051    @Override
052    public int hashCode() {
053        return 11 * value.hashCode();
054    }
055
056    @Override
057    public String toString() {
058        return "Left" + value;
059    }
060}