Class LazyImpl<T>
- Type Parameters:
T- The type of the value for this instance ofLazy.
- All Implemented Interfaces:
Lazy<T>
The implementation of the interface
Lazy.
An instance of this class holds a value that will be initialised by a
call to the supplier (provided with the constructor
LazyImpl(Supplier))
on a first call to
get().
For special purposes, the constructor
LazyImpl(Object)
creates an already initialised instance of Lazy.
Use
isPresent()
to avoid unnecessary initialisation.
As a lazy initialisation makes the value unpredictable, it is necessary
that the implementations of
equals(Object)
and
hashCode()
force the initialisation.
toString() do not force the initialisation.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: LazyImpl.java 1060 2023-09-24 19:21:40Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.lang.internal.LazyImpl"
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal Tget()Returns the value for this instance ofLazy.final inthashCode()final booleanChecks whether thisLazyinstance has been initialised already.orElseThrow(Supplier<? extends X> exceptionSupplier) Returns the value or throws the exception that is created by the givenSupplierwhen not yet initialised.final StringtoString()Methods inherited from interface Lazy
getAsString, getAsString, ifPresent, map
-
Field Details
-
m_Lock
-
m_Supplier
The supplier for the value of thisLazyinstance. It will be set tonullafterm_Valueis initialised. -
m_Value
-
-
Constructor Details
-
LazyImpl
-
LazyImpl
-
-
Method Details
-
equals
-
get
-
hashCode
-
isPresent
Checks whether this
Lazyinstance has been initialised already. But even it was initialised,Lazy.get()may still returnnull. -
orElseThrow
Returns the value or throws the exception that is created by the givenSupplierwhen not yet initialised.- Specified by:
orElseThrowin interfaceLazy<T>- Type Parameters:
X- The type of the implementation ofThrowable.- Parameters:
exceptionSupplier- The supplier for the exception to throw when the instance was not yet initialised.- Returns:
- The value.
- Throws:
X- When not initialised, the exception created by the given supplier will be thrown.
-
toString
-
