From 9a16143c896a0979a0e2547c27f9511ae3da0668 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Tue, 5 Mar 2013 16:50:59 +0100 Subject: [PATCH] Small documentation fix. --- .../protocol/concurrency/BlockingHashMap.java | 23 +++++++++++++++++++ .../server/InputStreamReflectLookup.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/BlockingHashMap.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/BlockingHashMap.java index 9d90b7d8..78854be4 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/BlockingHashMap.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/BlockingHashMap.java @@ -204,6 +204,29 @@ public class BlockingHashMap { } } + /** + * If and only if a key is not present in the map will it be associated with the given value. + * @param key - the key to associate. + * @param value - the value to associate. + * @return The previous value this key has been associated with. + */ + public TValue putIfAbsent(TKey key, TValue value) { + if (value == null) + throw new IllegalArgumentException("This map doesn't support NULL values."); + + final TValue previous = backingMap.putIfAbsent(key, value); + + // No need to unlock readers if we haven't changed anything + if (previous == null) { + final Object lock = getLock(key); + + synchronized (lock) { + lock.notifyAll(); + } + } + return previous; + } + public int size() { return backingMap.size(); } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/InputStreamReflectLookup.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/InputStreamReflectLookup.java index 2d971f5a..f374e9e9 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/InputStreamReflectLookup.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/server/InputStreamReflectLookup.java @@ -64,7 +64,7 @@ class InputStreamReflectLookup extends AbstractInputStreamLookup { return null; } } - + @Override public SocketInjector waitSocketInjector(SocketAddress address) { try {