Package org.organicdesign.fp.oneOf
Class OneOf2OrNone<A,B>
- java.lang.Object
-
- org.organicdesign.fp.oneOf.OneOf2OrNone<A,B>
-
public abstract class OneOf2OrNone<A,B> extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedOneOf2OrNone(java.lang.Object o, java.lang.Class<A> aClass, java.lang.Class<B> bClass, int index)Protected constructor for subclassing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object other)inthashCode()<R> Rmatch(Fn1<A,R> fa, Fn1<B,R> fb, Fn0<R> fz)Languages that have union types built in have a match statement that works like this method.java.lang.StringtoString()
-
-
-
Constructor Detail
-
OneOf2OrNone
protected OneOf2OrNone(java.lang.Object o, java.lang.Class<A> aClass, java.lang.Class<B> bClass, int index)Protected constructor for subclassing.- Parameters:
o- the item (may be null)aClass- class 0 (to have at runtime for descriptive error messages and toString()).bClass- class 1 (to have at runtime for descriptive error messages and toString()).index- 0 means this represents an A, 1 represents a B, 2 represents a None
-
-
Method Detail
-
match
public <R> R match(Fn1<A,R> fa, Fn1<B,R> fb, Fn0<R> fz)
Languages that have union types built in have a match statement that works like this method. Exactly one of these functions will be executed - determined by which type of item this object holds.- Parameters:
fa- the function to be executed if this OneOf stores the first type.fb- the function to be executed if this OneOf stores the second type.fz- the function to be executed if this OneOf stores a None.- Returns:
- the return value of whichever function is executed.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-