BAEL-6600: fix flaws in the logic of put method
This commit is contained in:
parent
2f9407e765
commit
8a31837a3e
|
@ -15,13 +15,10 @@ public class HashMapWithMaxSizeLimit<K, V> extends HashMap<K, V> {
|
|||
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
V res = null;
|
||||
if (this.maxSize == -1 || this.size() < this.maxSize) {
|
||||
res = super.put(key, value);
|
||||
} else if (this.maxSize != -1) {
|
||||
throw new RuntimeException("Max size exceeded!");
|
||||
if (this.maxSize == -1 || this.containsKey(key) || this.size() < this.maxSize) {
|
||||
return super.put(key, value);
|
||||
}
|
||||
return res;
|
||||
throw new RuntimeException("Max size exceeded!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue