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