com.nulabinc.backlog4j.core.Union Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of backlog4j Show documentation
Show all versions of backlog4j Show documentation
Backlog4j is a Backlog binding library for Java.
package com.nulabinc.backlog4j.core;
import java.security.InvalidParameterException;
/**
* @author nulab-inc
*/
public class Union {
private T1 t1;
private T2 t2;
private Union(T1 t1, T2 t2) {
this.t1 = t1;
this.t2 = t2;
}
public String toString() {
if (this.t1 != null) {
return this.t1.toString();
} else {
return this.t2.toString();
}
}
public Optional left() {
return Optional.ofNullable(this.t1);
}
public Optional right() {
return Optional.ofNullable(this.t2);
}
public static Union left(T t1) throws InvalidParameterException {
if (t1 == null) {
throw new InvalidParameterException("value can't be null");
} else {
return new Union(t1, null);
}
}
public static Union right(U t2) throws InvalidParameterException {
if (t2 == null) {
throw new InvalidParameterException("value can't be null");
} else {
return new Union(null, t2);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy