lucee.Componentmodels.Optional
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value. Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a block of code if the value is present). See https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html
Property Summary | ||||
---|---|---|---|---|
type | property | default | serializable | required |
any
|
jOptional
The Java Builder we represent.
|
true
|
false
|
Constructor Summary | |
---|---|
init([any optional])
Construct a CFML Optional out of the Java Optional. |
Method Summary | |
---|---|
Optional
|
$or(any supplier)
If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function. |
Optional
|
$or(any supplier)
If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function. |
Optional
|
empty()
Build an empty optional out. |
Optional
|
filter(any predicate)
If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional. |
any
|
get()
If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException. |
string
|
getJOptional()
|
any
|
getNativeType([any results])
Return a native CF type from incoming Java type. |
private any
|
getValueFromOptional()
Verify if the optional is of a certain primitive type and call the appropriate function to return it's value. |
numeric
|
hashCode()
Returns the hash code value of the present value, if any, or 0 (zero) if no value is present. |
void
|
ifPresent(any consumer)
If a value is present, invoke the specified consumer with the value, otherwise do nothing. |
void
|
ifPresentOrElse(any consumer, any runnable)
If a value is present, performs the given action with the value, otherwise performs the given empty-based action. |
boolean
|
isEmpty()
Return true if there is no value present, otherwise false. |
boolean
|
isEqual(any obj)
Indicates whether some other object is "equal to" this Optional. |
boolean
|
isPresent()
Return true if there is a value present, otherwise false. |
Optional
|
map(any mapper)
If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. |
Optional
|
of(any value)
Returns an Optional with the specified present non-null value. |
Optional
|
ofNullable([any value])
Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. |
any
|
orElse(any other)
Return the value if present, otherwise return other. |
any
|
orElseGet(any other)
Return the value if present, otherwise invoke other and return the result of that invocation. |
Optional
|
orElseRun(any runnable)
Runs the `runnable` closure/lambda if the value is not set and the same optional instance is returned. |
any
|
orElseThrow([any type='NoSuchElementException'], [any message=''])
If a value is present, returns the value, otherwise throws NoSuchElementException. |
any
|
setJOptional(any jOptional)
|
string
|
toString()
Returns a non-empty string representation of this Optional suitable for debugging. |
Methods inherited from class lucee.Component |
---|
None |
Constructor Detail |
---|
Construct a CFML Optional out of the Java Optional. If no optional passed, we will generate an empty one.
optional
- A Java optional to initialize this CFML Optional with.Property Detail |
---|
The Java Builder we represent
access
- publicrequired
- falsereturntype
- anyserializable
- trueMethod Detail |
---|
If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function.
supplier
- A closure/lambda that must return a cbOptionalIf a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function.
supplier
- A closure/lambda that must return a cbOptionalBuild an empty optional out.
If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.
predicate
- a predicate to apply to the value, if presentIf a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
Return a native CF type from incoming Java type. This is our Java to CF Bridge. Expand as needed
results
- The native Java returnVerify if the optional is of a certain primitive type and call the appropriate function to return it's value. If not, it reverts to a default typedless Optional.
Returns the hash code value of the present value, if any, or 0 (zero) if no value is present.
If a value is present, invoke the specified consumer with the value, otherwise do nothing.
consumer
- block to be executed if a value is presentIf a value is present, performs the given action with the value, otherwise performs the given empty-based action.
consumer
- The closure/lambda to execute if the value is presentrunnable
- The closure/lambda to execute if the value is NOT presentReturn true if there is no value present, otherwise false
Indicates whether some other object is "equal to" this Optional.
Please note that the incoming
obj
Return true if there is a value present, otherwise false.
If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional.
mapper
- a mapping function to apply to the value, if presentReturns an Optional with the specified present non-null value.
value
- The value to be present, which must be NON NULLReturns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
value
- the possibly-null value to describeReturn the value if present, otherwise return other.
other
- the value to be returned if there is no value present, may be nullReturn the value if present, otherwise invoke other and return the result of that invocation.
other
- a Supplier lambda or closure whose result is returned if no value is presentRuns the `runnable` closure/lambda if the value is not set and the same optional instance is returned.
runnable
- a lambda or closure that will runIf a value is present, returns the value, otherwise throws NoSuchElementException.
type
- The type of the exception to throw or defaults to NoSuchElementException,message
- The message of the exception, defaults to empty stringjOptional
Returns a non-empty string representation of this Optional suitable for debugging.