| 1 | package pro.verron.officestamper.preset; | |
| 2 | ||
| 3 | import org.jspecify.annotations.Nullable; | |
| 4 | import org.springframework.expression.AccessException; | |
| 5 | import org.springframework.expression.EvaluationContext; | |
| 6 | import org.springframework.expression.PropertyAccessor; | |
| 7 | import org.springframework.expression.TypedValue; | |
| 8 | import org.springframework.util.Assert; | |
| 9 | ||
| 10 | import java.util.Map; | |
| 11 | ||
| 12 | /// MapAccessor is an implementation of the [PropertyAccessor] interface, | |
| 13 | /// designed for accessing and manipulating properties specifically on Map objects. | |
| 14 | /// It provides functionality to read and write entries in a Map based on the | |
| 15 | /// property name provided. | |
| 16 | public class MapAccessor | |
| 17 | implements PropertyAccessor { | |
| 18 | ||
| 19 | /// Constructs a new instance of `MapAccessor`. | |
| 20 | public MapAccessor(){ | |
| 21 | // Explicit default constructor for Javadoc | |
| 22 | } | |
| 23 | ||
| 24 | @Override | |
| 25 | public Class<?>[] getSpecificTargetClasses() { | |
| 26 |
1
1. getSpecificTargetClasses : replaced return value with null for pro/verron/officestamper/preset/MapAccessor::getSpecificTargetClasses → TIMED_OUT |
return new Class<?>[]{Map.class}; |
| 27 | } | |
| 28 | ||
| 29 | @Override | |
| 30 | public boolean canRead(EvaluationContext context, @Nullable Object target, String name) { | |
| 31 |
3
1. canRead : negated conditional → TIMED_OUT 2. canRead : negated conditional → TIMED_OUT 3. canRead : replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canRead → TIMED_OUT |
return (target instanceof Map<?, ?> map && map.containsKey(name)); |
| 32 | } | |
| 33 | ||
| 34 | @Override | |
| 35 | public TypedValue read(EvaluationContext context, @Nullable Object target, String name) | |
| 36 | throws AccessException { | |
| 37 |
1
1. read : removed call to org/springframework/util/Assert::state → TIMED_OUT |
Assert.state(target instanceof Map, "Target must be of type Map"); |
| 38 | Map<?, ?> map = (Map<?, ?>) target; | |
| 39 | Object value = map.get(name); | |
| 40 |
2
1. read : negated conditional → TIMED_OUT 2. read : negated conditional → TIMED_OUT |
if (value == null && !map.containsKey(name)) { |
| 41 | throw new MapAccessException(name); | |
| 42 | } | |
| 43 |
1
1. read : replaced return value with null for pro/verron/officestamper/preset/MapAccessor::read → KILLED |
return new TypedValue(value); |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) { | |
| 48 |
2
1. canWrite : replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE 2. canWrite : replaced boolean return with false for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE |
return target instanceof Map; |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | @SuppressWarnings("unchecked") | |
| 53 | public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) { | |
| 54 |
1
1. write : removed call to org/springframework/util/Assert::state → NO_COVERAGE |
Assert.state(target instanceof Map, "Target must be of type Map"); |
| 55 | Map<Object, @Nullable Object> map = (Map<Object, Object>) target; | |
| 56 | map.put(name, newValue); | |
| 57 | } | |
| 58 | ||
| 59 | /// Exception thrown from `read` in order to reset a cached | |
| 60 | /// PropertyAccessor, allowing other accessors to have a try. | |
| 61 | private static class MapAccessException | |
| 62 | extends AccessException { | |
| 63 | ||
| 64 | private final String key; | |
| 65 | ||
| 66 | public MapAccessException(String key) { | |
| 67 | super(""); | |
| 68 | this.key = key; | |
| 69 | } | |
| 70 | ||
| 71 | @Override | |
| 72 | public String getMessage() { | |
| 73 |
1
1. getMessage : replaced return value with "" for pro/verron/officestamper/preset/MapAccessor$MapAccessException::getMessage → NO_COVERAGE |
return "Map does not contain a value for key '" + this.key + "'"; |
| 74 | } | |
| 75 | } | |
| 76 | } | |
Mutations | ||
| 26 |
1.1 |
|
| 31 |
1.1 2.2 3.3 |
|
| 37 |
1.1 |
|
| 40 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 48 |
1.1 2.2 |
|
| 54 |
1.1 |
|
| 73 |
1.1 |