Class OptionalMod<T>


  • public final class OptionalMod<T>
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static OptionalMod<?> EMPTY  
      private java.lang.String modId  
      private boolean searched  
      private T value  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private OptionalMod​(boolean searched)  
      private OptionalMod​(java.lang.String modId)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T> OptionalMod<T> empty()  
      boolean equals​(java.lang.Object obj)  
      OptionalMod<T> filter​(java.util.function.Predicate<? super T> predicate)
      If a mod object is present, and the mod object matches the given predicate, return an OptionalMod describing the value, otherwise return an empty OptionalMod.
      <U> java.util.Optional<U> flatMap​(java.util.function.Function<? super T,​java.util.Optional<U>> mapper)
      If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional.
      T get()
      If a mod is present in this OptionalMod, returns the value, otherwise throws NoSuchElementException.
      java.lang.String getModId()  
      private T getValue()  
      int hashCode()  
      void ifPresent​(java.util.function.Consumer<? super T> consumer)
      If a mod object is present, invoke the specified consumer with the object, otherwise do nothing.
      boolean isPresent()
      Return true if there is a mod object present, otherwise false.
      <U> java.util.Optional<U> map​(java.util.function.Function<? super T,​? extends U> mapper)
      If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result.
      static <M> OptionalMod<M> of​(java.lang.String modId)  
      T orElse​(T other)
      Return the mod object if present, otherwise return other.
      T orElseGet​(java.util.function.Supplier<? extends T> other)
      Return the mod object if present, otherwise invoke other and return the result of that invocation.
      <X extends java.lang.Throwable>
      T
      orElseThrow​(java.util.function.Supplier<? extends X> exceptionSupplier)
      Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • modId

        private final java.lang.String modId
      • value

        private T value
      • searched

        private boolean searched
    • Constructor Detail

      • OptionalMod

        private OptionalMod​(boolean searched)
      • OptionalMod

        private OptionalMod​(java.lang.String modId)
    • Method Detail

      • of

        public static <M> OptionalMod<M> of​(java.lang.String modId)
      • getValue

        private T getValue()
      • get

        public T get()
        If a mod is present in this OptionalMod, returns the value, otherwise throws NoSuchElementException.
        Returns:
        the modobject held by this OptionalMod
        Throws:
        java.util.NoSuchElementException - if there is no modobject present
        See Also:
        Optional.isPresent()
      • getModId

        public java.lang.String getModId()
      • isPresent

        public boolean isPresent()
        Return true if there is a mod object present, otherwise false.
        Returns:
        true if there is a mod object present, otherwise false
      • ifPresent

        public void ifPresent​(java.util.function.Consumer<? super T> consumer)
        If a mod object is present, invoke the specified consumer with the object, otherwise do nothing.
        Parameters:
        consumer - block to be executed if a mod object is present
        Throws:
        java.lang.NullPointerException - if mod object is present and consumer is null
      • filter

        public OptionalMod<T> filter​(java.util.function.Predicate<? super T> predicate)
        If a mod object is present, and the mod object matches the given predicate, return an OptionalMod describing the value, otherwise return an empty OptionalMod.
        Parameters:
        predicate - a predicate to apply to the mod object, if present
        Returns:
        an OptionalMod describing the value of this OptionalMod if a mod object is present and the mod object matches the given predicate, otherwise an empty OptionalMod
        Throws:
        java.lang.NullPointerException - if the predicate is null
      • map

        public <U> java.util.Optional<U> map​(java.util.function.Function<? super T,​? extends U> mapper)
        If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional.
        Type Parameters:
        U - The type of the result of the mapping function
        Parameters:
        mapper - a mapping function to apply to the mod object, if present
        Returns:
        an Optional describing the result of applying a mapping function to the mod object of this OptionalMod, if a mod object is present, otherwise an empty Optional
        Throws:
        java.lang.NullPointerException - if the mapping function is null
      • flatMap

        public <U> java.util.Optional<U> flatMap​(java.util.function.Function<? super T,​java.util.Optional<U>> mapper)
        If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional. This method is similar to map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, flatMap does not wrap it with an additional Optional.
        Type Parameters:
        U - The type parameter to the Optional returned by
        Parameters:
        mapper - a mapping function to apply to the mod object, if present the mapping function
        Returns:
        the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is present, otherwise an empty Optional
        Throws:
        java.lang.NullPointerException - if the mapping function is null or returns a null result
      • orElse

        public T orElse​(T other)
        Return the mod object if present, otherwise return other.
        Parameters:
        other - the mod object to be returned if there is no mod object present, may be null
        Returns:
        the mod object, if present, otherwise other
      • orElseGet

        public T orElseGet​(java.util.function.Supplier<? extends T> other)
        Return the mod object if present, otherwise invoke other and return the result of that invocation.
        Parameters:
        other - a Supplier whose result is returned if no mod object is present
        Returns:
        the mod object if present otherwise the result of other.get()
        Throws:
        java.lang.NullPointerException - if mod object is not present and other is null
      • orElseThrow

        public <X extends java.lang.Throwable> T orElseThrow​(java.util.function.Supplier<? extends X> exceptionSupplier)
                                                      throws X extends java.lang.Throwable
        Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.
        Type Parameters:
        X - Type of the exception to be thrown
        Parameters:
        exceptionSupplier - The supplier which will return the exception to be thrown
        Returns:
        the present mod object
        Throws:
        X - if there is no mod object present
        java.lang.NullPointerException - if no mod object is present and exceptionSupplier is null
        X extends java.lang.Throwable
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object