From b7e6a86c1e9b5920af696e7f7149d4675fbf0485 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 5 Jul 2013 14:07:51 +0900 Subject: [PATCH] Add MessageList.first() and last() for convenience. - Fixes #1530 --- .../java/io/netty/channel/MessageList.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/transport/src/main/java/io/netty/channel/MessageList.java b/transport/src/main/java/io/netty/channel/MessageList.java index 35f0cd8593..3a3d5b0c49 100644 --- a/transport/src/main/java/io/netty/channel/MessageList.java +++ b/transport/src/main/java/io/netty/channel/MessageList.java @@ -206,6 +206,32 @@ public final class MessageList implements Iterable { return elements[index]; } + /** + * Returns the first message in this list. + * + * @throws NoSuchElementException if this list is empty + */ + public T first() { + if (size != 0) { + return elements[0]; + } else { + throw new NoSuchElementException(); + } + } + + /** + * Returns the last message in this list. + * + * @throws NoSuchElementException if this list is empty + */ + public T last() { + if (size != 0) { + return elements[size - 1]; + } else { + throw new NoSuchElementException(); + } + } + /** * Sets the message on the given index. */