22
|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util;
|
|
2
|
|
3 public class DefaultEither<A,B> implements Either<A,B>
|
|
4 {
|
|
5 private final A theA;
|
|
6 private final B theB;
|
|
7
|
23
|
8 private DefaultEither(A _theA,B _theB)
|
22
|
9 {
|
|
10 theA = _theA;
|
23
|
11 theB = _theB;
|
|
12 }
|
|
13
|
|
14 public static final <A,B> DefaultEither<A,B> newA(A _theA)
|
|
15 {
|
|
16 return new DefaultEither<A,B>(_theA,null);
|
|
17 }
|
|
18
|
|
19 public static final <A,B> DefaultEither<A,B> newB(B _theB)
|
|
20 {
|
|
21 return new DefaultEither<A,B>(null,_theB);
|
22
|
22 }
|
|
23
|
|
24 @Override
|
|
25 public A a()
|
|
26 {
|
|
27 return theA;
|
|
28 }
|
|
29
|
|
30 @Override
|
|
31 public boolean isA()
|
|
32 {
|
39
|
33 return theA != null;
|
22
|
34 }
|
|
35
|
|
36 @Override
|
|
37 public B b()
|
|
38 {
|
|
39 return theB;
|
|
40 }
|
|
41
|
|
42 @Override
|
|
43 public boolean isB()
|
|
44 {
|
39
|
45 return theB != null;
|
22
|
46 }
|
|
47 }
|