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 Right<A, B> extends Either<A, B> { 011 012 private final B value; 013 014 Right(B value) { 015 this.value = Check.notNull(value); 016 } 017 018 public B getValue() { 019 return value; 020 } 021 022 @Override 023 public boolean isLeft() { 024 return false; 025 } 026 027 @Override 028 public A getLeft() { 029 throw new UnsupportedOperationException("Right.getLeft"); 030 } 031 032 @Override 033 public boolean isRight() { 034 return true; 035 } 036 037 @Override 038 public B getRight() { 039 return value; 040 } 041 042 @Override 043 public boolean equals(Object obj) { 044 if (obj instanceof Right<?, ?>) { 045 Right<?, ?> other = (Right<?, ?>) obj; 046 return value.equals(other.value); 047 } 048 return false; 049 } 050 051 @Override 052 public int hashCode() { 053 return 7 * value.hashCode(); 054 } 055 056 @Override 057 public String toString() { 058 return "Right " + value; 059 } 060}