Record Class Option.None<T>

java.lang.Object
java.lang.Record
org.jhotdraw8.icollection.impl.redblack.Option.None<T>
All Implemented Interfaces:
Iterable<T>, Option<T>, ReadOnlyCollection<T>
Enclosing interface:
Option<T>

public static record Option.None<T>() extends Record implements Option<T>
  • Constructor Details

    • None

      public None()
      Creates an instance of a None record class.
  • Method Details

    • size

      public int size()
      Description copied from interface: ReadOnlyCollection
      Returns the size of the collection.
      Specified by:
      size in interface ReadOnlyCollection<T>
      Returns:
      the size
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Option
      Returns true, if this is None, otherwise false, if this is Some.
      
       // Prints "false"
       System.out.println(Option.of(10).isEmpty());
      
       // Prints "true"
       System.out.println(Option.none().isEmpty());
       
      Specified by:
      isEmpty in interface Option<T>
      Specified by:
      isEmpty in interface ReadOnlyCollection<T>
      Returns:
      true, if this Option is empty, false otherwise
    • contains

      public boolean contains(Object o)
      Description copied from interface: ReadOnlyCollection
      Returns true if this collection contains the specified object.
      Specified by:
      contains in interface ReadOnlyCollection<T>
      Parameters:
      o - an object
      Returns:
      true if this collection contains the specified object
    • iterator

      public @NonNull Iterator<T> iterator()
      Description copied from interface: ReadOnlyCollection
      Returns an iterator over the elements in this collection.
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface ReadOnlyCollection<T>
      Returns:
      an iterator
    • orElse

      public @NonNull Option<T> orElse(@NonNull Option<? extends T> other)
      Description copied from interface: Option
      Returns this Option if it is nonempty, otherwise return the alternative.
      
       Option<String> other = Option.of("Other");
      
       // = Some("Hello World")
       Option.of("Hello World").orElse(other);
      
       // = Some("Other")
       Option.none().orElse(other);
       
      Specified by:
      orElse in interface Option<T>
      Parameters:
      other - An alternative Option
      Returns:
      this Option if it is nonempty, otherwise return the alternative.
    • get

      public T get()
      Description copied from interface: Option
      Gets the value if this is a Some or throws if this is a None.
      
       // Prints "57"
       System.out.println(Option.of(57).get());
      
       // Throws a NoSuchElementException
       Option.none().get();
       
      Specified by:
      get in interface Option<T>
      Returns:
      the value
    • orNull

      public @Nullable T orNull()
      Description copied from interface: Option
      Returns this Option if this is defined, or null if it is empty.
      
       // = Some("Hello World")
       Option.of("Hello World").orNull();
      
       // = null
       Option.none().orNull();
       
      Specified by:
      orNull in interface Option<T>
      Returns:
      this value if it is defined, or null if it is empty.
    • orThrow

      public T orThrow()
      Description copied from interface: Option
      Returns this Option if this is defined, or throws a NoSuchElementException if it is empty.
      
       // = Some("Hello World")
       Option.of("Hello World").orThrow();
      
       // = null
       Option.none().orThrow();
       
      Specified by:
      orThrow in interface Option<T>
      Returns:
      this value if it is defined, or null if it is empty.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.