/** * Construct a new immutable {@code ContractCondition} instance. * @param predicate The value for the {@code predicate} attribute * @param describer The value for the {@code describer} attribute * @return An immutable ContractCondition instance */ public static <T> ContractCondition<T> of(Predicate<T> predicate, Function<T, String> describer) { return new ContractCondition<T>(predicate, describer); }
/** * This instance is equal to all instances of {@code ContractCondition} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ContractCondition<?> && equalTo((ContractCondition<T>) another); }
/** * Construct a predicate from the given predicate function and describer. * * @param condition The predicate function * @param describer The describer * @param <T> The type of values * * @return A predicate */ public static <T> ContractCondition<T> condition( final Predicate<T> condition, final Function<T, String> describer) { return ContractCondition.of(condition, describer); }
/** * Creates an immutable copy of a {@link ContractConditionType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param <T> generic parameter T * @param instance The instance to copy * @return A copied immutable ContractCondition instance */ public static <T> ContractCondition<T> copyOf(ContractConditionType<T> instance) { if (instance instanceof ContractCondition<?>) { return (ContractCondition<T>) instance; } return ContractCondition.<T>builder() .from(instance) .build(); }
/** * Creates an immutable copy of a {@link ContractConditionType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param <T> generic parameter T * @param instance The instance to copy * @return A copied immutable ContractCondition instance */ public static <T> ContractCondition<T> copyOf(ContractConditionType<T> instance) { if (instance instanceof ContractCondition<?>) { return (ContractCondition<T>) instance; } return ContractCondition.<T>builder() .from(instance) .build(); }
/** * Construct a new immutable {@code ContractCondition} instance. * @param predicate The value for the {@code predicate} attribute * @param describer The value for the {@code describer} attribute * @return An immutable ContractCondition instance */ public static <T> ContractCondition<T> of(Predicate<T> predicate, Function<T, String> describer) { return new ContractCondition<T>(predicate, describer); }
/** * This instance is equal to all instances of {@code ContractCondition} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @SuppressWarnings("unchecked") @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ContractCondition<?> && equalTo((ContractCondition<T>) another); }
/** * Construct a predicate from the given predicate function and describer. * * @param condition The predicate function * @param describer The describer * @param <T> The type of values * * @return A predicate */ public static <T> ContractCondition<T> condition( final Predicate<T> condition, final Function<T, String> describer) { return ContractCondition.of(condition, describer); }
/** * Copy the current immutable object by setting a value for the {@link ContractConditionType#predicate() predicate} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for predicate * @return A modified copy of the {@code this} object */ public final ContractCondition<T> withPredicate(Predicate<T> value) { if (this.predicate == value) return this; Predicate<T> newValue = Objects.requireNonNull(value, "predicate"); return new ContractCondition<T>(this, newValue, this.describer); }
/** * Copy the current immutable object by setting a value for the {@link ContractConditionType#describer() describer} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for describer * @return A modified copy of the {@code this} object */ public final ContractCondition<T> withDescriber(Function<T, String> value) { if (this.describer == value) return this; Function<T, String> newValue = Objects.requireNonNull(value, "describer"); return new ContractCondition<T>(this, this.predicate, newValue); }
/** * Copy the current immutable object by setting a value for the {@link ContractConditionType#predicate() predicate} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for predicate * @return A modified copy of the {@code this} object */ public final ContractCondition<T> withPredicate(Predicate<T> value) { if (this.predicate == value) return this; Predicate<T> newValue = Objects.requireNonNull(value, "predicate"); return new ContractCondition<T>(this, newValue, this.describer); }
/** * Copy the current immutable object by setting a value for the {@link ContractConditionType#describer() describer} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for describer * @return A modified copy of the {@code this} object */ public final ContractCondition<T> withDescriber(Function<T, String> value) { if (this.describer == value) return this; Function<T, String> newValue = Objects.requireNonNull(value, "describer"); return new ContractCondition<T>(this, this.predicate, newValue); }
/** * Builds a new {@link ContractCondition ContractCondition}. * @return An immutable instance of ContractCondition * @throws java.lang.IllegalStateException if any required attributes are missing */ public ContractCondition<T> build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ContractCondition<T>(null, predicate, describer); }
/** * Builds a new {@link ContractCondition ContractCondition}. * @return An immutable instance of ContractCondition * @throws java.lang.IllegalStateException if any required attributes are missing */ public ContractCondition<T> build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ContractCondition<T>(null, predicate, describer); }