Enum Warning
- All Implemented Interfaces:
Serializable,Comparable<Warning>
EqualsVerifier.- See Also:
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionSignals that not all fields are relevant in theequalscontract.Signals that non-final fields are not relevant in theequalscontract.Disables the check that equality ofBigDecimalfields is implemented usingcompareTorather thanequals.Disables the check, when theequalsmethod is overridden in the class under test, that an instance of this class should be equal to an identical copy of itself.Disables the check, when theequalsmethod is overridden in the class under test, that an instance of this class should be equal to an identical copy of itself.Disables the check that verifiesequalsis actually overridden.Disables the example check for cachedhashCode.Disables checks for non-final fields on whichequalsandhashCodedepend.Disables the check for reference equality on fields.Disables the check that all fields used inequalsmust also be used inhashCode.Disables some of the stricter inheritance tests.Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequalscontract.Disables the check that transient fields not be part of theequalscontract.Disables checks with fields with value 0 withinequals,hashCodeandtoStringmethods. -
Method Summary
-
Enum Constant Details
-
ALL_FIELDS_SHOULD_BE_USED
Signals that not all fields are relevant in theequalscontract.EqualsVerifierwill not fail if one or more fields do not affect the outcome ofequals.Only applies to non-transient fields.
-
ALL_NONFINAL_FIELDS_SHOULD_BE_USED
Signals that non-final fields are not relevant in theequalscontract.EqualsVerifierwill not fail if one or more non-final fields do not affect the outcome ofequals.Only applies to non-transient fields.
-
REFERENCE_EQUALITY
Disables the check for reference equality on fields.EqualsVerifier will check if the
equalsmethod calls equals on the object fields of the class under test, instead of the==operator, since normally this signifies a mistake (e.g. comparing string fields with==).However, sometimes
==is used intentionally, or the field in question doesn't implementequalsitself, so a call to theequalsmethod of that field is essentially a reference equality check instead of a value equality check. In these cases, this warning can be suppressed. -
IDENTICAL_COPY
Disables the check, when theequalsmethod is overridden in the class under test, that an instance of this class should be equal to an identical copy of itself.Normally, it is important that an object be equal to an identical copy of itself: after all, this is the point of overriding
equalsin the first place.However, when the class is part of a hierarchy, but should be (pseudo-)singleton, it can be useful to suppress this warning. This can happen in certain implementations of the Null Object Pattern, for example.
If this warning is suppressed, and it turns out that an instance of the class under test is equal to an identical copy of itself after all,
EqualsVerifierwill fail. -
IDENTICAL_COPY_FOR_VERSIONED_ENTITY
Disables the check, when theequalsmethod is overridden in the class under test, that an instance of this class should be equal to an identical copy of itself.Normally, it is important that an object be equal to an identical copy of itself: after all, this is the point of overriding
equalsin the first place.However, when the class is a kind of versioned entity and there is an
idfield that is zero when the object is new, it is often the case that two new objects are never equal to each other. In these cases, it can be useful to suppress this warning.You cannot use
IDENTICAL_COPYin these cases, because when theids are equal, the objects should be, too, andEqualsVerifierwould fail in this case.If this warning is suppressed, and it turns out that an instance of the class under test is equal to an identical copy of itself after all,
EqualsVerifierwill NOT fail. -
INHERITED_DIRECTLY_FROM_OBJECT
Disables the check that verifiesequalsis actually overridden.Can be used when a whole package of classes is automatically scanned and presented to EqualsVerifier, and one or more of them don't need to override
equals. -
NO_EXAMPLE_FOR_CACHED_HASHCODE
Disables the example check for cachedhashCode.The example check verifies that the cached
hashCodeis properly initialized. You can use this, if creating an example object is too cumbersome. In this case, null can be passed as an example.Note that suppressing this warning can be dangerous and should only be done in unusual circumstances.
-
NONFINAL_FIELDS
Disables checks for non-final fields on whichequalsandhashCodedepend.EqualsVerifier's standard behaviour is to disallow non-final fields being used inequalsandhashCodemethods, since classes that depend on non-final fields in these methods cannot reliably be used in collections.However, sometimes an external library requires that fields be non-final. An example of this are Java Beans. In such a case, suppress this warning to prevent
EqualsVerifierfrom checking for non-final fields. -
NULL_FIELDS
Disables checks forNullPointerExceptionwithinequals,hashCodeandtoStringmethods.Sometimes the constructor of a class makes sure no field can be null. If this is the case, and if the fields cannot be made null later in the lifecycle of the class by setters or other methods, suppress this warning to disable the check for
NullPointerException. -
STRICT_HASHCODE
Disables the check that all fields used inequalsmust also be used inhashCode.This is useful when bringing legacy systems under test, where you don't want to change the existing
hashCodebehaviour but you do want to use EqualsVerifier.Note that
hashCodes with higher distributions give better performance when used in collections such asHashMap. Therefore, if possible, you should use all fields that are used inequals, inhashCodeas well. -
STRICT_INHERITANCE
Disables some of the stricter inheritance tests.EqualsVerifier's standard behaviour, if T is not final and neither are itsequalsandhashCodemethods, is to require a reference to a subclass of T for which no instance can be equal to any instance of T, to make sure that subclasses that can redefineequalsorhashCodedon't break the contract; or it asks to call theusingGetClassmethod if T usesgetClass()instead ofinstanceofin itsequalsmethod.Some may find that too strict for their liking; suppressing this warning disables that test.
-
SURROGATE_KEY
Disables the check that fields marked with the @Id or @EmbeddedId annotations in JPA entities may not be used in theequalscontract.When this warning is suppressed, the fields marked with @Id or @EmbeddedId will become the entity's surrogate key. Only these fields can now be part of the
equalscontract; all other fields may no longer be used inequals. -
TRANSIENT_FIELDS
Disables the check that transient fields not be part of theequalscontract.EqualsVerifier's standard behaviour is to disallow transient fields being used inequalsandhashCodemethods, since these fields may not be restored to their original state after deserialization, which would breakequals.If measures are taken that this will never happen, this warning can be suppressed to disable
EqualsVerifier's transience test. -
BIGDECIMAL_EQUALITY
Disables the check that equality ofBigDecimalfields is implemented usingcompareTorather thanequals.BigDecimalobjects that are equal usingcompareToare not necessarily equal usingequals, for example the values of 1 and 1.0. For variants of the same value to be considered equal, classes withBigDecimalfields should usecompareToto check equality of non-nullBigDecimalreferences and produce the same hashcode for all equal variants.EqualsVerifierchecks for this by default but it can be disabled by suppressing this warning. -
ZERO_FIELDS
Disables checks with fields with value 0 withinequals,hashCodeandtoStringmethods.Sometimes the constructor of a class makes sure no field can be 0. If this is the case, and if the fields cannot be made 0 later in the lifecycle of the class by setters or other methods, suppress this warning to disable the checks with fields that have value 0.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-