Class ValidationContextImpl
- java.lang.Object
-
- org.finos.tracdap.common.validation.core.impl.ValidationContextImpl
-
- All Implemented Interfaces:
ValidationContext
public class ValidationContextImpl extends java.lang.Object implements ValidationContext
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ValidationContextapply(ValidationFunction.Basic validator)ValidationContextapply(ValidationFunction.Typed<java.lang.String> validator)<T> ValidationContextapply(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)<T,U>
ValidationContextapply(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)ValidationContextapply(ValidationFunction.Version<java.lang.Object> validator)<T> ValidationContextapply(ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)ValidationContextapplyIf(boolean condition, ValidationFunction.Basic validator)ValidationContextapplyIf(boolean condition, ValidationFunction.Typed<java.lang.String> validator)<T> ValidationContextapplyIf(boolean condition, ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)<T,U>
ValidationContextapplyIf(boolean condition, ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)<T> ValidationContextapplyIf(boolean condition, ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)ValidationContextapplyMapKeys(ValidationFunction.Basic validator)ValidationContextapplyMapKeys(ValidationFunction.Typed<java.lang.String> validator)<U> ValidationContextapplyMapKeys(ValidationFunction.TypedArg<java.lang.String,U> validator, U arg)ValidationContextapplyMapValues(ValidationFunction.Basic validator)<T> ValidationContextapplyMapValues(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)<T,U>
ValidationContextapplyMapValues(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)ValidationContextapplyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Basic validator)<T> ValidationContextapplyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)<T,U>
ValidationContextapplyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)<T> ValidationContextapplyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)ValidationContextapplyRegistered()ValidationContextapplyRepeated(ValidationFunction.Basic validator)ValidationContextapplyRepeated(ValidationFunction.Typed<java.lang.String> validator)<T> ValidationContextapplyRepeated(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)<T,U>
ValidationContextapplyRepeated(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)booleandone()ValidationContexterror(java.lang.String message)Record an error against the current location in the validation stackbooleanfailed()com.google.protobuf.Descriptors.FieldDescriptorfield()java.lang.StringfieldName()static ValidationContextforMessage(com.google.protobuf.Message msg)static ValidationContextforMethod(com.google.protobuf.Message msg, com.google.protobuf.Descriptors.MethodDescriptor method)static ValidationContextforVersion(com.google.protobuf.Message current, com.google.protobuf.Message prior)java.util.List<ValidationFailure>getErrors()booleanisMap()booleanisOneOf()booleanisRepeated()ValidationKeykey()com.google.protobuf.Descriptors.OneofDescriptoroneOf()com.google.protobuf.MessageparentMsg()ValidationContextpop()Pop the current object from the validation stackValidationContextprior()ValidationContextpush(com.google.protobuf.Descriptors.FieldDescriptor fd)Push a member field of the current object onto the validation stackValidationContextpushMap(com.google.protobuf.Descriptors.FieldDescriptor fd)Push a map member field of the current object onto the validation stack This method will work with applyMapKeys() and applyMapValues().<TMsg extends com.google.protobuf.Message>
ValidationContextpushMap(com.google.protobuf.Descriptors.FieldDescriptor mapField, java.util.function.Function<TMsg,java.util.Map<?,?>> getMapFunc)Push a map member field of the current object onto the validation stack This method only pushes the map itself onto the stack, the validation target will be a Java Map object.ValidationContextpushMapKey(java.lang.Object key)Push an individual map key onto the validation stack Requires that the current target is a map field.ValidationContextpushMapValue(java.lang.Object key)Push an individual map value onto the validation stack Requires that the current target is a map field.ValidationContextpushOneOf(com.google.protobuf.Descriptors.OneofDescriptor oneOf)Push a "one-of" field of the current object onto the validation stackValidationContextpushRepeated(com.google.protobuf.Descriptors.FieldDescriptor fd)Push a repeated member field of the current object onto the validation stack This method pushes a list onto the validation stack, so the target becomes a Java List object.ValidationContextpushRepeatedItem(int index)Push an individual list item onto the validation stack Requires that the current target is a repeated field.ValidationContextpushRepeatedItem(int index, java.lang.Object priorObj)Push an individual list item onto the validation stack Requires that the current target is a repeated field.ValidationContextpushRepeatedItem(java.lang.Object obj, java.lang.Object priorObj)Push an individual list item onto the validation stack Requires that the current target is a repeated field.ValidationContextskip()Skip the current location in the validation stack Any future calls to apply() at this location or child locations will be ignored.booleanskipped()java.lang.Objecttarget()ValidationTypevalidationType()
-
-
-
Method Detail
-
forMethod
public static ValidationContext forMethod(com.google.protobuf.Message msg, com.google.protobuf.Descriptors.MethodDescriptor method)
-
forMessage
public static ValidationContext forMessage(com.google.protobuf.Message msg)
-
forVersion
public static ValidationContext forVersion(com.google.protobuf.Message current, com.google.protobuf.Message prior)
-
push
public ValidationContext push(com.google.protobuf.Descriptors.FieldDescriptor fd)
Description copied from interface:ValidationContextPush a member field of the current object onto the validation stack- Specified by:
pushin interfaceValidationContext- Parameters:
fd- The field that will be pushed onto the stack- Returns:
- A validation context pointing at the field that has been pushed
-
pushOneOf
public ValidationContext pushOneOf(com.google.protobuf.Descriptors.OneofDescriptor oneOf)
Description copied from interface:ValidationContextPush a "one-of" field of the current object onto the validation stack- Specified by:
pushOneOfin interfaceValidationContext- Parameters:
oneOf- The one-of field that will be pushed onto the stack- Returns:
- A validation context pointing at the field that has been pushed
-
pushRepeated
public ValidationContext pushRepeated(com.google.protobuf.Descriptors.FieldDescriptor fd)
Description copied from interface:ValidationContextPush a repeated member field of the current object onto the validation stack This method pushes a list onto the validation stack, so the target becomes a Java List object. To push individual list items, use pushRepeatedItem() after calling this method.- Specified by:
pushRepeatedin interfaceValidationContext- Parameters:
fd- The field that will be pushed onto the stack- Returns:
- A validation context pointing at the list that has been pushed
-
pushRepeatedItem
public ValidationContext pushRepeatedItem(int index)
Description copied from interface:ValidationContextPush an individual list item onto the validation stack Requires that the current target is a repeated field.- Specified by:
pushRepeatedItemin interfaceValidationContext- Parameters:
index- The index of the list item to push onto the stack (must be within bounds of the list)- Returns:
- A validation context pointing at the list item that has been pushed
-
pushRepeatedItem
public ValidationContext pushRepeatedItem(int index, java.lang.Object priorObj)
Description copied from interface:ValidationContextPush an individual list item onto the validation stack Requires that the current target is a repeated field. This overload allows a prior version of the object to be specified for version comparison. This is helpful for version validators, which need to match current / prior entries in a list.- Specified by:
pushRepeatedItemin interfaceValidationContext- Parameters:
index- The index of the list item to push onto the stack (must be within bounds of the list)priorObj- The prior object to be compared against this list item in version validators- Returns:
- A validation context pointing at the list item that has been pushed
-
pushRepeatedItem
public ValidationContext pushRepeatedItem(java.lang.Object obj, java.lang.Object priorObj)
Description copied from interface:ValidationContextPush an individual list item onto the validation stack Requires that the current target is a repeated field. This overload allows a prior version of the object to be specified for version comparison. This is helpful for version validators, which need to match current / prior entries in a list.- Specified by:
pushRepeatedItemin interfaceValidationContext- Parameters:
obj- The current list item to push onto the stack (must be a member of the list)priorObj- The prior object to be compared against this list item in version validators- Returns:
- A validation context pointing at the list item that has been pushed
-
pushMap
public ValidationContext pushMap(com.google.protobuf.Descriptors.FieldDescriptor fd)
Description copied from interface:ValidationContextPush a map member field of the current object onto the validation stack This method will work with applyMapKeys() and applyMapValues(). If you need to look up map items by key or want to call pushMapKey() / pushMapValue() explicitly, use the overload which takes getMapFunc as a parameter (protobuf for Java does not provide a generic way of looking up map keys).- Specified by:
pushMapin interfaceValidationContext- Parameters:
fd- The field that will be pushed onto the stack- Returns:
- A validation context pointing at the map that has been pushed (this is not a Map object)
-
pushMap
public <TMsg extends com.google.protobuf.Message> ValidationContext pushMap(com.google.protobuf.Descriptors.FieldDescriptor mapField, java.util.function.Function<TMsg,java.util.Map<?,?>> getMapFunc)
Description copied from interface:ValidationContextPush a map member field of the current object onto the validation stack This method only pushes the map itself onto the stack, the validation target will be a Java Map object. To push individual keys or values, use pushMapKey() or pushMapValue() after calling this method. This method needs a method reference from the parent message class to return Java map object associated with this field (protobuf for Java does not yet provide a generic way of looking up map keys).- Specified by:
pushMapin interfaceValidationContext- Parameters:
mapField- The field that will be pushed onto the stackgetMapFunc- Method reference, on the parent message to return the field as a Java map- Returns:
- A validation context pointing at the map that has been pushed (this is a Map object)
-
pushMapKey
public ValidationContext pushMapKey(java.lang.Object key)
Description copied from interface:ValidationContextPush an individual map key onto the validation stack Requires that the current target is a map field.- Specified by:
pushMapKeyin interfaceValidationContext- Parameters:
key- The map key to push onto the stack- Returns:
- A validation context pointing at the map key that has been pushed
-
pushMapValue
public ValidationContext pushMapValue(java.lang.Object key)
Description copied from interface:ValidationContextPush an individual map value onto the validation stack Requires that the current target is a map field.- Specified by:
pushMapValuein interfaceValidationContext- Parameters:
key- The key of the map value to push onto the stack- Returns:
- A validation context pointing at the map value that has been pushed
-
pop
public ValidationContext pop()
Description copied from interface:ValidationContextPop the current object from the validation stack- Specified by:
popin interfaceValidationContext- Returns:
- A validation context pointing at the parent of the current object
-
error
public ValidationContext error(java.lang.String message)
Description copied from interface:ValidationContextRecord an error against the current location in the validation stack- Specified by:
errorin interfaceValidationContext- Parameters:
message- The error message to record- Returns:
- A validation context which includes the recorded error
-
skip
public ValidationContext skip()
Description copied from interface:ValidationContextSkip the current location in the validation stack Any future calls to apply() at this location or child locations will be ignored. Errors already recorded at this location or child locations are still included in the validation report.- Specified by:
skipin interfaceValidationContext- Returns:
- A validation context with the current object marked as skipped
-
applyRegistered
public ValidationContext applyRegistered()
- Specified by:
applyRegisteredin interfaceValidationContext
-
apply
public ValidationContext apply(ValidationFunction.Basic validator)
- Specified by:
applyin interfaceValidationContext
-
apply
public ValidationContext apply(ValidationFunction.Typed<java.lang.String> validator)
- Specified by:
applyin interfaceValidationContext
-
apply
public <T> ValidationContext apply(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyin interfaceValidationContext
-
apply
public <T,U> ValidationContext apply(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)
- Specified by:
applyin interfaceValidationContext
-
apply
public ValidationContext apply(ValidationFunction.Version<java.lang.Object> validator)
- Specified by:
applyin interfaceValidationContext
-
apply
public <T> ValidationContext apply(ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyin interfaceValidationContext
-
applyIf
public ValidationContext applyIf(boolean condition, ValidationFunction.Basic validator)
- Specified by:
applyIfin interfaceValidationContext
-
applyIf
public ValidationContext applyIf(boolean condition, ValidationFunction.Typed<java.lang.String> validator)
- Specified by:
applyIfin interfaceValidationContext
-
applyIf
public <T> ValidationContext applyIf(boolean condition, ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyIfin interfaceValidationContext
-
applyIf
public <T,U> ValidationContext applyIf(boolean condition, ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)
- Specified by:
applyIfin interfaceValidationContext
-
applyIf
public <T> ValidationContext applyIf(boolean condition, ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyIfin interfaceValidationContext
-
applyOneOf
public ValidationContext applyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Basic validator)
- Specified by:
applyOneOfin interfaceValidationContext
-
applyOneOf
public <T> ValidationContext applyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyOneOfin interfaceValidationContext
-
applyOneOf
public <T,U> ValidationContext applyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)
- Specified by:
applyOneOfin interfaceValidationContext
-
applyOneOf
public <T> ValidationContext applyOneOf(com.google.protobuf.Descriptors.FieldDescriptor field, ValidationFunction.Version<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyOneOfin interfaceValidationContext
-
applyRepeated
public ValidationContext applyRepeated(ValidationFunction.Basic validator)
- Specified by:
applyRepeatedin interfaceValidationContext
-
applyRepeated
public ValidationContext applyRepeated(ValidationFunction.Typed<java.lang.String> validator)
- Specified by:
applyRepeatedin interfaceValidationContext
-
applyRepeated
public <T> ValidationContext applyRepeated(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyRepeatedin interfaceValidationContext
-
applyRepeated
public <T,U> ValidationContext applyRepeated(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)
- Specified by:
applyRepeatedin interfaceValidationContext
-
applyMapKeys
public ValidationContext applyMapKeys(ValidationFunction.Basic validator)
- Specified by:
applyMapKeysin interfaceValidationContext
-
applyMapKeys
public ValidationContext applyMapKeys(ValidationFunction.Typed<java.lang.String> validator)
- Specified by:
applyMapKeysin interfaceValidationContext
-
applyMapKeys
public <U> ValidationContext applyMapKeys(ValidationFunction.TypedArg<java.lang.String,U> validator, U arg)
- Specified by:
applyMapKeysin interfaceValidationContext
-
applyMapValues
public ValidationContext applyMapValues(ValidationFunction.Basic validator)
- Specified by:
applyMapValuesin interfaceValidationContext
-
applyMapValues
public <T> ValidationContext applyMapValues(ValidationFunction.Typed<T> validator, java.lang.Class<T> targetClass)
- Specified by:
applyMapValuesin interfaceValidationContext
-
applyMapValues
public <T,U> ValidationContext applyMapValues(ValidationFunction.TypedArg<T,U> validator, java.lang.Class<T> targetClass, U arg)
- Specified by:
applyMapValuesin interfaceValidationContext
-
validationType
public ValidationType validationType()
- Specified by:
validationTypein interfaceValidationContext
-
key
public ValidationKey key()
- Specified by:
keyin interfaceValidationContext
-
target
public java.lang.Object target()
- Specified by:
targetin interfaceValidationContext
-
parentMsg
public com.google.protobuf.Message parentMsg()
- Specified by:
parentMsgin interfaceValidationContext
-
isOneOf
public boolean isOneOf()
- Specified by:
isOneOfin interfaceValidationContext
-
isRepeated
public boolean isRepeated()
- Specified by:
isRepeatedin interfaceValidationContext
-
isMap
public boolean isMap()
- Specified by:
isMapin interfaceValidationContext
-
oneOf
public com.google.protobuf.Descriptors.OneofDescriptor oneOf()
- Specified by:
oneOfin interfaceValidationContext
-
field
public com.google.protobuf.Descriptors.FieldDescriptor field()
- Specified by:
fieldin interfaceValidationContext
-
fieldName
public java.lang.String fieldName()
- Specified by:
fieldNamein interfaceValidationContext
-
prior
public ValidationContext prior()
- Specified by:
priorin interfaceValidationContext
-
failed
public boolean failed()
- Specified by:
failedin interfaceValidationContext
-
skipped
public boolean skipped()
- Specified by:
skippedin interfaceValidationContext
-
done
public boolean done()
- Specified by:
donein interfaceValidationContext
-
getErrors
public java.util.List<ValidationFailure> getErrors()
- Specified by:
getErrorsin interfaceValidationContext
-
-