testbox.system.modules.cbstreams.models

Class Optional

lucee.Component
    extended by testbox.system.modules.cbstreams.models.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

Class Attributes:
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    any jOptional
          The Java Builder we represent.

    • access = public
    • returntype = any
    true false
    Constructor Summary
    init([any optional])
          Construct a CFML Optional out of the Java Optional.
    Method Summary
    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.
    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.
    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

    init

    public init([any optional])

    Construct a CFML Optional out of the Java Optional. If no optional passed, we will generate an empty one.

    Parameters:
    optional - A Java optional to initialize this CFML Optional with.

    Property Detail

    jOptional

    property any jOptional

    The Java Builder we represent

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    empty

    public Optional empty()

    Build an empty optional out.


    filter

    public 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.

    Parameters:
    predicate - a predicate to apply to the value, if present
    Returns:
    an Optional describing the value of this Optional if a value is present and the value matches the given predicate, otherwise an empty Optional

    get

    public any get()

    If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.


    getJOptional

    public string getJOptional()


    getNativeType

    public any getNativeType([any results])

    Return a native CF type from incoming Java type. This is our Java to CF Bridge. Expand as needed

    Parameters:
    results - The native Java return

    getValueFromOptional

    private any getValueFromOptional()

    Verify 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.


    hashCode

    public numeric hashCode()

    Returns the hash code value of the present value, if any, or 0 (zero) if no value is present.


    ifPresent

    public void ifPresent(any consumer)

    If a value is present, invoke the specified consumer with the value, otherwise do nothing.

    Parameters:
    consumer - block to be executed if a value is present

    isEqual

    public boolean isEqual(any obj)

    Indicates whether some other object is "equal to" this Optional. Please note that the incoming obj must also be an Optional

    Parameters:
    obj

    isPresent

    public boolean isPresent()

    Return true if there is a value present, otherwise false.


    map

    public 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. Otherwise return an empty Optional.

    Parameters:
    mapper - a mapping function to apply to the value, if present
    Returns:
    an Optional describing the result of applying a mapping function to the value of this Optional, if a value is present, otherwise an empty Optional

    of

    public Optional of(any value)

    Returns an Optional with the specified present non-null value.

    Parameters:
    value - The value to be present, which must be NON NULL
    Returns:
    an Optional with the value present

    ofNullable

    public Optional ofNullable([any value])

    Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.

    Parameters:
    value - the possibly-null value to describe
    Returns:
    an Optional with a present value if the specified value is non-null, otherwise an empty Optional

    orElse

    public any orElse(any other)

    Return the value if present, otherwise return other.

    Parameters:
    other - the value to be returned if there is no value present, may be null
    Returns:
    the value, if present, otherwise other

    orElseGet

    public any orElseGet(any other)

    Return the value if present, otherwise invoke other and return the result of that invocation.

    Parameters:
    other - a Supplier lambda or closure whose result is returned if no value is present
    Returns:
    the value if present otherwise the result of other.get()

    setJOptional

    public any setJOptional(any jOptional)

    Parameters:
    jOptional

    toString

    public string toString()

    Returns a non-empty string representation of this Optional suitable for debugging.