1 | package com.github.valid8j.pcond.core.fluent.builtins; | |
2 | ||
3 | import com.github.valid8j.pcond.core.fluent.AbstractObjectTransformer; | |
4 | import com.github.valid8j.pcond.forms.Functions; | |
5 | import com.github.valid8j.pcond.forms.Printables; | |
6 | import com.github.valid8j.pcond.internals.InternalUtils; | |
7 | ||
8 | import java.util.List; | |
9 | import java.util.function.Function; | |
10 | import java.util.function.Predicate; | |
11 | import java.util.function.Supplier; | |
12 | ||
13 | import static java.lang.String.format; | |
14 | ||
15 | ||
16 | /** | |
17 | * This interface is used for object whose type doesn't have an explicit support. | |
18 | * Do not try to extend/implement this class to support your own class. | |
19 | * | |
20 | * @param <T> The type of the target value of the instance of this interface. | |
21 | * @param <E> The type of the target value of the checker instance. | |
22 | * In most cases, the same type as `T` is chosen. | |
23 | */ | |
24 | public interface ObjectTransformer< | |
25 | T, | |
26 | E | |
27 | > extends | |
28 | AbstractObjectTransformer< | |
29 | ObjectTransformer<T, E>, | |
30 | ObjectChecker<T, E>, | |
31 | T, | |
32 | E> { | |
33 | ||
34 | @SuppressWarnings("unchecked") | |
35 | default ObjectTransformer<T, E> transform(Function<ObjectTransformer<T, E>, Predicate<E>> clause) { | |
36 |
2
1. lambda$transform$0 : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::lambda$transform$0 → NO_COVERAGE 2. transform : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::transform → NO_COVERAGE |
return this.addTransformAndCheckClause(tx -> clause.apply((ObjectTransformer<T, E>) tx)); |
37 | } | |
38 | ||
39 | /** | |
40 | * Lets the framework know the value to be checked is a `String`. | |
41 | * This method may throw an exception, if the value is not a `String`. | |
42 | * | |
43 | * @return A {@link StringTransformer <T>} object. | |
44 | */ | |
45 | default StringTransformer<T> asString() { | |
46 |
1
1. asString : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asString → KILLED |
return toString(Functions.cast(String.class)); |
47 | } | |
48 | ||
49 | /** | |
50 | * Lets the framework know the value to be checked is a `Integer`. | |
51 | * This method may throw an exception, if the value is not a `Integer`. | |
52 | * | |
53 | * @return A {@link IntegerTransformer <T>} object. | |
54 | */ | |
55 | default IntegerTransformer<T> asInteger() { | |
56 |
1
1. asInteger : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asInteger → KILLED |
return toInteger(Functions.cast(Integer.class)); |
57 | } | |
58 | ||
59 | /** | |
60 | * Lets the framework know the value to be checked is a `Long`. | |
61 | * This method may throw an exception, if the value is not a `Long`. | |
62 | * | |
63 | * @return A {@link LongTransformer <T>} object. | |
64 | */ | |
65 | default LongTransformer<T> asLong() { | |
66 |
1
1. asLong : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asLong → KILLED |
return toLong(Functions.cast(Long.class)); |
67 | } | |
68 | ||
69 | /** | |
70 | * Lets the framework know the value to be checked is a `Short`. | |
71 | * This method may throw an exception, if the value is not a `Short`. | |
72 | * | |
73 | * @return A {@link ShortTransformer <T>} object. | |
74 | */ | |
75 | default ShortTransformer<T> asShort() { | |
76 |
1
1. asShort : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asShort → KILLED |
return toShort(Functions.cast(Short.class)); |
77 | } | |
78 | ||
79 | /** | |
80 | * Lets the framework know the value to be checked is a `Double`. | |
81 | * This method may throw an exception, if the value is not a `Double`. | |
82 | * | |
83 | * @return A {@link DoubleTransformer <T>} object. | |
84 | */ | |
85 | default DoubleTransformer<T> asDouble() { | |
86 |
1
1. asDouble : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asDouble → KILLED |
return toDouble(Functions.cast(Double.class)); |
87 | } | |
88 | ||
89 | /** | |
90 | * Lets the framework know the value to be checked is a `Float`. | |
91 | * This method may throw an exception, if the value is not a `Float`. | |
92 | * | |
93 | * @return A {@link FloatTransformer <T>} object. | |
94 | */ | |
95 | default FloatTransformer<T> asFloat() { | |
96 |
1
1. asFloat : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asFloat → KILLED |
return toFloat(Functions.cast(Float.class)); |
97 | } | |
98 | ||
99 | /** | |
100 | * Lets the framework know the value to be checked is a `Boolean`. | |
101 | * This method may throw an exception, if the value is not a `Boolean`. | |
102 | * | |
103 | * @return A {@link BooleanTransformer <T>} object. | |
104 | */ | |
105 | default BooleanTransformer<T> asBoolean() { | |
106 | /* | |
107 | * Lets the framework know the value to be checked is a `Boolean`. | |
108 | * This method may throw an exception, if the value is not a `Boolean`. | |
109 | * | |
110 | * @return A {@link BooleanTransformer<T>} object. | |
111 | */ | |
112 |
1
1. asBoolean : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asBoolean → KILLED |
return toBoolean(Functions.cast(Boolean.class)); |
113 | } | |
114 | ||
115 | /** | |
116 | * Lets the framework know the value to be checked is a `List` of `EE`. | |
117 | * This method may throw an exception, if the value is not a `List`. | |
118 | * | |
119 | * @return A {@link ListTransformer <EE>} object. | |
120 | */ | |
121 | @SuppressWarnings("unchecked") | |
122 | default <EE> ListTransformer<T, EE> asListOf(Class<EE> type) { | |
123 |
2
1. lambda$asListOf$1 : replaced return value with Collections.emptyList for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::lambda$asListOf$1 → NO_COVERAGE 2. asListOf : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asListOf → KILLED |
return toList(Printables.function(format("castTo[List<%s>]", type.getSimpleName()), v -> (List<EE>) v)); |
124 | } | |
125 | ||
126 | /** | |
127 | * Lets the framework know the value to be checked is a `List`. | |
128 | * This method may throw an exception, if the value is not a `List`. | |
129 | * | |
130 | * @return A {@link ListTransformer <T>} object. | |
131 | */ | |
132 | @SuppressWarnings("unchecked") | |
133 | default <EE> ListTransformer<T, EE> asList() { | |
134 |
1
1. asList : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::asList → KILLED |
return (ListTransformer<T, EE>) asListOf(Object.class); |
135 | } | |
136 | ||
137 | /** | |
138 | * Creates a new Object transformer whose target value is given by a supplier. | |
139 | * | |
140 | * @param value A supplier of the target value. | |
141 | * @param <E> The type of the target value. | |
142 | * @return Created transformer. | |
143 | */ | |
144 | static <E> ObjectTransformer<E, E> create(Supplier<E> value) { | |
145 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer::create → KILLED |
return new Impl<>(value, InternalUtils.trivialIdentityFunction()); |
146 | } | |
147 | ||
148 | class Impl< | |
149 | T, | |
150 | E> extends | |
151 | Base< | |
152 | ObjectTransformer<T, E>, | |
153 | ObjectChecker<T, E>, | |
154 | T, | |
155 | E> implements | |
156 | ObjectTransformer<T, E> { | |
157 | public Impl(Supplier<T> rootValue, Function<T, E> root) { | |
158 | super(rootValue, root); | |
159 | } | |
160 | ||
161 | @Override | |
162 | protected ObjectChecker<T, E> toChecker(Function<T, E> transformFunction) { | |
163 |
1
1. toChecker : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer$Impl::toChecker → KILLED |
return new ObjectChecker.Impl<>(this::baseValue, transformFunction); |
164 | } | |
165 | ||
166 | @Override | |
167 | protected ObjectTransformer<E, E> rebase() { | |
168 |
1
1. rebase : replaced return value with null for com/github/valid8j/pcond/core/fluent/builtins/ObjectTransformer$Impl::rebase → NO_COVERAGE |
return new Impl<>(this::value, InternalUtils.trivialIdentityFunction()); |
169 | } | |
170 | ||
171 | } | |
172 | } | |
Mutations | ||
36 |
1.1 2.2 |
|
46 |
1.1 |
|
56 |
1.1 |
|
66 |
1.1 |
|
76 |
1.1 |
|
86 |
1.1 |
|
96 |
1.1 |
|
112 |
1.1 |
|
123 |
1.1 2.2 |
|
134 |
1.1 |
|
145 |
1.1 |
|
163 |
1.1 |
|
168 |
1.1 |