if(obj.getAttribute() != null) {
newobject.setAttribute(obj.getAttribute());
}
if(obj.getAttribute() != null) {
newobject.setAttribute(obj.getAttribute());
}
if(obj.getAttribute() != null) {
newobject.setAttribute(obj.getAttribute());
}
Imagine this code at scale - mapping an object with 15+ attributes. How do I reduce cognitive complexity without splitting the mapping in two/three parts which increases the cognitive complexity overall.
You might use
OptionallikeBut it depends of what should happen when
obj.getAttribute()is empty ?From what is provided
newobject.attributewill be empty anyway, assigning property from parent does not require null-check.