Package org.javimmutable.collections
Class NotNull<T>
java.lang.Object
org.javimmutable.collections.NotNull<T>
- All Implemented Interfaces:
- Serializable,- Iterable<T>,- IStreamable<T>,- SplitableIterable<T>
Used to handle cases when a value may or may not exist and to eliminate the use of
 null values.  The value of a 
NotNull cannot be null.
 Provides a variety of utility methods to allow call chaining.- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionInvokes absentAction if this is empty.Invokes presentAction with this value if this is full.applyThrows(Proc0Throws<E> absentAction) Invokes absentAction if this is empty.applyThrows(Proc1Throws<? super T, E> presentAction) Invokes presentAction with this value if this is full.static <T> NotNull<T> Determine if the object is an instance of the specified Class or a subclass.static <T> NotNull<T> empty()Returns aNotNullwith no value.static <T> NotNull<T> Returns aNotNullcontaining the first value of the collection.static <T> NotNull<T> Returns aNotNullcontaining the first value of the collection for which the predicate returns true.abstract <A> NotNull<A> Produce aNotNullbased on this one.Produce aNotNullbased on this one.abstract <A> NotNull<A> Produce aNotNullbased on this one.flatMapThrows(Func0Throws<NotNull<A>, E> absentMapping, Func1Throws<? super T, NotNull<A>, E> presentMapping) Produce aNotNullbased on this one.flatMapThrows(Func0Throws<NotNull<T>, E> absentMapping) Produce aNotNullbased on this one.flatMapThrows(Func1Throws<? super T, NotNull<A>, E> presentMapping) Produce aNotNullbased on this one.abstract TGets this value.abstract TGets this value.abstract TGets this value.abstract booleanisEmpty()Returns true if this has no valueabstract booleanisFull()Returns true if this has a valueProduce a fullNotNull.abstract <U> NotNull<U> Produce a fullNotNull.abstract <U> NotNull<U> Produce aNotNullthat is empty if this is empty or else contains the result of passing this value to the given mapping function.mapThrows(Func0Throws<? extends T, E> absentMapping) Produce a fullNotNull.mapThrows(Func0Throws<? extends U, E> absentMapping, Func1Throws<? super T, ? extends U, E> presentMapping) Produce a fullNotNull.mapThrows(Func1Throws<? super T, ? extends U, E> presentMapping) Produce aNotNullthat is empty if this is empty or else contains the result of passing this value to the given mapping function.abstract <U> UGets a value based on this value.abstract <U> UGets a value based on this value.abstract <U,E extends Exception> 
 UmatchOrThrows(Func0Throws<U, E> absentMapping, Func1Throws<? super T, U, E> presentMapping) Gets a value based on this value.abstract <U,E extends Exception> 
 UmatchThrows(U absentValue, Func1Throws<? super T, U, E> presentMapping) Gets a value based on this value.maybe()If this empty returnsMaybe.empty(), otherwise returnsMaybe.of(T).static <T> NotNull<T> of(T valueOrNull) Returns aNotNullcontaining the value.Returns this if this is full and predicate returns false.Returns this if this is full and predicate returns true.abstract TGets this value.Gets this value.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.javimmutable.collections.IStreamablegetSpliteratorCharacteristics, iterator, parallelStream, spliterator, streamMethods inherited from interface org.javimmutable.collections.SplitableIterableforEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
- 
Method Details- 
empty
- 
ofReturns aNotNullcontaining the value. Null is treated as empty.
- 
castDetermine if the object is an instance of the specified Class or a subclass. If the object is null, returns aNotNullcontaining null. If the object is not null but not of the correct class, returns an empty Holder. Otherwise returns a Holder containing the value cast to the target type.- Type Parameters:
- T- type of the class
- Parameters:
- klass- class to cast the object to
- valueOrNull- object to be case
- Returns:
- a NotNull
 
- 
first
- 
first
- 
maybeIf this empty returnsMaybe.empty(), otherwise returnsMaybe.of(T).
- 
mapProduce a fullNotNull. If thisNotNullis full it is returned. Otherwise the absentMapping function is called to provide a value for the resultNotNull.- Parameters:
- absentMapping- produces value if this is empty
- Returns:
- a full NotNull
 
- 
mapProduce aNotNullthat is empty if this is empty or else contains the result of passing this value to the given mapping function.- Parameters:
- presentMapping- maps this value to new value
- Returns:
- a possibly empty NotNull
 
- 
map@Nonnull public abstract <U> NotNull<U> map(@Nonnull Func0<? extends U> absentMapping, @Nonnull Func1<? super T, ? extends U> presentMapping) Produce a fullNotNull. If this is empty the absentMapping function is called to provide a value. Otherwise the presentMapping function is called to produce a new value based on this value.- Parameters:
- absentMapping- produces value when this is empty
- presentMapping- maps this value to new value
- Returns:
- a full NotNull
 
- 
mapThrows@Nonnull public abstract <E extends Exception> NotNull<T> mapThrows(@Nonnull Func0Throws<? extends T, E> absentMapping) throws EProduce a fullNotNull. If thisNotNullis full it is returned. Otherwise the absentMapping function is called to provide a value for the resultNotNull.- Parameters:
- absentMapping- produces value if this is empty
- Returns:
- a full NotNull
- Throws:
- E
 
- 
mapThrows@Nonnull public abstract <U,E extends Exception> NotNull<U> mapThrows(@Nonnull Func1Throws<? super T, ? extends U, throws EE> presentMapping) Produce aNotNullthat is empty if this is empty or else contains the result of passing this value to the given mapping function.- Parameters:
- presentMapping- maps this value to new value
- Returns:
- a possibly empty NotNull
- Throws:
- E
 
- 
mapThrows@Nonnull public abstract <U,E extends Exception> NotNull<U> mapThrows(@Nonnull Func0Throws<? extends U, E> absentMapping, @Nonnull Func1Throws<? super T, throws E? extends U, E> presentMapping) Produce a fullNotNull. If this is empty the absentMapping function is called to provide a value. Otherwise the presentMapping function is called to produce a new value based on this value.- Parameters:
- absentMapping- produces value when this is empty
- presentMapping- maps this value to new value
- Returns:
- a full NotNull
- Throws:
- E
 
- 
flatMap
- 
flatMap@Nonnull public abstract <A> NotNull<A> flatMap(@Nonnull Func1<? super T, NotNull<A>> presentMapping) 
- 
flatMap@Nonnull public abstract <A> NotNull<A> flatMap(@Nonnull Func0<NotNull<A>> absentMapping, @Nonnull Func1<? super T, NotNull<A>> presentMapping) 
- 
flatMapThrows@Nonnull public abstract <E extends Exception> NotNull<T> flatMapThrows(@Nonnull Func0Throws<NotNull<T>, E> absentMapping) throws E
- 
flatMapThrows@Nonnull public abstract <A,E extends Exception> NotNull<A> flatMapThrows(@Nonnull Func1Throws<? super T, NotNull<A>, throws EE> presentMapping) 
- 
flatMapThrows@Nonnull public abstract <A,E extends Exception> NotNull<A> flatMapThrows(@Nonnull Func0Throws<NotNull<A>, E> absentMapping, @Nonnull Func1Throws<? super T, throws ENotNull<A>, E> presentMapping) 
- 
select@Nonnull public abstract NotNull<T> select(@Nonnull java.util.function.Predicate<? super T> predicate) Returns this if this is full and predicate returns true. Otherwise an emptyNotNullis returned.- Parameters:
- predicate- determines whether to accept this value
- Returns:
- a NotNull
 
- 
reject@Nonnull public abstract NotNull<T> reject(@Nonnull java.util.function.Predicate<? super T> predicate) Returns this if this is full and predicate returns false. Otherwise an emptyNotNullis returned.- Parameters:
- predicate- determines whether to reject this value
- Returns:
- a NotNull
 
- 
applyInvokes absentAction if this is empty.- Parameters:
- absentAction- action to call if this is empty
- Returns:
- this
 
- 
applyInvokes presentAction with this value if this is full.- Parameters:
- presentAction- action to call if this is full
- Returns:
- this
 
- 
applyThrows@Nonnull public abstract <E extends Exception> NotNull<T> applyThrows(@Nonnull Proc0Throws<E> absentAction) throws E Invokes absentAction if this is empty.- Parameters:
- absentAction- action to call if this is empty
- Returns:
- this
- Throws:
- E
 
- 
applyThrows@Nonnull public abstract <E extends Exception> NotNull<T> applyThrows(@Nonnull Proc1Throws<? super T, E> presentAction) throws EInvokes presentAction with this value if this is full.- Parameters:
- presentAction- action to call if this is full
- Returns:
- this
- Throws:
- E
 
- 
unsafeGetGets this value. Throws NoSuchElementException if this is empty.- Returns:
- this value
- Throws:
- NoSuchElementException- if this is empty
 
- 
unsafeGetpublic abstract <E extends Exception> T unsafeGet(@Nonnull Func0<E> absentExceptionMapping) throws E Gets this value. Calls absentExceptionMapping to get an exception to throw if this is empty.- Returns:
- this value
- Throws:
- E- an exception produced by mapping if this is empty
 
- 
getGets this value. If this is empty returns absentValue instead.- Parameters:
- absentValue- value to return if this is empty
 
- 
getOrNullGets this value. If this is empty returns null.
- 
getOrGets this value. If this is empty returns result of calling absentMapping instead.- Parameters:
- absentMapping- function to generate value to return if this is empty
 
- 
matchGets a value based on this value. If this is empty absentValue is returned. Otherwise this value is passed to presentMapping to obtain a return value.- Parameters:
- absentValue- value to return if this is empty
- presentMapping- function to map this value into return value
- Returns:
- a value
 
- 
matchOrpublic abstract <U> U matchOr(@Nonnull Func0<U> absentMapping, @Nonnull Func1<? super T, U> presentMapping) Gets a value based on this value. If this is empty absentMapping is called to obtain a return value. Otherwise this value is passed to presentMapping to obtain a return value.- Parameters:
- absentMapping- function to produce a value to return if this is empty
- presentMapping- function to map this value into return value
- Returns:
- a value
 
- 
matchThrowspublic abstract <U,E extends Exception> U matchThrows(U absentValue, @Nonnull Func1Throws<? super T, U, throws EE> presentMapping) Gets a value based on this value. If this is empty absentValue is returned. Otherwise this value is passed to presentMapping to obtain a return value.- Parameters:
- absentValue- value to return if this is empty
- presentMapping- function to map this value into return value
- Returns:
- a value
- Throws:
- E
 
- 
matchOrThrowspublic abstract <U,E extends Exception> U matchOrThrows(@Nonnull Func0Throws<U, E> absentMapping, @Nonnull Func1Throws<? super T, throws EU, E> presentMapping) Gets a value based on this value. If this is empty absentMapping is called to obtain a return value. Otherwise this value is passed to presentMapping to obtain a return value.- Parameters:
- absentMapping- function to produce a value to return if this is empty
- presentMapping- function to map this value into return value
- Returns:
- a value
- Throws:
- E
 
- 
isEmptypublic abstract boolean isEmpty()Returns true if this has no value
- 
isFullpublic abstract boolean isFull()Returns true if this has a value
 
-