All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jonasg.bob.NoneNullableValidatableField Maven / Gradle / Ivy

The newest version!
package io.jonasg.bob;

/**
 * Container Object for a required field and its value that cannot be set as
 * null
 *
 * @param 
 *            the type of the required field its value
 */
@SuppressWarnings("unused")
public final class NoneNullableValidatableField implements ValidatableField {

	private T fieldValue;

	private final String fieldName;

	private final String typeName;

	NoneNullableValidatableField(T fieldValue, String fieldName, String typeName) {
		this.fieldValue = fieldValue;
		this.fieldName = fieldName;
		this.typeName = typeName;
	}

	@Override
	public void set(T value) {
		this.fieldValue = value;
	}

	@Override
	public T orElseThrow() {
		if (fieldValue == null) {
			throw new MandatoryFieldMissingException(fieldName, typeName);
		}
		return fieldValue;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy