index null validation
This commit is contained in:
parent
cc973b0a28
commit
70506bb040
@ -132,6 +132,11 @@ public class Index<K, V> {
|
|||||||
* @return true if the key already existed and was overwritten; false otherwise.
|
* @return true if the key already existed and was overwritten; false otherwise.
|
||||||
*/
|
*/
|
||||||
public synchronized boolean put(K key, V value) {
|
public synchronized boolean put(K key, V value) {
|
||||||
|
if (key == null)
|
||||||
|
throw new IllegalArgumentException("An index key may not be null");
|
||||||
|
if (value == null)
|
||||||
|
throw new IllegalArgumentException("An index value may not be null");
|
||||||
|
|
||||||
boolean overwrote = false;
|
boolean overwrote = false;
|
||||||
|
|
||||||
V oldValue = this.forwardMap.get(key);
|
V oldValue = this.forwardMap.get(key);
|
||||||
@ -159,6 +164,9 @@ public class Index<K, V> {
|
|||||||
* @return true if the key and its value were removed; false otherwise.
|
* @return true if the key and its value were removed; false otherwise.
|
||||||
*/
|
*/
|
||||||
public synchronized boolean remove(K key) {
|
public synchronized boolean remove(K key) {
|
||||||
|
if (key == null)
|
||||||
|
throw new IllegalArgumentException("An index key may not be null");
|
||||||
|
|
||||||
V oldValue = this.forwardMap.remove(key);
|
V oldValue = this.forwardMap.remove(key);
|
||||||
if (oldValue == null)
|
if (oldValue == null)
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user