All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nulabinc.backlog4j.core.Union Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
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