From a8bb0d074be5756f6d8899fc084f77d6f71770d5 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 29 Sep 2011 18:25:41 -0600 Subject: [PATCH] implement first() and last() in TreeSet --- classpath/java/util/TreeSet.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classpath/java/util/TreeSet.java b/classpath/java/util/TreeSet.java index 16f291a134..01e76496a2 100644 --- a/classpath/java/util/TreeSet.java +++ b/classpath/java/util/TreeSet.java @@ -41,6 +41,18 @@ public class TreeSet extends AbstractSet implements Collection { add(item); } } + + public T first() { + if (isEmpty()) throw new NoSuchElementException(); + + return set.first().value().value; + } + + public T last() { + if (isEmpty()) throw new NoSuchElementException(); + + return set.last().value().value; + } public Iterator iterator() { return new MyIterator(set.first());