| 1 | package fr.sii.ogham.core.util.bean; | |
| 2 | ||
| 3 | import java.util.Collection; | |
| 4 | import java.util.HashSet; | |
| 5 | import java.util.List; | |
| 6 | import java.util.Map; | |
| 7 | import java.util.Set; | |
| 8 | import java.util.TreeSet; | |
| 9 | ||
| 10 | import fr.sii.ogham.core.exception.util.InvalidPropertyException; | |
| 11 | ||
| 12 | /** | |
| 13 | * Wraps a bean and exposes as a Map. | |
| 14 | * | |
| 15 | * The Map is indexed by the property names defined in the bean and allow to | |
| 16 | * access the value using the Map insterface. | |
| 17 | * | |
| 18 | * This implementation doesn't support update methods (remove, clear, put...) | |
| 19 | * and doesn't support access to values directly (values, containsValue). | |
| 20 | * | |
| 21 | * This implementation delegates access to real bean properties through a | |
| 22 | * {@link SimpleBeanReadWrapper} instance (by default). You can | |
| 23 | * override this default wrapper using the constructor | |
| 24 | * {@link #MapBeanReadWrapper(BeanReadWrapper)}. | |
| 25 | * | |
| 26 | * @author Aurélien Baudet | |
| 27 | * | |
| 28 | */ | |
| 29 | public class MapBeanReadWrapper implements BeanReadWrapper, Map<String, Object> { | |
| 30 | private final BeanReadWrapper delegate; | |
| 31 | ||
| 32 | /** | |
| 33 | * Initializes the wrapper for the provided bean. | |
| 34 | * | |
| 35 | * {@link SimpleBeanReadWrapper} is used to access bean | |
| 36 | * properties. | |
| 37 | * | |
| 38 | * @param bean | |
| 39 | * the bean to wrap | |
| 40 | */ | |
| 41 | public MapBeanReadWrapper(Object bean) { | |
| 42 | this(bean, true); | |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Initializes the wrapper for the provided bean. | |
| 47 | * | |
| 48 | * {@link SimpleBeanReadWrapper} is used to access bean | |
| 49 | * properties. | |
| 50 | * | |
| 51 | * @param bean | |
| 52 | * the bean to wrap | |
| 53 | * @param failOnMissingProperty | |
| 54 | * if false null is returned if the property doesn't exist, if | |
| 55 | * true an {@link InvalidPropertyException} is thrown if the | |
| 56 | * property doesn't exist | |
| 57 | */ | |
| 58 | public MapBeanReadWrapper(Object bean, boolean failOnMissingProperty) { | |
| 59 | this(new SimpleBeanReadWrapper(bean, failOnMissingProperty)); | |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Point of extension by providing custom bean wrapper. | |
| 64 | * | |
| 65 | * @param delegate | |
| 66 | * the bean wrapper that access bean properties | |
| 67 | */ | |
| 68 | public MapBeanReadWrapper(BeanReadWrapper delegate) { | |
| 69 | super(); | |
| 70 | this.delegate = delegate; | |
| 71 | } | |
| 72 | ||
| 73 | @Override | |
| 74 | public int size() { | |
| 75 |
8
1. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → NO_COVERAGE 2. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → TIMED_OUT 3. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED 4. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED 5. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED 6. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED 7. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED 8. size : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::size → KILLED |
return getProperties().size(); |
| 76 | } | |
| 77 | ||
| 78 | @Override | |
| 79 | public boolean isEmpty() { | |
| 80 |
4
1. isEmpty : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::isEmpty → NO_COVERAGE 2. isEmpty : negated conditional → NO_COVERAGE 3. isEmpty : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::isEmpty → KILLED 4. isEmpty : negated conditional → KILLED |
return size() == 0; |
| 81 | } | |
| 82 | ||
| 83 | @Override | |
| 84 | public boolean containsKey(Object key) { | |
| 85 | for (String prop : getProperties()) { | |
| 86 |
2
1. containsKey : negated conditional → NO_COVERAGE 2. containsKey : negated conditional → KILLED |
if (prop.equals(key)) { |
| 87 |
2
1. containsKey : replaced boolean return with false for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::containsKey → NO_COVERAGE 2. containsKey : replaced boolean return with false for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::containsKey → KILLED |
return true; |
| 88 | } | |
| 89 | } | |
| 90 |
2
1. containsKey : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::containsKey → NO_COVERAGE 2. containsKey : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::containsKey → KILLED |
return false; |
| 91 | } | |
| 92 | ||
| 93 | @Override | |
| 94 | public boolean containsValue(Object value) { | |
| 95 | throw new UnsupportedOperationException("containsValue not implemented"); | |
| 96 | } | |
| 97 | ||
| 98 | @Override | |
| 99 | public Object get(Object key) { | |
| 100 |
2
1. get : negated conditional → NO_COVERAGE 2. get : negated conditional → KILLED |
if (key == null) { |
| 101 | throw new IllegalArgumentException("key must not be null"); | |
| 102 | } | |
| 103 |
2
1. get : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::get → NO_COVERAGE 2. get : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::get → KILLED |
return getPropertyValue(key.toString()); |
| 104 | } | |
| 105 | ||
| 106 | @Override | |
| 107 | public Object put(String key, Object value) { | |
| 108 | throw new UnsupportedOperationException("put not implemented"); | |
| 109 | } | |
| 110 | ||
| 111 | @Override | |
| 112 | public Object remove(Object key) { | |
| 113 | throw new UnsupportedOperationException("remove not implemented"); | |
| 114 | } | |
| 115 | ||
| 116 | @Override | |
| 117 | public void putAll(Map<? extends String, ? extends Object> m) { | |
| 118 | throw new UnsupportedOperationException("putAll not implemented"); | |
| 119 | } | |
| 120 | ||
| 121 | @Override | |
| 122 | public void clear() { | |
| 123 | throw new UnsupportedOperationException("clear not implemented"); | |
| 124 | } | |
| 125 | ||
| 126 | @Override | |
| 127 | public Set<String> keySet() { | |
| 128 |
2
1. keySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::keySet → NO_COVERAGE 2. keySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::keySet → KILLED |
return new HashSet<>(delegate.getProperties()); |
| 129 | } | |
| 130 | ||
| 131 | @Override | |
| 132 | public Collection<Object> values() { | |
| 133 | throw new UnsupportedOperationException("values not implemented"); | |
| 134 | } | |
| 135 | ||
| 136 | @Override | |
| 137 | public Set<Entry<String, Object>> entrySet() { | |
| 138 | Set<Entry<String, Object>> entries = new TreeSet<>(); | |
| 139 | for (String prop : getProperties()) { | |
| 140 | entries.add(new MapBeanReadWrapperEntry(delegate, prop)); | |
| 141 | } | |
| 142 |
8
1. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → NO_COVERAGE 2. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → TIMED_OUT 3. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED 4. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED 5. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED 6. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED 7. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED 8. entrySet : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::entrySet → KILLED |
return entries; |
| 143 | } | |
| 144 | ||
| 145 | @Override | |
| 146 | public Object getPropertyValue(String name) { | |
| 147 |
2
1. getPropertyValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getPropertyValue → NO_COVERAGE 2. getPropertyValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getPropertyValue → KILLED |
return delegate.getPropertyValue(name); |
| 148 | } | |
| 149 | ||
| 150 | @Override | |
| 151 | public List<String> getProperties() { | |
| 152 |
8
1. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → NO_COVERAGE 2. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → TIMED_OUT 3. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED 4. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED 5. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED 6. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED 7. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED 8. getProperties : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getProperties → KILLED |
return delegate.getProperties(); |
| 153 | } | |
| 154 | ||
| 155 | @Override | |
| 156 | public Object getWrappedBean() { | |
| 157 |
1
1. getWrappedBean : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper::getWrappedBean → NO_COVERAGE |
return delegate.getWrappedBean(); |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Specific Entry implementation that delegates to a real bean wrapper in order | |
| 162 | * to access bean properties. | |
| 163 | * | |
| 164 | * @author Aurélien Baudet | |
| 165 | * | |
| 166 | */ | |
| 167 | public static class MapBeanReadWrapperEntry implements Entry<String, Object>, Comparable<MapBeanReadWrapperEntry> { | |
| 168 | private final BeanReadWrapper delegate; | |
| 169 | private final String key; | |
| 170 | ||
| 171 | public MapBeanReadWrapperEntry(BeanReadWrapper delegate, String key) { | |
| 172 | super(); | |
| 173 | this.delegate = delegate; | |
| 174 | this.key = key; | |
| 175 | } | |
| 176 | ||
| 177 | @Override | |
| 178 | public String getKey() { | |
| 179 |
8
1. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → NO_COVERAGE 2. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → TIMED_OUT 3. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED 4. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED 5. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED 6. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED 7. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED 8. getKey : replaced return value with "" for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getKey → KILLED |
return key; |
| 180 | } | |
| 181 | ||
| 182 | @Override | |
| 183 | public Object getValue() { | |
| 184 |
7
1. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → NO_COVERAGE 2. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → TIMED_OUT 3. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → KILLED 4. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → KILLED 5. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → KILLED 6. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → KILLED 7. getValue : replaced return value with null for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::getValue → KILLED |
return delegate.getPropertyValue(key); |
| 185 | } | |
| 186 | ||
| 187 | @Override | |
| 188 | public Object setValue(Object value) { | |
| 189 | throw new UnsupportedOperationException("entry.setValue not implemented"); | |
| 190 | } | |
| 191 | ||
| 192 | @Override | |
| 193 | public int compareTo(MapBeanReadWrapperEntry o) { | |
| 194 |
8
1. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → NO_COVERAGE 2. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → TIMED_OUT 3. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED 4. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED 5. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED 6. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED 7. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED 8. compareTo : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::compareTo → KILLED |
return key.compareTo(o.getKey()); |
| 195 | } | |
| 196 | ||
| 197 | @Override | |
| 198 | public int hashCode() { | |
| 199 | int prime = 31; | |
| 200 | int result = 1; | |
| 201 |
3
1. hashCode : Replaced integer multiplication with division → NO_COVERAGE 2. hashCode : Replaced integer addition with subtraction → NO_COVERAGE 3. hashCode : negated conditional → NO_COVERAGE |
result = prime * result + ((key == null) ? 0 : key.hashCode()); |
| 202 |
1
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::hashCode → NO_COVERAGE |
return result; |
| 203 | } | |
| 204 | ||
| 205 | @Override | |
| 206 | public boolean equals(Object obj) { | |
| 207 |
1
1. equals : negated conditional → NO_COVERAGE |
if (this == obj) { |
| 208 |
1
1. equals : replaced boolean return with false for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return true; |
| 209 | } | |
| 210 |
1
1. equals : negated conditional → NO_COVERAGE |
if (obj == null) { |
| 211 |
1
1. equals : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return false; |
| 212 | } | |
| 213 |
1
1. equals : negated conditional → NO_COVERAGE |
if (obj.getClass() != getClass()) { |
| 214 |
1
1. equals : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return false; |
| 215 | } | |
| 216 | MapBeanReadWrapperEntry other = (MapBeanReadWrapperEntry) obj; | |
| 217 |
1
1. equals : negated conditional → NO_COVERAGE |
if (key == null) { |
| 218 |
1
1. equals : negated conditional → NO_COVERAGE |
if (other.key != null) { |
| 219 |
1
1. equals : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return false; |
| 220 | } | |
| 221 |
1
1. equals : negated conditional → NO_COVERAGE |
} else if (!key.equals(other.key)) { |
| 222 |
1
1. equals : replaced boolean return with true for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return false; |
| 223 | } | |
| 224 |
1
1. equals : replaced boolean return with false for fr/sii/ogham/core/util/bean/MapBeanReadWrapper$MapBeanReadWrapperEntry::equals → NO_COVERAGE |
return true; |
| 225 | } | |
| 226 | } | |
| 227 | } | |
Mutations | ||
| 75 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 80 |
1.1 2.2 3.3 4.4 |
|
| 86 |
1.1 2.2 |
|
| 87 |
1.1 2.2 |
|
| 90 |
1.1 2.2 |
|
| 100 |
1.1 2.2 |
|
| 103 |
1.1 2.2 |
|
| 128 |
1.1 2.2 |
|
| 142 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 147 |
1.1 2.2 |
|
| 152 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 157 |
1.1 |
|
| 179 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 184 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 194 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 201 |
1.1 2.2 3.3 |
|
| 202 |
1.1 |
|
| 207 |
1.1 |
|
| 208 |
1.1 |
|
| 210 |
1.1 |
|
| 211 |
1.1 |
|
| 213 |
1.1 |
|
| 214 |
1.1 |
|
| 217 |
1.1 |
|
| 218 |
1.1 |
|
| 219 |
1.1 |
|
| 221 |
1.1 |
|
| 222 |
1.1 |
|
| 224 |
1.1 |