Class Optionals

java.lang.Object
com.comphenix.protocol.utility.Optionals

public final class Optionals extends Object
Utility methods for operating with Optionals
  • Constructor Details

    • Optionals

      public Optionals()
  • Method Details

    • or

      public static <T> Optional<T> or(Optional<T> primary, Supplier<Optional<T>> secondary)
      Chains two optionals together by returning the secondary optional if the primary does not contain a value
      Type Parameters:
      T - Type
      Parameters:
      primary - Primary optional
      secondary - Supplier of secondary optional
      Returns:
      The resulting optional
    • TestIfPresent

      public static <T> boolean TestIfPresent(Optional<T> optional, Predicate<T> predicate)
      Evaluates the provided predicate against the optional only if it is present
      Type Parameters:
      T - Type
      Parameters:
      optional - Optional
      predicate - Test to run against potential value
      Returns:
      True if the optional is present and the predicate passes
    • Equals

      public static <T> boolean Equals(Optional<T> optional, Class<?> contents)
      Check if the optional has a value and its value equals the provided value
      Type Parameters:
      T - Type
      Parameters:
      optional - Optional
      contents - Contents to test for
      Returns:
      True if the optional has a value and that value equals the parameter