Skip to content

Commit

Permalink
Let BufUtil.retain(...) return the given object
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Mar 10, 2013
1 parent ed825de commit 0ac5fd9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions buffer/src/main/java/io/netty/buffer/BufUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 0ac5fd9

Please sign in to comment.