view src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/util/DefaultEither.java @ 23:3ef2a66a8c5d

commit
author Shoshi TAMAKI
date Thu, 10 Jan 2013 23:22:42 +0900
parents 9fd57b7c6adb
children 7d78bbf4a9cd
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util;

public class DefaultEither<A,B> implements Either<A,B>
{
	private final A theA;
	private final B theB;
	
	private DefaultEither(A _theA,B _theB)
	{
		theA = _theA;
		theB = _theB;
	}
	
	public static final <A,B> DefaultEither<A,B> newA(A _theA)
	{
		return new DefaultEither<A,B>(_theA,null);
	}
	
	public static final <A,B> DefaultEither<A,B> newB(B _theB)
	{
		return new DefaultEither<A,B>(null,_theB);
	}

	@Override
	public A a()
	{
		return theA;
	}

	@Override
	public boolean isA()
	{
		return (theA == null) ? true : false;
	}

	@Override
	public B b()
	{
		return theB;
	}

	@Override
	public boolean isB()
	{
		return (theB == null) ? true : false;
	}
}