Interface LogProperty.ValidatedResult<T>
- Type Parameters:
T- property type.
- All Superinterfaces:
LogProperty.Result<T>
- All Known Subinterfaces:
LogProperty.RequiredResult<T>, LogProperty.Result.Success<T>
- All Known Implementing Classes:
LogProperty.Result.Error, LogProperty.Result.Missing
- Enclosing interface:
LogProperty
public static sealed interface LogProperty.ValidatedResult<T>
extends LogProperty.Result<T>
permits LogProperty.Result.Missing<T>, LogProperty.Result.Error<T>, LogProperty.RequiredResult<T>
A
LogProperty.Result that is safe to pull a value out of - either because it can never
actually be missing (LogProperty.RequiredResult: a LogProperty.Result.Success or an
LogProperty.Result.Error, both already resolved one way or the other) or because a
caller has explicitly acknowledged the possibility of a still-LogProperty.Result.Missing
result by running it through LogProperty.Result.validate(Validator),
LogProperty.Result.validateIfError(Validator), or LogProperty.Result.validateNow(Class).
LogProperty.Result itself deliberately does not declare value()/
valueOrNull()/optional() - a bare LogProperty.Result returned by
LogProperty.ofString() and friends forces a caller through one of those
validation paths before it can pull a value out, instead of blindly calling
value() on a result that might still be LogProperty.Result.Missing.
-
Nested Class Summary
Nested classes/interfaces inherited from interface LogProperty.Result
LogProperty.Result.Error<T>, LogProperty.Result.Missing<T>, LogProperty.Result.Success<T>Modifier and TypeInterfaceDescriptionstatic final recordA property that was present but failed conversion.static final recordA property that is missing (null).static interfaceA property that is present. -
Method Summary
Modifier and TypeMethodDescriptionoptional()Convenience that turns a value into an optional.value()Gets the value and will fail withNoSuchElementExceptionif there is no value.@Nullable TGets the value.default @Nullable TvalueOrNull(@Nullable T fallback) Gets a value if there is if not uses the fallback.Methods inherited from interface LogProperty.Result
describe, map, or, or, validate, validateIfError, validateNowModifier and TypeMethodDescriptiondescribe()A description of the result for error messages.<U> LogProperty.Result<U> map(LogProperty.PropertyFunction<T, U, ? super Exception> mapper) Maps this result's value throughmapper.Returns the current result if fallback is null or returns fallback as a result if this result is missing.Returns the current result if success or error otherwise fallback supplier is used.default LogProperty.ValidatedResult<T> validate(LogProperty.Validator validator) Registers this result withvalidatorviaLogProperty.Validator.add(Result)(a still-LogProperty.Result.Missingresult is treated as a real failure) and returns this result unchanged, so a chain that builds a required property can register itself with a sharedLogProperty.Validatorand keep going in one expression -properties.forKey(key).ofString().or(fallback).validate(v)- instead of a separatevar x = ...; v.add(x);statement pair.default LogProperty.ValidatedResult<T> validateIfError(LogProperty.Validator validator) LikeLogProperty.Result.validate(Validator)but viaLogProperty.Validator.addIfError(Result)instead ofLogProperty.Validator.add(Result)- aLogProperty.Result.Missingresult is expected and ignored, only aLogProperty.Result.Erroris treated as a failure.default TvalidateNow(Class<?> component) Convenience for a genuine one-off, single-property validation that does not need to participate in a larger batch: builds a single-useLogProperty.Validator, registers this result with it viaLogProperty.Validator.add(Result), and validates immediately - instead of registering with a caller-managedLogProperty.ValidatorviaLogProperty.Result.validate(Validator)and deferring to a laterLogProperty.Validator.validate()call.
-
Method Details
-
value
Gets the value and will fail withNoSuchElementExceptionif there is no value.- Returns:
- value.
- Throws:
LogProperty.PropertyMissingException- if there is no value.LogProperty.PropertyConvertException- if the property failed conversion.
-
valueOrNull
-
valueOrNull
Gets a value if there is if not uses the fallback.- Parameters:
fallback- maybenull.- Returns:
- value.
-
optional
-