1 | package pro.verron.officestamper.api; | |
2 | ||
3 | import org.docx4j.wml.R; | |
4 | import org.springframework.lang.Nullable; | |
5 | ||
6 | import static pro.verron.officestamper.utils.WmlFactory.newRun; | |
7 | ||
8 | /// This is an abstract class that provides a generic implementation for | |
9 | /// resolving objects to strings. It is used in conjunction with | |
10 | /// [ObjectResolver] interface to provide a flexible way to | |
11 | /// resolve different types of objects to strings. | |
12 | /// | |
13 | /// @param <T> the type of the object to resolve | |
14 | /// | |
15 | /// @author Joseph Verron | |
16 | /// @version ${version} | |
17 | /// @since 1.6.7 | |
18 | public abstract class StringResolver<T> | |
19 | implements ObjectResolver { | |
20 | ||
21 | private final Class<T> type; | |
22 | ||
23 | /// Creates a new StringResolver with the given type. | |
24 | /// | |
25 | /// @param type the type of object to be resolved | |
26 | protected StringResolver(Class<T> type) { | |
27 | assert type != null; | |
28 | this.type = type; | |
29 | } | |
30 | ||
31 | /// Resolves an object to a string and creates a new run with the resolved string as content. | |
32 | /// | |
33 | /// @param document the WordprocessingMLPackage document | |
34 | /// @param expression the expression string | |
35 | /// @param object the object to be resolved | |
36 | /// | |
37 | /// @return the newly created run with the resolved string as content | |
38 | @Override | |
39 | public final R resolve( | |
40 | DocxPart document, | |
41 | String expression, | |
42 | Object object | |
43 | ) { | |
44 |
1
1. resolve : replaced return value with null for pro/verron/officestamper/api/StringResolver::resolve → KILLED |
return newRun(resolve(type.cast(object))); |
45 | } | |
46 | ||
47 | /// Determines if the given object can be resolved by the StringResolver. | |
48 | /// | |
49 | /// @param object the object to be resolved | |
50 | /// | |
51 | /// @return true if the object can be resolved, false otherwise | |
52 | @Override | |
53 | public final boolean canResolve(@Nullable Object object) { | |
54 |
2
1. canResolve : replaced boolean return with true for pro/verron/officestamper/api/StringResolver::canResolve → KILLED 2. canResolve : replaced boolean return with false for pro/verron/officestamper/api/StringResolver::canResolve → KILLED |
return type.isInstance(object); |
55 | } | |
56 | ||
57 | /// Resolves an object to a string. | |
58 | /// | |
59 | /// @param object the object to be resolved | |
60 | /// | |
61 | /// @return the string representation of the object | |
62 | protected abstract String resolve(T object); | |
63 | } | |
Mutations | ||
44 |
1.1 |
|
54 |
1.1 2.2 |