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

org.jetbrains.java.decompiler.util.Either Maven / Gradle / Ivy

Go to download

Modern Java & JVM language decompiler aiming to be as accurate as possible, with an emphasis on output quality.

The newest version!
package org.jetbrains.java.decompiler.util;

import java.util.function.Consumer;

public final class Either {
  private final L left;
  private final R right;

  private Either(L left, R right) {
    this.left = left;
    this.right = right;
  }

  public static  Either left(L left) {
    return new Either<>(left, null);
  }

  public static  Either right(R right) {
    return new Either<>(null, right);
  }

  public void map(Consumer ifLeft, Consumer ifRight) {
    checkInvariants();

    if (left != null) {
      ifLeft.accept(left);
    }

    if (right != null) {
      ifRight.accept(right);
    }
  }

  private void checkInvariants() {
    if (left == null && right == null) {
      throw new IllegalStateException("Either is empty!");
    }

    if (left != null && right != null) {
      throw new IllegalStateException("Either is full!");
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy