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

name.neuhalfen.projects.crypto.internal.Preconditions Maven / Gradle / Ivy

The newest version!
package name.neuhalfen.projects.crypto.internal;

import javax.annotation.Nullable;

/**
 * Idea borrowed from google guava.
 */
public final class Preconditions {

  /*
   * Prevent instantiation
   */
  private Preconditions() {
  }


  /**
   * 

Throw a IllegalArgumentException when 'expression' is false. *

* Call this function in methods to check parameters. *

* * @param expression expression that must be true, else the exception is raised * @param message message passed to the exception * * @throws IllegalArgumentException expression is false */ public static void checkArgument(boolean expression, @Nullable String message) { if (!expression) { throw new IllegalArgumentException(nonNullString(message)); } } /** *

Throw a IllegalArgumentException when 'expression' is false. *

* Call this function in methods to check parameters. *

* * @param expression expression that must be true, else the exception is raised * * @throws IllegalArgumentException expression is false */ public static void checkArgument(boolean expression) { if (!expression) { throw new IllegalArgumentException(); } } /** *

Throw a IllegalStateException when 'expression' is false. *

* Call this function in methods to check state. *

* * @param expression expression that must be true, else the exception is raised * @param message message passed to the exception * * @throws IllegalStateException expression is false */ public static void checkState(boolean expression, @Nullable String message) { if (!expression) { throw new IllegalStateException(nonNullString(message)); } } /** *

Throw a IllegalStateException when 'expression' is false. *

* Call this function in methods to check state. *

* * @param expression expression that must be true, else the exception is raised * * @throws IllegalStateException expression is false */ public static void checkState(boolean expression) { if (!expression) { throw new IllegalStateException(); } } private static String nonNullString(String string) { return (string == null) ? "" : string; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy