io.jonasg.bob.NullableValidatableField Maven / Gradle / Ivy
The newest version!
package io.jonasg.bob;
/**
* Container Object for a required field and its value that can be set as null
*
* @param
* the type of the required field its value
*/
@SuppressWarnings("unused")
public class NullableValidatableField implements ValidatableField {
private T fieldValue;
private boolean fieldSet;
private final String fieldName;
private final String typeName;
public NullableValidatableField(T fieldValue, String fieldName, String typeName) {
this.fieldValue = fieldValue;
this.fieldName = fieldName;
this.typeName = typeName;
}
@Override
public void set(T value) {
this.fieldValue = value;
this.fieldSet = true;
}
@Override
public T orElseThrow() {
if (!this.fieldSet && this.fieldValue == null) {
throw new MandatoryFieldMissingException(this.fieldName, this.typeName);
}
return this.fieldValue;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy