Package dev.cel.common.values
Class OptionalValue<E extends CelValue>
- java.lang.Object
-
- dev.cel.common.values.CelValue
-
- dev.cel.common.values.OptionalValue<E>
-
- 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 Summary
Fields Modifier and Type Field Description static OptionalValue<CelValue>EMPTYSentinel value representing an empty optional ('optional.none()' in CEL)
-
Constructor Summary
Constructors Constructor Description OptionalValue()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionalTypecelType()The CelType that represents this value.static <E extends CelValue>
OptionalValue<E>create(E value)java.util.Optional<CelValue>find(CelValue field)Finds the field.booleanisZeroValue()Returns true if theCelValue.value()is a zero value for its type.CelValueselect(CelValue field)Optional field selection on maps or structs.Evalue()The underlying value.
-
-
-
Field Detail
-
EMPTY
public static final OptionalValue<CelValue> EMPTY
Sentinel value representing an empty optional ('optional.none()' in CEL)
-
-
Method Detail
-
value
public E value()
Description copied from class:CelValueThe 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).
-
isZeroValue
public boolean isZeroValue()
Description copied from class:CelValueReturns true if theCelValue.value()is a zero value for its type.- Specified by:
isZeroValuein classCelValue
-
celType
public OptionalType celType()
Description copied from class:CelValueThe CelType that represents this value.
-
select
public CelValue select(CelValue field)
Optional field selection on maps or structs.- msg.?field -> has(msg.field) ? optional{msg.field} : optional.none()
- map[?key] -> key in map ? optional{map[key]} : optional.none()
- Specified by:
selectin interfaceSelectableValue<E extends CelValue>
-
find
public java.util.Optional<CelValue> find(CelValue field)
Description copied from interface:SelectableValueFinds the field. This will return anOptional.empty()if the field does not exist. This can be used for presence testing.- Specified by:
findin interfaceSelectableValue<E extends CelValue>
-
create
public static <E extends CelValue> OptionalValue<E> create(E value)
-
-