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