/** * Construct a new immutable {@code Violation} instance. * @param error The value for the {@code error} attribute * @param message The value for the {@code message} attribute * @param property The value for the {@code property} attribute * @return An immutable Violation instance */ public static Violation of(String error, String message, String property) { return validate(new ImmutableViolation(error, message, property)); }
/** * Builds a new {@link Violation Violation}. * @return An immutable instance of Violation * @throws java.lang.IllegalStateException if any required attributes are missing */ public Violation build() { return ImmutableViolation.validate(new ImmutableViolation(error, message, property)); } }
/** * This instance is equal to all instances of {@code ImmutableViolation} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableViolation && equalTo((ImmutableViolation) another); }
/** * Copy the current immutable object by setting a value for the {@link Violation#property() property} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for property (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableViolation withProperty(String value) { if (Objects.equals(this.property, value)) return this; return validate(new ImmutableViolation(this.error, this.message, value)); }
/** * Copy the current immutable object by setting a value for the {@link Violation#error() error} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for error (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableViolation withError(String value) { if (Objects.equals(this.error, value)) return this; return validate(new ImmutableViolation(value, this.message, this.property)); }
/** * Copy the current immutable object by setting a value for the {@link Violation#message() message} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for message (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableViolation withMessage(String value) { if (Objects.equals(this.message, value)) return this; return validate(new ImmutableViolation(this.error, value, this.property)); }