Skip to content

Commit 009045d

Browse files
committed
Adds Javadoc
1 parent 726adcb commit 009045d

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

equalsverifier-core/src/main/java/nl/jqno/equalsverifier/api/EqualsVerifierApi.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public interface EqualsVerifierApi<T> {
5252
*/
5353
<S> EqualsVerifierApi<T> withPrefabValues(Class<S> otherType, S red, S blue);
5454

55+
/**
56+
* Adds Suppliers for resettable prefabricated values for instance fields of classes that EqualsVerifier cannot
57+
* instantiate by itself. Resettable values are values that are created new every time a new instance of {@code T}
58+
* is constructed within EqualsVerifier. This can be useful when {@code T} mutates its instances of {@code S}.
59+
*
60+
* @param <S> The class of the prefabricated values.
61+
* @param otherType The class of the prefabricated values.
62+
* @param red An instance of {@code S}.
63+
* @param blue Another instance of {@code S}, not equal to {@code red}.
64+
* @return {@code this}, for easy method chaining.
65+
* @throws NullPointerException If either {@code otherType}, {@code red}, or {@code blue} is null.
66+
* @throws IllegalArgumentException If {@code red} equals {@code blue}.
67+
*
68+
* @since 4.1
69+
*/
5570
<S> EqualsVerifierApi<T> withResettablePrefabValue(Class<S> otherType, Supplier<S> red, Supplier<S> blue);
5671

5772
/**

equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/PrefabValuesApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static <T> void addResettablePrefabValues(
5656
Validations.validateEqual(red.get(), red.get(), "red prefab value is not equal to itself after reset.");
5757
Validations.validateEqual(blue.get(), blue.get(), "blue prefab value is not equal to itself after reset.");
5858

59-
userPrefabs.register(otherType, red, blue, red);
59+
userPrefabs.registerResettable(otherType, red, blue, red);
6060
}
6161

6262
public static <T> void addPrefabValuesForField(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package nl.jqno.equalsverifier.internal.instantiation;
22

3+
/**
4+
* Decides whether {@link CachingValueProvider} should cache instances of the given type.
5+
*/
36
@FunctionalInterface
47
public interface CacheDecider {
8+
/**
9+
* Determines whether instances of {@code type} should be cached.
10+
*
11+
* @param type The type whose instances should or should not be cached.
12+
* @return Whether instances of the given type should be cached.
13+
*/
514
boolean canBeCached(Class<?> type);
615
}

equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/UserPrefabValueProvider.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ private <T> Tuple<T> attempt(Class<?> type) {
6565
return (Tuple<T>) cache.get(type);
6666
}
6767

68-
public <T> void register(Class<T> type, Supplier<T> red, Supplier<T> blue, Supplier<T> redCopy) {
68+
/**
69+
* Registers a resettable prefab value.
70+
*
71+
* @param type The class of the prefabricated values.
72+
* @param red A Supplier for an instance of {@code T}.
73+
* @param blue A Supplier for another instance of {@code T}, not equal to {@code red}.
74+
* @param redCopy A Supplier for an instance of {@code T}, equal to {@code red} but preferably not the same
75+
* instance.
76+
* @param <T> The type of the instances.
77+
*/
78+
public <T> void registerResettable(Class<T> type, Supplier<T> red, Supplier<T> blue, Supplier<T> redCopy) {
6979
Tuple<Supplier<?>> tuple = new Tuple<>(red, blue, redCopy);
7080
supplierCache.put(type, tuple);
7181
}

0 commit comments

Comments
 (0)