Class OptionalFloat

java.lang.Object
net.apartium.cocoabeans.utils.OptionalFloat

public final class OptionalFloat extends Object
A java optional like wrapper class for float primitive type
See Also:
  • Method Details

    • empty

      public static OptionalFloat empty()
      Retrieves a global empty OptionalFloat instance
      Returns:
      a global empty OptionalFloat instance
      See Also:
    • of

      public static OptionalFloat of(float val)
      Creates a new OptionalFloat instance consisting of given value
      Parameters:
      val - value
      Returns:
      a new OptionalFloat instance
    • isEmpty

      public boolean isEmpty()
      Checks whether current instance is empty.
      Returns:
      true if empty, otherwise false
    • getAsFloat

      public float getAsFloat()
      Retrieves current value as float, or throws an exception if empty
      Returns:
      current float value
    • ifPresent

      public void ifPresent(FloatConsumer consumer)
      Executes given consumer if current instance is not empty
      Parameters:
      consumer - given consumer action
    • getOrThrow

      public float getOrThrow(Supplier<RuntimeException> exceptionSupplier)
      Retrieves current value, or throws given exception if nul
      Parameters:
      exceptionSupplier - exception supplier
      Returns:
      float value
      Throws:
      RuntimeException - exceptionSupplier if empty
    • filter

      public OptionalFloat filter(FloatPredicate predicate)
      Filters given instance. Given predicate will not invoke if current instance is empty
      Parameters:
      predicate - if given predicate returns true, return the current instance, if false returns empty instance
      Returns:
      See Also:
    • mapToObj

      public <E> Optional<E> mapToObj(FloatToObject<E> operation)
      Maps current value to an object. If empty, will return empty optional instance.
      Type Parameters:
      E - object element type
      Parameters:
      operation - mapping operation
      Returns:
      mapped value
    • orElse

      public float orElse(float f)
      Returns current value, or given value if empty
      Parameters:
      f - value to return if current value is empty
      Returns:
      current value, or given value if empty
    • orElseGet

      public float orElseGet(FloatSupplier supplier)
      Attempts to return current value, but if this instance is empty retrieves value from given supplier
      Parameters:
      supplier - supplier to be used if current instance is empty
      Returns:
      float value
    • isPresent

      public boolean isPresent()
      Returns:
      true if current instance is not empty, else false
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object