Package javascalautils
Class None<T>
- java.lang.Object
-
- javascalautils.None<T>
-
- Type Parameters:
T
- The type of the value represented by this instance
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<T>
,Option<T>
public final class None<T> extends java.lang.Object implements Option<T>, java.io.Serializable
Represents an emptyOption
.
TheNone
is a replacement fornull
values representing a non-existing value.
One can considerNone
as a collection of size 0.
Instances of None should not be created directly, rather use the factory methods provided onOption
. SinceNone
anyways cannot represent a value it is preferable to use it as a singleton saving unnecessary instance creation.
For examples on usage refer to the documentation forOption
.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface javascalautils.Option
DEFAULT_NONE
-
-
Constructor Summary
Constructors Constructor Description None()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
boolean
exists(java.util.function.Predicate<T> predicate)
Always returnsfalse
.<R> Option<R>
flatMap(ThrowableFunction1<T,Option<R>> function)
Always returnsthis
.T
get()
Always throwsNoSuchElementException
since None cannot per definition hold any value.T
getOrElse(java.util.function.Supplier<T> supplier)
Always the value provided by the supplier.int
hashCode()
Always returns0
as None is stateless and has no value.java.util.Iterator<T>
iterator()
Always returns an empty iterator.<R> Option<R>
map(ThrowableFunction1<T,R> function)
Always returnsthis
.Option<T>
orElse(java.util.function.Supplier<Option<T>> supplier)
Always the value provided by the supplier.java.util.stream.Stream<T>
stream()
Always returns an empty stream.<R> Either<T,R>
toLeft(java.util.function.Supplier<R> right)
Returns aRight
containing the value from the provided supplier.<L> Either<L,T>
toRight(java.util.function.Supplier<L> left)
Returns aLeft
containing the value from the provided supplier.java.lang.String
toString()
Returns a String representation of the instance.
-
-
-
Method Detail
-
get
public T get()
Always throwsNoSuchElementException
since None cannot per definition hold any value.
-
getOrElse
public T getOrElse(java.util.function.Supplier<T> supplier)
Always the value provided by the supplier.
-
exists
public boolean exists(java.util.function.Predicate<T> predicate)
-
map
public <R> Option<R> map(ThrowableFunction1<T,R> function)
-
flatMap
public <R> Option<R> flatMap(ThrowableFunction1<T,Option<R>> function)
-
orElse
public Option<T> orElse(java.util.function.Supplier<Option<T>> supplier)
Always the value provided by the supplier.
-
toLeft
public <R> Either<T,R> toLeft(java.util.function.Supplier<R> right)
Returns aRight
containing the value from the provided supplier.
-
toRight
public <L> Either<L,T> toRight(java.util.function.Supplier<L> left)
Returns aLeft
containing the value from the provided supplier.
-
equals
public boolean equals(java.lang.Object other)
Returnstrue
if other is aNone
asNone
is stateless comparing it to some other None is therefore always the same,false
otherwise.- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- The other object to compare to- Returns:
true
if other isNone
,false
otherwise- Since:
- 1.0
-
hashCode
public int hashCode()
Always returns0
as None is stateless and has no value.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- 0
- Since:
- 1.0
-
toString
public java.lang.String toString()
Returns a String representation of the instance.- Overrides:
toString
in classjava.lang.Object
- Since:
- 1.0
-
iterator
public final java.util.Iterator<T> iterator()
Always returns an empty iterator.- Specified by:
iterator
in interfacejava.lang.Iterable<T>
- Returns:
- An empty iterator
- Since:
- 1.0
-
stream
public final java.util.stream.Stream<T> stream()
Always returns an empty stream.- Returns:
- An empty stream
- Since:
- 1.0
-
-