Add MessageList.first() and last() for convenience.

- Fixes #1530
This commit is contained in:
Trustin Lee 2013-07-05 14:07:51 +09:00
parent 0b9235f072
commit b7e6a86c1e

View File

@ -206,6 +206,32 @@ public final class MessageList<T> implements Iterable<T> {
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.
*/