com.brightsparklabs.asanti.validator.builtin.NullValidator Maven / Gradle / Ivy
/*
* Maintained by brightSPARK Labs.
* www.brightsparklabs.com
*
* Refer to LICENSE at repository root for license details.
*/
package com.brightsparklabs.asanti.validator.builtin;
import com.brightsparklabs.asanti.schema.AsnBuiltinType;
import com.brightsparklabs.asanti.validator.FailureType;
import com.brightsparklabs.asanti.validator.failure.ByteValidationFailure;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.Set;
/**
* Validator for data of type {@link AsnBuiltinType#Null}
*
* @author brightSPARK Labs
*/
public class NullValidator extends PrimitiveBuiltinTypeValidator {
// -------------------------------------------------------------------------
// INSTANCE VARIABLES
// -------------------------------------------------------------------------
/** singleton instance */
private static NullValidator instance;
// -------------------------------------------------------------------------
// CONSTRUCTION
// -------------------------------------------------------------------------
/**
* Default constructor.
*
* This is private, use {@link #getInstance()} to obtain an instance
*/
private NullValidator() {}
/**
* Returns a singleton instance of this class
*
* @return a singleton instance of this class
*/
public static NullValidator getInstance() {
if (instance == null) {
instance = new NullValidator();
}
return instance;
}
// -------------------------------------------------------------------------
// IMPLEMENTATION: PrimitiveBuiltinTypeValidator
// -------------------------------------------------------------------------
@Override
protected ImmutableSet validateNonNullBytes(final byte[] bytes) {
final Set failures = Sets.newHashSet();
if (bytes.length != 0) {
final ByteValidationFailure failure =
new ByteValidationFailure(
0, FailureType.DataIncorrectlyFormatted, NULL_VALIDATION_ERROR);
failures.add(failure);
}
return ImmutableSet.copyOf(failures);
}
}