view src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/DefaultEither.java @ 0:44465893e8b8

first Commit
author Kazuma
date Wed, 30 Nov 2016 01:47:55 +0900
parents
children
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.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;
	}

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

	@Override
	public boolean isB()
	{
		return theB != null;
	}
}