Change mutate on drafts to be a bit faster.
This commit is contained in:
parent
f9b1563bdd
commit
11de7015c2
1 changed files with 14 additions and 19 deletions
|
@ -107,28 +107,24 @@ public abstract class AbstractEntityDraft<E> implements Drafted<E> {
|
||||||
return (T) mutate(this.<T>methodNameFor(getter), value);
|
return (T) mutate(this.<T>methodNameFor(getter), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object mutate(String key, Object value) {
|
public <T> T mutate(String key, T value) {
|
||||||
Objects.requireNonNull(key);
|
Objects.requireNonNull(key);
|
||||||
|
|
||||||
if (value == null) {
|
if (value != null) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
Map<String, Object> map = entity.toMap();
|
if (entityMap.containsKey(key)) {
|
||||||
|
T currentValue = this.<T>fetch(key);
|
||||||
if (map.containsKey(key) && !value.equals(map.get(key))) {
|
if (currentValue != null && !value.equals(currentValue)) {
|
||||||
backingMap.put(key, value);
|
backingMap.put(key, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return map.get(key);
|
|
||||||
} else {
|
} else {
|
||||||
backingMap.put(key, value);
|
backingMap.put(key, value);
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private <T> String methodNameFor(Getter<T> getter) {
|
private <T> String methodNameFor(Getter<T> getter) {
|
||||||
return MappingUtil.resolveMappingProperty(getter).getProperty().getPropertyName();
|
return MappingUtil.resolveMappingProperty(getter).getProperty().getPropertyName();
|
||||||
|
@ -153,7 +149,6 @@ public abstract class AbstractEntityDraft<E> implements Drafted<E> {
|
||||||
|
|
||||||
private <T> T fetch(String key) {
|
private <T> T fetch(String key) {
|
||||||
T value = (T) backingMap.get(key);
|
T value = (T) backingMap.get(key);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = (T) entityMap.get(key);
|
value = (T) entityMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue