forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArg.java
More file actions
61 lines (53 loc) · 1.49 KB
/
Arg.java
File metadata and controls
61 lines (53 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package fj.test;
import fj.F;
import fj.Show;
import static fj.Show.anyShow;
import static fj.Show.showS;
/**
* An argument used in a property that may have undergone shrinking following falsification.
*
* @version %build.number%
*/
public final class Arg<T> {
private final T value;
private final int shrinks;
private Arg(final T value, final int shrinks) {
this.value = value;
this.shrinks = shrinks;
}
/**
* Construct a property argument with the given value and number of shrinks.
*
* @param value The value to construct an argument with.
* @param shrinks The number of shrinks to construct an argument with.
* @return A new argument.
*/
public static <T> Arg<T> arg(final T value, final int shrinks) {
return new Arg<T>(value, shrinks);
}
/**
* Returns the argument's value.
*
* @return The argument's value.
*/
public Object value() {
return value;
}
/**
* Returns the argument's number of shrinks following falsification.
*
* @return The argument's number of shrinks following falsification.
*/
public int shrinks() {
return shrinks;
}
/**
* The rendering of an argument (uses {@link Object#toString()} for the argument value).
*/
public static final Show<Arg<?>> argShow = showS(new F<Arg<?>, String>() {
public String f(final Arg<?> arg) {
return anyShow().showS(arg.value) +
(arg.shrinks > 0 ? " (" + arg.shrinks + " shrink" + (arg.shrinks == 1 ? "" : 's') + ')' : "");
}
});
}