diff options
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/RollbackIterator.scala | 44 | ||||
-rw-r--r-- | src/library/scala/collection/Sorted.scala | 28 | ||||
-rw-r--r-- | src/library/scala/mobile/Code.scala | 11 |
3 files changed, 53 insertions, 30 deletions
diff --git a/src/library/scala/collection/RollbackIterator.scala b/src/library/scala/collection/RollbackIterator.scala index 291d72f507..81567aca03 100644 --- a/src/library/scala/collection/RollbackIterator.scala +++ b/src/library/scala/collection/RollbackIterator.scala @@ -1,28 +1,43 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + package scala.collection + import scala.collection.mutable.{ArrayBuffer} /** Rollback iterators are buffered iterators which allow for unbounded rollbacks * * @author Sean McDirmid */ -class RollbackIterator[+A](underlying : Iterator[A]) extends BufferedIterator.Default[A] { - private[this] var rollback : ArrayBuffer[A] = null - protected def fill(sz : Int) : Seq[A] = if (underlying.hasNext) underlying.next :: Nil else Nil +class RollbackIterator[+A](underlying: Iterator[A]) extends BufferedIterator.Default[A] { + private[this] var rollback: ArrayBuffer[A] = null + protected def fill(sz: Int): Seq[A] = + if (underlying.hasNext) underlying.next :: Nil else Nil - override def next : A = { + override def next: A = { val ret = super.next if (rollback != null) rollback += ret ret } - private def initRollback = if (rollback == null) { - rollback = new ArrayBuffer[A] - None - } else Some(rollback.length) + + private def initRollback = + if (rollback == null) { + rollback = new ArrayBuffer[A] + None + } + else Some(rollback.length) /** will rollback all elements iterated during * <code>f</code>'s execution if <code>f</code> return false */ - def tryRead[T](f : => Option[T]) : Option[T] = { + def tryRead[T](f: => Option[T]): Option[T] = { val oldLength = initRollback var g : Option[T] = None try { @@ -45,9 +60,9 @@ class RollbackIterator[+A](underlying : Iterator[A]) extends BufferedIterator.De /** remembers elements iterated over during <code>g</code>'s execution * and provides these elements to the result of <code>g</code>'s execution */ - def remember[T](g : => (Seq[A] => T)) : T = { + def remember[T](g: => (Seq[A] => T)): T = { val oldLength = initRollback - var in : Seq[A] = Nil + var in: Seq[A] = Nil val f = try { g } finally { @@ -56,14 +71,17 @@ class RollbackIterator[+A](underlying : Iterator[A]) extends BufferedIterator.De } f(in) } + /** returns true if any elements are iterated over during <code>f</code>'s execution */ - def read(f : => Unit) : Boolean = remember[Boolean]{ + def read(f: => Unit): Boolean = remember[Boolean] { f; seq => !seq.isEmpty } + /** if elements of <code>seq</code> will be iterated over next in this iterator, * returns true and iterates over these elements */ override def readIfStartsWith(seq : Seq[Any]) : Boolean = !tryRead{if (seq.forall(a => hasNext && next == a)) Some(()) else None}.isEmpty -}
\ No newline at end of file + +} diff --git a/src/library/scala/collection/Sorted.scala b/src/library/scala/collection/Sorted.scala index eda7c21aef..b7ce28d8dd 100644 --- a/src/library/scala/collection/Sorted.scala +++ b/src/library/scala/collection/Sorted.scala @@ -1,22 +1,23 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2006-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ // $Id$ -package scala.collection; +package scala.collection /** Any collection (including maps) whose keys (or elements) are ordered. * * @author Sean McDirmid */ trait Sorted[K,+A] extends Ranged[K,A] { + /** return as a projection the set of keys in this collection */ - def keySet : SortedSet[K]; + def keySet: SortedSet[K] /** Creates a ranged projection of this collection. Any mutations in the * ranged projection will update this collection and vice versa. Keys @@ -27,15 +28,18 @@ trait Sorted[K,+A] extends Ranged[K,A] { * @param until The upper-bound (exclusive) of the ranged projection. * <code>None</code> if there is no upper bound. */ - override def rangeImpl(from: Option[K], until: Option[K]) : Sorted[K,A]; - override def from(from: K) = rangeImpl(Some(from), None); - override def until(until: K) = rangeImpl(None, Some(until)); - override def range(from: K, until: K) = rangeImpl(Some(from),Some(until)); + override def rangeImpl(from: Option[K], until: Option[K]): Sorted[K,A] + + override def from(from: K) = rangeImpl(Some(from), None) + + override def until(until: K) = rangeImpl(None, Some(until)) + + override def range(from: K, until: K) = rangeImpl(Some(from),Some(until)) /** Create a range projection of this collection with no lower-bound. * @param to The upper-bound (inclusive) of the ranged projection. */ - def to(to : K): Sorted[K,A] = { + def to(to: K): Sorted[K,A] = { // tough! val i = keySet.from(to).elements; if (!i.hasNext) return this; @@ -45,7 +49,8 @@ trait Sorted[K,+A] extends Ranged[K,A] { else return until(i.next); } else return until(next); } - protected def hasAll(j : Iterator[K]) : Boolean = { + + protected def hasAll(j: Iterator[K]): Boolean = { val i = keySet.elements; if (!i.hasNext) return !j.hasNext; var in = i.next; @@ -59,6 +64,7 @@ trait Sorted[K,+A] extends Ranged[K,A] { else true; }) in = i.next; } - return true; + true } + } diff --git a/src/library/scala/mobile/Code.scala b/src/library/scala/mobile/Code.scala index ba7a5b8fb4..0ff0092b23 100644 --- a/src/library/scala/mobile/Code.scala +++ b/src/library/scala/mobile/Code.scala @@ -195,7 +195,7 @@ class Code(clazz: java.lang.Class[_]) { private def applyFun(methName: String, args: Array[JObject], argTypes: Array[Class[T] forSome { type T }]): JObject = { try { - val method = clazz.getMethod(methName, argTypes: _*) + val method = clazz.getMethod(methName, argTypes) var obj: JObject = null if (! Modifier.isStatic(method.getModifiers())) { if (instance eq null) { @@ -205,7 +205,7 @@ class Code(clazz: java.lang.Class[_]) { val cs = clazz.getConstructors() //Console.println("cs.length=" + cs.length); if (cs.length > 0) { - cs(0).newInstance(Array(""): _*).asInstanceOf[AnyRef] + cs(0).newInstance(Array("")).asInstanceOf[AnyRef] } else { error("class " + clazz.getName() + " has no public constructor") null @@ -214,15 +214,15 @@ class Code(clazz: java.lang.Class[_]) { } obj = instance } - val result = method.invoke(obj, args: _*) + val result = method.invoke(obj, args) if (result eq null) ().asInstanceOf[JObject] else result } catch { case me: NoSuchMethodException => if (isConstructorName(methName)) { try { - val cstr = clazz.getConstructor(argTypes: _*) - instance = cstr.newInstance(args: _*).asInstanceOf[AnyRef] + val cstr = clazz.getConstructor(argTypes) + instance = cstr.newInstance(args).asInstanceOf[AnyRef] instance } catch { @@ -244,4 +244,3 @@ class Code(clazz: java.lang.Class[_]) { } } - |