diff options
author | michelou <michelou@epfl.ch> | 2006-09-21 10:33:43 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2006-09-21 10:33:43 +0000 |
commit | 2282fe8e8d2e16679aa4a612fdf2fc410006759d (patch) | |
tree | 7739f08d8237e10c71283721f25220516dfc2df9 /src/library | |
parent | 8bb69c4fa852b784569b43a83d41a4834bebfabf (diff) | |
download | scala-2282fe8e8d2e16679aa4a612fdf2fc410006759d.tar.gz scala-2282fe8e8d2e16679aa4a612fdf2fc410006759d.tar.bz2 scala-2282fe8e8d2e16679aa4a612fdf2fc410006759d.zip |
removed leading/trailing tabs/blanks in scala/c...
removed leading/trailing tabs/blanks in scala/concurrent/*.scala
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Application.scala | 2 | ||||
-rw-r--r-- | src/library/scala/Attribute.scala | 10 | ||||
-rw-r--r-- | src/library/scala/BigInt.scala | 57 | ||||
-rw-r--r-- | src/library/scala/BufferedIterator.scala | 3 | ||||
-rw-r--r-- | src/library/scala/CaseClass.scala | 7 | ||||
-rw-r--r-- | src/library/scala/Ordered.scala | 17 | ||||
-rw-r--r-- | src/library/scala/PartiallyOrdered.scala | 11 | ||||
-rw-r--r-- | src/library/scala/collection/BitSet.scala | 6 | ||||
-rw-r--r-- | src/library/scala/concurrent/Channel.scala | 35 | ||||
-rw-r--r-- | src/library/scala/concurrent/Lock.scala | 16 | ||||
-rw-r--r-- | src/library/scala/concurrent/MailBox.scala | 106 | ||||
-rw-r--r-- | src/library/scala/concurrent/NameServer.scala | 34 | ||||
-rw-r--r-- | src/library/scala/concurrent/Process.scala | 44 | ||||
-rw-r--r-- | src/library/scala/concurrent/TIMEOUT.scala | 10 |
14 files changed, 209 insertions, 149 deletions
diff --git a/src/library/scala/Application.scala b/src/library/scala/Application.scala index c2be7c9f54..f5db3c40ac 100644 --- a/src/library/scala/Application.scala +++ b/src/library/scala/Application.scala @@ -33,7 +33,7 @@ package scala * </pre> * * @author Matthias Zenger - * @version 1.0, 10/09/03 + * @version 1.0, 10/09/2003 */ trait Application { diff --git a/src/library/scala/Attribute.scala b/src/library/scala/Attribute.scala index 404661295f..5cce5c2ec1 100644 --- a/src/library/scala/Attribute.scala +++ b/src/library/scala/Attribute.scala @@ -9,9 +9,11 @@ // $Id$ -package scala; - +package scala /** A base class for attributes -*/ -class Attribute {} + * + * @author Martin Odersky + * @version 1.0, 15/07/2004 + */ +class Attribute diff --git a/src/library/scala/BigInt.scala b/src/library/scala/BigInt.scala index a306a7a718..be2d00d5e5 100644 --- a/src/library/scala/BigInt.scala +++ b/src/library/scala/BigInt.scala @@ -1,4 +1,14 @@ -package scala; +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + +package scala import java.math.BigInteger import java.util.Random @@ -9,11 +19,15 @@ import java.util.Random */ object BigInt { - private val minCached = -1024; - private val maxCached = 1024; + private val minCached = -1024 + private val maxCached = 1024 private val cache = new Array[BigInt](maxCached - minCached + 1) - /** Constructs a BigInt whose value is equal to that of the specified integer value. + /** Constructs a <code>BigInt</code> whose value is equal to that of the + * specified integer value. + * + * @param i the specified integer value + * @return the constructed <code>BigInt</code> */ def apply(i: Int): BigInt = if (minCached <= i && i <= maxCached) { @@ -22,7 +36,11 @@ object BigInt { n } else new BigInt(BigInteger.valueOf(i)) - /** Constructs a BigInt whose value is equal to that of the specified long value. + /** Constructs a <code>BigInt</code> whose value is equal to that of the + * specified long value. + * + * @param l the specified long value + * @return the constructed <code>BigInt</code> */ def apply(l: Long): BigInt = if (minCached <= l && l <= maxCached) apply(l.toInt) @@ -45,8 +63,12 @@ object BigInt { def apply(bitlength: Int, certaInty: Int, rnd: Random): BigInt = new BigInt(new BigInteger(bitlength, certaInty, rnd)) - /** Constructs a randomly generated BigInt, uniformly distributed over the range - * 0 to (2 ^ numBits - 1), inclusive. + /** Constructs a randomly generated BigInt, uniformly distributed over the + * range 0 to (2 ^ numBits - 1), inclusive. + * + * @param numbits ... + * @param rnd ... + * @return ... */ def apply(numbits: Int, rnd: Random): BigInt = new BigInt(new BigInteger(numbits, rnd)) @@ -56,8 +78,12 @@ object BigInt { def apply(x: String): BigInt = new BigInt(new BigInteger(x)) - /** Translates the String representation of a BigInt in the - * specified radix into a BigInt. + /** Translates the string representation of a BigInt in the + * specified <code>radix</code> into a BigInt. + * + * @param x ... + * @param radix ... + * @return ... */ def apply(x: String, radix: Int): BigInt = new BigInt(new BigInteger(x, radix)) @@ -67,7 +93,7 @@ object BigInt { def probablePrime(bitLength: Int, rnd: Random): BigInt = new BigInt(BigInteger.probablePrime(bitLength, rnd)) - /** Implicit conversion from int to BigInt + /** Implicit conversion from <code>int</code> to <code>BigInt</code>. */ implicit def int2bigInt(i: Int): BigInt = apply(i) @@ -75,7 +101,7 @@ object BigInt { */ implicit def long2bigInt(l: Long): BigInt = apply(l) - /** Implicit conversion from BigInt to Ordered + /** Implicit conversion from BigInt to <code>Ordered</code>. */ implicit def bigInt2ordered(x: BigInt): Ordered[BigInt] = new Ordered[BigInt] with Proxy { def self: Any = x; @@ -319,10 +345,11 @@ class BigInt(val bigInteger: BigInteger) extends runtime.BoxedNumber { */ def toString(radix: Int): String = this.bigInteger.toString(radix) - /** Returns a byte array containing the two's-complement representation of this BigInt. - * The byte array will be in big-endian byte-order: the most significant byte is in the - * zeroth element. The array will contain the minimum number of bytes required to represent - * this BigInt, including at least one sign bit. + /** Returns a byte array containing the two's-complement representation of + * this BigInt. The byte array will be in big-endian byte-order: the most + * significant byte is in the zeroth element. The array will contain the + * minimum number of bytes required to represent this BigInt, including at + * least one sign bit. */ def toByteArray: Array[Byte] = this.bigInteger.toByteArray() } diff --git a/src/library/scala/BufferedIterator.scala b/src/library/scala/BufferedIterator.scala index b4ce24d16a..67d5016193 100644 --- a/src/library/scala/BufferedIterator.scala +++ b/src/library/scala/BufferedIterator.scala @@ -11,8 +11,7 @@ package scala - -/** Buffered iterators are iterators which llow to inspect the next +/** Buffered iterators are iterators which allow to inspect the next * element without discarding it. * * @author Martin Odersky diff --git a/src/library/scala/CaseClass.scala b/src/library/scala/CaseClass.scala index 9ef03e8799..88d2fa8c48 100644 --- a/src/library/scala/CaseClass.scala +++ b/src/library/scala/CaseClass.scala @@ -19,10 +19,11 @@ package scala */ trait CaseClass extends AnyRef { - /** for a case class A(x_0,...,x_(k-1)), returns x_i for 0 <= i < k, - * <code>null</code> otherwise. + /** for a case class <code>A(x_0,...,x_(k-1))</code>, returns <code>x_i</code> + * for <code>0 <= i < k</code>, <code>null</code> otherwise. * * @param n ... + * @return ... */ def caseElement(n: Int): Any @@ -30,7 +31,7 @@ trait CaseClass extends AnyRef { def setCaseElement(n: Int, v: Any): unit */ - /** for a case class A(x_0,...,x_(k-1)), returns k + /** for a case class <code>A(x_0,...,x_(k-1))</code>, returns <code>k</code> */ def caseArity: Int diff --git a/src/library/scala/Ordered.scala b/src/library/scala/Ordered.scala index 35ac27cd76..4eeab101f0 100644 --- a/src/library/scala/Ordered.scala +++ b/src/library/scala/Ordered.scala @@ -9,23 +9,24 @@ // $Id$ -package scala; +package scala - -/** A class for totally ordered data. bq: Note that since version 2006-07-24, - * this class is no longer covariant in a. +/** A class for totally ordered data. + * + * Note that since version 2006-07-24 this class is no longer covariant in a. + * * @author Martin Odersky - * @version 2006-07-24 + * @version 1.1, 2006-07-24 */ trait Ordered[a] { - /** Result of comparing `this' with operand `that'. - * returns `x' where + /** Result of comparing <code>this</code> with operand <code>that</code>. + * returns <code>x</code> where * <code>x < 0</code> iff <code>this < that</code> * <code>x == 0</code> iff <code>this == that</code> * <code>x > 0</code> iff <code>this > that</code> */ - def compare(that: a): Int; + def compare(that: a): Int def < (that: a): Boolean = (this compare that) < 0 def > (that: a): Boolean = (this compare that) > 0 diff --git a/src/library/scala/PartiallyOrdered.scala b/src/library/scala/PartiallyOrdered.scala index 45aa1fc58b..b4c86fedd8 100644 --- a/src/library/scala/PartiallyOrdered.scala +++ b/src/library/scala/PartiallyOrdered.scala @@ -9,8 +9,7 @@ // $Id$ -package scala; - +package scala /** A class for partially ordered data. * @@ -19,14 +18,14 @@ package scala; */ trait PartiallyOrdered[+a] { - /** Result of comparing `this' with operand `that'. - * Returns `None' if operands are not comparable. - * If operands are comparable, returns `Some(x)' where + /** Result of comparing <code>this</code> with operand <code>that</code>. + * Returns <code>None</code> if operands are not comparable. + * If operands are comparable, returns <code>Some(x)</code> where * <code>x < 0</code> iff <code>this < that</code> * <code>x == 0</code> iff <code>this == that</code> * <code>x > 0</code> iff <code>this > that</code> */ - def tryCompareTo [b >: a <% PartiallyOrdered[b]](that: b): Option[int]; + def tryCompareTo [b >: a <% PartiallyOrdered[b]](that: b): Option[int] def < [b >: a <% PartiallyOrdered[b]](that: b): boolean = (this tryCompareTo that) match { diff --git a/src/library/scala/collection/BitSet.scala b/src/library/scala/collection/BitSet.scala index b4658049db..b999756bcb 100644 --- a/src/library/scala/collection/BitSet.scala +++ b/src/library/scala/collection/BitSet.scala @@ -73,7 +73,7 @@ abstract class BitSet extends AnyRef with Function1[Int,Boolean] with Set[Int] { var len = memsize(min(this.capacity, other.capacity)) var i = 0 var res = true - while((i < len) && res) { + while ((i < len) && res) { res = arr(i) == other.arr(i) i = i + 1 } @@ -96,8 +96,8 @@ abstract class BitSet extends AnyRef with Function1[Int,Boolean] with Set[Int] { var i = 0 var res = true while((i < len) && res) { - res = other.arr(i) == (other.arr(i) | arr(i)); - i = i + 1; + res = other.arr(i) == (other.arr(i) | arr(i)) + i = i + 1 } res && (this.capacity <= other.capacity || { // if this set is bigger check that the rest is empty diff --git a/src/library/scala/concurrent/Channel.scala b/src/library/scala/concurrent/Channel.scala index 1638a8f10c..f7a156271f 100644 --- a/src/library/scala/concurrent/Channel.scala +++ b/src/library/scala/concurrent/Channel.scala @@ -9,31 +9,38 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent +/** This class ... + * + * @author Martin Odersky + * @version 1.0, 10/03/2003 + */ class Channel[a] { class LinkedList[a] { - var elem: a = _; - var next: LinkedList[a] = null; + var elem: a = _ + var next: LinkedList[a] = null } - private var written = new LinkedList[a]; // FIFO buffer, realized through - private var lastWritten = written; // aliasing of a linked list - private var nreaders = 0; + private var written = new LinkedList[a] // FIFO buffer, realized through + private var lastWritten = written // aliasing of a linked list + private var nreaders = 0 + /** + * @param x ... + */ def write(x: a) = synchronized { - lastWritten.elem = x; - lastWritten.next = new LinkedList[a]; - lastWritten = lastWritten.next; - if (nreaders > 0) notify(); + lastWritten.elem = x + lastWritten.next = new LinkedList[a] + lastWritten = lastWritten.next + if (nreaders > 0) notify() } def read: a = synchronized { if (written.next == null) { - nreaders = nreaders + 1; wait(); nreaders = nreaders - 1; + nreaders = nreaders + 1; wait(); nreaders = nreaders - 1 } - val x = written.elem; - written = written.next; + val x = written.elem + written = written.next x } } diff --git a/src/library/scala/concurrent/Lock.scala b/src/library/scala/concurrent/Lock.scala index dd89517362..cd7371aa86 100644 --- a/src/library/scala/concurrent/Lock.scala +++ b/src/library/scala/concurrent/Lock.scala @@ -9,17 +9,23 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent +/** This class ... + * + * @author Martin Odersky + * @version 1.0, 10/03/2003 + */ class Lock { - var available = true; + var available = true + def acquire = synchronized { - if (!available) wait(); + if (!available) wait() available = false } + def release = synchronized { - available = true; + available = true notify() } } diff --git a/src/library/scala/concurrent/MailBox.scala b/src/library/scala/concurrent/MailBox.scala index 100c29faf2..7a8b4eac20 100644 --- a/src/library/scala/concurrent/MailBox.scala +++ b/src/library/scala/concurrent/MailBox.scala @@ -9,42 +9,46 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent +/** This class ... + * + * @author Martin Odersky + * @version 1.0, 12/03/2003 + */ //class MailBox with Monitor with LinkedListQueueCreator { class MailBox extends AnyRef with ListQueueCreator { - type Message = AnyRef; + type Message = AnyRef private abstract class PreReceiver { - var msg: Message = null; - def isDefinedAt(msg: Message): boolean; + var msg: Message = null + def isDefinedAt(msg: Message): boolean } private class Receiver[a](receiver: PartialFunction[Message, a]) extends PreReceiver { - def isDefinedAt(msg: Message) = receiver.isDefinedAt(msg); + def isDefinedAt(msg: Message) = receiver.isDefinedAt(msg) def receive(): a = synchronized { - while (msg == null) wait(); + while (msg == null) wait() receiver(msg) } def receiveWithin(msec: long): a = synchronized { - if (msg == null) wait(msec); + if (msg == null) wait(msec) receiver(if (msg != null) msg else TIMEOUT) } } - private val messageQueue = queueCreate[Message]; - private val receiverQueue = queueCreate[PreReceiver]; + private val messageQueue = queueCreate[Message] + private val receiverQueue = queueCreate[PreReceiver] /** Unconsumed messages. */ - private var sent = messageQueue.make; + private var sent = messageQueue.make /** Pending receivers. */ - private var receivers = receiverQueue.make; + private var receivers = receiverQueue.make /** * Check whether the receiver can be applied to an unconsumed message. @@ -55,8 +59,8 @@ class MailBox extends AnyRef with ListQueueCreator { messageQueue.extractFirst(sent, msg => receiver.isDefinedAt(msg)) match { case None => receivers = receiverQueue.append(receivers, receiver) case Some(Pair(msg, withoutMsg)) => { - sent = withoutMsg; - receiver.msg = msg + sent = withoutMsg + receiver.msg = msg } } } @@ -70,9 +74,9 @@ class MailBox extends AnyRef with ListQueueCreator { receiverQueue.extractFirst(receivers, r => r.isDefinedAt(msg)) match { case None => sent = messageQueue.append(sent, msg) case Some(Pair(receiver, withoutReceiver)) => { - receivers = withoutReceiver; - receiver.msg = msg; - receiver synchronized { receiver.notify() }; + receivers = withoutReceiver + receiver.msg = msg + receiver synchronized { receiver.notify() } } } } @@ -82,8 +86,8 @@ class MailBox extends AnyRef with ListQueueCreator { * <code>f</code> is defined. */ def receive[a](f: PartialFunction[Message, a]): a = { - val r = new Receiver(f); - scanSentMsgs(r); + val r = new Receiver(f) + scanSentMsgs(r) r.receive() } @@ -92,8 +96,8 @@ class MailBox extends AnyRef with ListQueueCreator { * <code>f</code> is defined or the timeout is over. */ def receiveWithin[a](msec: long)(f: PartialFunction[Message, a]): a = { - val r = new Receiver(f); - scanSentMsgs(r); + val r = new Receiver(f) + scanSentMsgs(r) r.receiveWithin(msec) } @@ -106,66 +110,66 @@ class MailBox extends AnyRef with ListQueueCreator { */ trait QueueModule[a] { /** Type of queues. */ - type t; + type t /** Create an empty queue. */ - def make: t; + def make: t /** Append an element to a queue. */ - def append(l: t, x: a): t; + def append(l: t, x: a): t /** Extract an element satisfying a predicate from a queue. */ - def extractFirst(l: t, p: a => boolean): Option[Pair[a, t]]; + def extractFirst(l: t, p: a => boolean): Option[Pair[a, t]] } /** Inefficient but simple queue module creator. */ trait ListQueueCreator { def queueCreate[a]: QueueModule[a] = new QueueModule[a] { - type t = List[a]; - def make: t = Nil; - def append(l: t, x: a): t = l ::: x :: Nil; + type t = List[a] + def make: t = Nil + def append(l: t, x: a): t = l ::: x :: Nil def extractFirst(l: t, p: a => boolean): Option[Pair[a, t]] = l match { - case Nil => None - case head :: tail => - if (p(head)) - Some(Pair(head, tail)) - else - extractFirst(tail, p) match { - case None => None - case Some(Pair(x, without_x)) => Some(Pair(x, head :: without_x)) - } + case Nil => None + case head :: tail => + if (p(head)) + Some(Pair(head, tail)) + else + extractFirst(tail, p) match { + case None => None + case Some(Pair(x, without_x)) => Some(Pair(x, head :: without_x)) + } } } } /** Efficient queue module creator based on linked lists. */ trait LinkedListQueueCreator { - import scala.collection.mutable.LinkedList; + import scala.collection.mutable.LinkedList def queueCreate[a >: Null <: AnyRef]: QueueModule[a] = new QueueModule[a] { - type t = Pair[LinkedList[a], LinkedList[a]]; // fst = the list, snd = last elem + type t = Pair[LinkedList[a], LinkedList[a]] // fst = the list, snd = last elem def make: t = { - val l = new LinkedList[a](null, null); + val l = new LinkedList[a](null, null) Pair(l, l) } def append(l: t, x: a): t = { - val atTail = new LinkedList(x, null); + val atTail = new LinkedList(x, null) l._2 append atTail; Pair(l._1, atTail) } def extractFirst(l: t, p: a => boolean): Option[Pair[a, t]] = { - var xs = l._1; - var xs1 = xs.next; + var xs = l._1 + var xs1 = xs.next while (xs1 != null && !p(xs1.elem)) { - xs = xs1; - xs1 = xs1.next; + xs = xs1 + xs1 = xs1.next } if (xs1 != null) { - xs.next = xs1.next; - if (xs.next == null) - Some(Pair(xs1.elem, Pair(l._1, xs))) - else - Some(Pair(xs1.elem, l)) + xs.next = xs1.next + if (xs.next == null) + Some(Pair(xs1.elem, Pair(l._1, xs))) + else + Some(Pair(xs1.elem, l)) } else - None + None } } } diff --git a/src/library/scala/concurrent/NameServer.scala b/src/library/scala/concurrent/NameServer.scala index 57c75ce543..6cdaca045c 100644 --- a/src/library/scala/concurrent/NameServer.scala +++ b/src/library/scala/concurrent/NameServer.scala @@ -9,29 +9,37 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent +/** + * @author Erik Stenman + * @version 1.0, 01/10/2003 + */ object NameServer { - val names = new scala.collection.mutable.HashMap[Symbol, Process]; + val names = new scala.collection.mutable.HashMap[Symbol, Process] + /** + * @param name ... + * @param proc ... + */ def register(name: Symbol, proc: Process) = { - if (names.contains(name)) error("Name:" + name + " already registred"); - names += name -> proc; + if (names contains name) error("Name:" + name + " already registred") + names += name -> proc } - def unregister(name: Symbol) = { - if (names.contains(name)) - names -= name; - else - error("Name:" + name + " not registred"); - } + def unregister(name: Symbol) = + if (names contains name) names -= name + else error("Name:" + name + " not registred") + /** + * @param name ... + * @return ... + */ def whereis(name: Symbol): Option[Process] = - names.get(name); + names.get(name) def send(name: Symbol, msg: MailBox#Message) = - names(name).send(msg); + names(name).send(msg) } diff --git a/src/library/scala/concurrent/Process.scala b/src/library/scala/concurrent/Process.scala index 537b6c120c..fce91b50b8 100644 --- a/src/library/scala/concurrent/Process.scala +++ b/src/library/scala/concurrent/Process.scala @@ -9,43 +9,47 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent +/** This object ... + * + * @author Erik Stenman + * @version 1.0, 01/10/2003 + */ object Process { def spawn(body: => Unit): Process = { - val p = new Process(body); - p.start(); + val p = new Process(body) + p.start() p } def spawn_link(body: => Unit): Process = - self.spawn_link(body); + self.spawn_link(body) def send(p: Process, msg: MailBox#Message) = - p.send(msg); + p.send(msg) def receive[a](f: PartialFunction[MailBox#Message, a]): a = - self.receive(f); + self.receive(f) def receiveWithin[a](msec: long)(f: PartialFunction[MailBox#Message, a]): a = - self.receiveWithin(msec)(f); + self.receiveWithin(msec)(f) def self: Process = if (Thread.currentThread().isInstanceOf[Process]) Thread.currentThread().asInstanceOf[Process] else - error("Self called outside a process"); + error("Self called outside a process") def exit(p: Process, reason: AnyRef) = - p.exit(reason); + p.exit(reason) } class Process(body: => Unit) extends Actor() { - private var exitReason: AnyRef = null; - private var links: List[Process] = Nil; + private var exitReason: AnyRef = null + private var links: List[Process] = Nil override def run() = try { @@ -56,28 +60,28 @@ class Process(body: => Unit) extends Actor() { signal(exitReason) case (exitSignal) => signal(exitSignal) - }; + } private def signal(s: MailBox#Message) = links.foreach { p: Process => p.send(Triple('EXIT, this, s)) } def !(msg: MailBox#Message) = - send(msg); + send(msg) def link(p: Process) = - links = p::links; + links = p::links def spawn_link(body: => Unit) = { - val p = new Process(body); - p.link(this); - p.start(); + val p = new Process(body) + p.link(this) + p.start() p } - //def self = this; + //def self = this def exit(reason: AnyRef): Unit = { - exitReason = reason; + exitReason = reason interrupt() } diff --git a/src/library/scala/concurrent/TIMEOUT.scala b/src/library/scala/concurrent/TIMEOUT.scala index 4a3b0a8dc6..055a81d70e 100644 --- a/src/library/scala/concurrent/TIMEOUT.scala +++ b/src/library/scala/concurrent/TIMEOUT.scala @@ -9,11 +9,13 @@ // $Id$ -package scala.concurrent; - +package scala.concurrent /** * The message sent to a message box when the period specified in - * <code>receiveWithin</code? expires. + * <code>receiveWithin</code> expires. + * + * @author Martin Odersky + * @version 1.0, 10/03/2003 */ -case object TIMEOUT; +case object TIMEOUT |