Class OptionalValue<E extends CelValue>

  • All Implemented Interfaces:
    SelectableValue<CelValue>

    @Immutable(containerOf="E")
    public abstract class OptionalValue<E extends CelValue>
    extends CelValue
    implements SelectableValue<CelValue>
    First-class support for CEL optionals. Supports similar semantics to java.util.Optional. Also supports optional field selection and presence tests against maps and structs using the optional syntax.
    • Field Detail

      • EMPTY

        public static final OptionalValue<CelValue> EMPTY
        Sentinel value representing an empty optional ('optional.none()' in CEL)
    • Constructor Detail

      • OptionalValue

        public OptionalValue()
    • Method Detail

      • value

        public E value()
        Description copied from class: CelValue
        The underlying value. This is typically the Java native value or a derived instance of CelValue (ex: an element in lists or key/value pair in maps).
        Specified by:
        value in class CelValue
      • select

        public CelValue select​(CelValue field)
        Optional field selection on maps or structs.
        1. msg.?field -> has(msg.field) ? optional{msg.field} : optional.none()
        2. map[?key] -> key in map ? optional{map[key]} : optional.none()
        Specified by:
        select in interface SelectableValue<E extends CelValue>
      • find

        public java.util.Optional<CelValue> find​(CelValue field)
        Description copied from interface: SelectableValue
        Finds the field. This will return an Optional.empty() if the field does not exist. This can be used for presence testing.
        Specified by:
        find in interface SelectableValue<E extends CelValue>