aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorImran Rashid <imran@quantifind.com>2013-02-21 16:55:14 -0800
committerImran Rashid <imran@quantifind.com>2013-02-21 16:55:14 -0800
commit9230617f238b4aab8de95173d9f1cdc0b18cdb43 (patch)
treeaa3379484beeae0ad37fe3c8dfa1ecc18002390b /core
parent81bd07da265a9fdaad366d8fd46a70df6d5c9806 (diff)
downloadspark-9230617f238b4aab8de95173d9f1cdc0b18cdb43.tar.gz
spark-9230617f238b4aab8de95173d9f1cdc0b18cdb43.tar.bz2
spark-9230617f238b4aab8de95173d9f1cdc0b18cdb43.zip
add cleanup iterator
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/spark/util/CleanupIterator.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/src/main/scala/spark/util/CleanupIterator.scala b/core/src/main/scala/spark/util/CleanupIterator.scala
new file mode 100644
index 0000000000..d2093c0230
--- /dev/null
+++ b/core/src/main/scala/spark/util/CleanupIterator.scala
@@ -0,0 +1,25 @@
+package spark.util
+
+/**
+ * Wrapper around an iterator which calls a cleanup method when its finished iterating through its elements
+ */
+abstract class CleanupIterator[+A, +I <: Iterator[A]](sub: I) extends Iterator[A]{
+ def next = sub.next
+ def hasNext = {
+ val r = sub.hasNext
+ if (!r) {
+ cleanup
+ }
+ r
+ }
+
+ def cleanup
+}
+
+object CleanupIterator {
+ def apply[A, I <: Iterator[A]](sub: I, cleanupFunction: => Unit) : CleanupIterator[A,I] = {
+ new CleanupIterator[A,I](sub) {
+ def cleanup = cleanupFunction
+ }
+ }
+} \ No newline at end of file