Property support: Use static unmodifiable Maps for common defaults - #2041
Conversation
0828d57 to
4d8d0f1
Compare
Goal: Decrease memory usage when lots of property supports are in use. 449281
4d8d0f1 to
7a101bf
Compare
paolobazzi
left a comment
There was a problem hiding this comment.
See inputs for minor improvements
| public class DefaultValueMapTest { | ||
|
|
||
| @Test | ||
| public void testIsEmptyAndSize() { |
There was a problem hiding this comment.
Add test methods for non-covered parts:
- Constructor using startEmpty=true
- containsKey
- containsValue
- size
- isEmpty
There was a problem hiding this comment.
size/isEmpty is tested by testIsEmptyAndSize - additional tests necessary?
Some other tests have been added, see https://github.com/eclipse-scout/scout.rt/compare/0d91af9a3b0a0f3a3c9a0b783d3882ca68295a28..3f51b964e32eeb523113d121e626d9125254ea83
| boolean additionalValuesContainsKey = m_additionalValues.containsKey(key); | ||
| if (m_defaultValues.containsKey(key)) { | ||
| if (isDefaultValue(key, value)) { // must be same, equals would not be sufficient | ||
| return additionalValuesContainsKey |
There was a problem hiding this comment.
code is hard to read -> split into several methods or use if then else on separate lines and prepending a javadoc indicating which case is handled
e.g.:
@Override
public Object put(String key, Object value) {
boolean additionalValuesContainsKey = m_additionalValues.containsKey(key);
if (m_defaultValues.containsKey(key)) {
if (isDefaultValue(key, value)) { // must be same, equals would not be sufficient
if (additionalValuesContainsKey) {
Object removedValue = m_additionalValues.remove(key);
return removedValue != REMOVED_MARKER ? removedValue : null;
} else {
return m_defaultValues.get(key);
}
}
else if (!additionalValuesContainsKey) {
m_additionalValues.put(key, value);
return m_defaultValues.get(key); // load previous value from default values (if any)
}
}
//....
There was a problem hiding this comment.
Simplified a bit (and added more tests because of simplification): https://github.com/eclipse-scout/scout.rt/compare/cb6eef71e529068cee3809ea3d1d7f0c2066bd51..df77bd946c25172c1065f279cfeda8023496bbfb
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class DefaultValueMapTest { |
There was a problem hiding this comment.
check for missing coverage in DefaultValueMap:
- Iterator/EntrySet.next()
- Iterator/EntrySet.remove()
- Iterator/EntrySet.size
- Iterator/EntrySet.isEmpty
There was a problem hiding this comment.
|
Added cherry-pick for 27/1, see #2322
|
Goal: Decrease memory usage when lots of property supports are in use.
449281