Type Parameters:
S - the type of this validator
T - the type of the value that is being validated
All Known Subinterfaces:
BigDecimalValidator, BigIntegerValidator, BooleanValidator, ByteArrayValidator, ByteValidator, CharacterValidator, CollectionValidator<T,E>, ComparableValidator<T>, DoubleValidator, FloatValidator, GenericTypeValidator<T>, InetAddressValidator, IntegerValidator, JsonNodeValidator<T>, ListValidator<T,E>, LongValidator, MapValidator<T,K,V>, MultimapValidator<T,K,V>, ObjectArrayValidator<T,E>, ObjectValidator<T>, OptionalValidator<T>, PathValidator, PrimitiveBooleanArrayValidator, PrimitiveByteArrayValidator, PrimitiveCharacterArrayValidator, PrimitiveDoubleArrayValidator, PrimitiveFloatArrayValidator, PrimitiveIntegerArrayValidator, PrimitiveLongArrayValidator, PrimitiveShortArrayValidator, ShortValidator, StringValidator, UnsignedIntegerValidator, UriValidator

public interface ObjectComponent<S,T>
Methods that all object validators must contain.
  • Method Details

    • getValue

      T getValue()
      Returns the value that is being validated.
      Returns:
      the value
      Throws:
      IllegalStateException - if a previous validation failed
    • isNull

      S isNull()
      Ensures that the value is null.
      Returns:
      this
      Throws:
      IllegalArgumentException - if the value is not null
    • isNotNull

      S isNotNull()
      Ensures that the value is not null.

      This method should be used to validate method arguments that are assigned to class fields but not accessed right away (such as constructor and setter arguments). It should also be used to validate any method arguments when the validator contains additional contextual information. Otherwise, the default Java handler is preferable because it throws NullPointerException with a helpful message.

      Returns:
      this
      Throws:
      NullPointerException - if the value is null
    • isReferenceEqualTo

      S isReferenceEqualTo(Object expected, String name)
      Ensures that the value is the same reference expected.
      Parameters:
      expected - the expected object
      name - the name of the expected object
      Returns:
      this
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the value does not reference the same value as expected
    • isReferenceNotEqualTo

      S isReferenceNotEqualTo(Object unwanted, String name)
      Ensures that the value is not the same reference as unwanted.
      Parameters:
      unwanted - the unwanted object
      name - the name of the unwanted object
      Returns:
      this
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the value references the same value as unwanted
    • isInstanceOf

      <U> ObjectValidator<U> isInstanceOf(Class<U> expected)
      Ensures that the object is an instance of a class.
      Type Parameters:
      U - the desired class
      Parameters:
      expected - the desired class. For types that contain type-parameters, use the TypeToken overload.
      Returns:
      a validator for an object of the desired class
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the value is not an instance of the desired class
    • isInstanceOf

      <U> ObjectValidator<U> isInstanceOf(GenericType<U> expected)
      Ensures that the object is an instance of a class.
      Type Parameters:
      U - the desired class
      Parameters:
      expected - the desired class. For types without type-parameters, prefer the Class overload.
      Returns:
      a validator for an object of the desired class
      Throws:
      NullPointerException - if the value or expected are null
      IllegalArgumentException - if the value is not an instance of the desired class
    • isNotInstanceOf

      S isNotInstanceOf(Class<?> unwanted)
      Ensures that the object is not an instance of a class.
      Parameters:
      unwanted - the unwanted class. For types that contain type-parameters, use the TypeToken overload.
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the value is an instance of the unwanted class
    • isNotInstanceOf

      S isNotInstanceOf(GenericType<?> unwanted)
      Ensures that the object is not an instance of a class.
      Parameters:
      unwanted - the unwanted class. For types without type-parameters, prefer the Class overload.
      Returns:
      this
      Throws:
      NullPointerException - if the value or unwanted are null
      IllegalArgumentException - if the value is an instance of the unwanted class
    • isEqualTo

      S isEqualTo(Object expected)
      Ensures that the object is equal to expected.
      Parameters:
      expected - the expected value
      Returns:
      this
      Throws:
      IllegalArgumentException - if the value is not equal to expected
      See Also:
    • isEqualTo

      S isEqualTo(Object expected, String name)
      Ensures that the object is equal to expected.
      Parameters:
      expected - the expected value
      name - the name of the expected value
      Returns:
      this
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the value is not equal to expected
      See Also:
    • isNotEqualTo

      S isNotEqualTo(Object unwanted)
      Ensures that the object is not equal to unwanted.
      Parameters:
      unwanted - the unwanted value
      Returns:
      this
      Throws:
      IllegalArgumentException - if the value is equal to expected
      See Also:
    • isNotEqualTo

      S isNotEqualTo(Object unwanted, String name)
      Ensures that the object is not equal to unwanted.
      Parameters:
      unwanted - the unwanted value
      name - the name of the other value
      Returns:
      this
      Throws:
      NullPointerException - if name is null
      IllegalArgumentException - if:
      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context
      • the value is equal to the unwanted value
      See Also: