Let BufUtil.retain(...) return the given object

This commit is contained in:
Norman Maurer 2013-03-10 19:50:26 +01:00
parent ed825de4bf
commit 0ac5fd9f18

View File

@ -46,20 +46,24 @@ public final class BufUtil {
* Try to call {@link ReferenceCounted#retain()} if the specified message implements {@link ReferenceCounted}.
* If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing.
*/
public static void retain(Object msg) {
@SuppressWarnings("unchecked")
public static <T> T retain(T msg) {
if (msg instanceof ReferenceCounted) {
((ReferenceCounted) msg).retain();
return (T) ((ReferenceCounted) msg).retain();
}
return msg;
}
/**
* Try to call {@link ReferenceCounted#retain()} if the specified message implements {@link ReferenceCounted}.
* If the specified message doesn't implement {@link ReferenceCounted}, this method does nothing.
*/
public static void retain(Object msg, int increment) {
@SuppressWarnings("unchecked")
public static <T> T retain(T msg, int increment) {
if (msg instanceof ReferenceCounted) {
((ReferenceCounted) msg).retain(increment);
return (T) ((ReferenceCounted) msg).retain(increment);
}
return msg;
}
/**