| 1 | package fr.sii.ogham.core.template.context; | |
| 2 | ||
| 3 | import java.util.HashMap; | |
| 4 | import java.util.Map; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.util.EqualsBuilder; | |
| 7 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
| 8 | ||
| 9 | /** | |
| 10 | * Simple context that stores variable substitutions into a map. This map in | |
| 11 | * then provided directly when calling {@link #getVariables()}. | |
| 12 | * | |
| 13 | * @author Aurélien Baudet | |
| 14 | * | |
| 15 | */ | |
| 16 | public class SimpleContext implements Context { | |
| 17 | ||
| 18 | /** | |
| 19 | * The variable values indexed by the variable names | |
| 20 | */ | |
| 21 | private Map<String, Object> variables; | |
| 22 | ||
| 23 | /** | |
| 24 | * Initialize the variables with only one entry. | |
| 25 | * | |
| 26 | * @param variable | |
| 27 | * the name of the variable | |
| 28 | * @param value | |
| 29 | * the value of the variable | |
| 30 | */ | |
| 31 | public SimpleContext(String variable, Object value) { | |
| 32 | this(new HashMap<>()); | |
| 33 | addValue(variable, value); | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Initialize the variables with the provided map. The map is used as is. | |
| 38 | * | |
| 39 | * @param variables | |
| 40 | * the variable values indexed by the variable names | |
| 41 | */ | |
| 42 | public SimpleContext(Map<String, Object> variables) { | |
| 43 | super(); | |
| 44 | this.variables = variables; | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Add a new variable entry. | |
| 49 | * | |
| 50 | * @param variable | |
| 51 | * the name of the variable | |
| 52 | * @param value | |
| 53 | * the value of the variable | |
| 54 | * @return the context for fluent use | |
| 55 | */ | |
| 56 | public final SimpleContext addValue(String variable, Object value) { | |
| 57 | variables.put(variable, value); | |
| 58 |
1
1. addValue : replaced return value with null for fr/sii/ogham/core/template/context/SimpleContext::addValue → NO_COVERAGE |
return this; |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public Map<String, Object> getVariables() { | |
| 63 |
1
1. getVariables : replaced return value with null for fr/sii/ogham/core/template/context/SimpleContext::getVariables → NO_COVERAGE |
return variables; |
| 64 | } | |
| 65 | ||
| 66 | @Override | |
| 67 | public int hashCode() { | |
| 68 |
1
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/template/context/SimpleContext::hashCode → NO_COVERAGE |
return new HashCodeBuilder().append(variables).hashCode(); |
| 69 | } | |
| 70 | ||
| 71 | @Override | |
| 72 | public boolean equals(Object obj) { | |
| 73 |
2
1. equals : replaced boolean return with false for fr/sii/ogham/core/template/context/SimpleContext::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/core/template/context/SimpleContext::equals → NO_COVERAGE |
return new EqualsBuilder(this, obj).appendFields("variables").isEqual(); |
| 74 | } | |
| 75 | } | |
Mutations | ||
| 58 |
1.1 |
|
| 63 |
1.1 |
|
| 68 |
1.1 |
|
| 73 |
1.1 2.2 |