Permalink
Browse files

Merge branch 'scala-2.8.0'

* scala-2.8.0:
  Convert set to array before performing map.
  Introduce ChannelType.withNameOpt and use it instead of deprecated Enumeration.valueOf.
  Use explicit cast to avoid unchecked warning.
  Use StringBuilder.appendAll instead of append (the latter is deprecated).
  Use iterator instead of elements (latter is deprecated).
  Use math instead of Math (the latter is deprecated).
  Include the class directory in the classpath for Scala compilation in genappserver.
  Avoid cast by wrapping in Scala collection before calling toArray.
  Use mapValues instead of Map.Projection.
  Add ClassManifest context bound to both parameters of BucketKeeper.
  Replace !WeakReference.isValid with WeakReference.get.isEmpty.
  Fix imports for Message and Reset (they were moved to collection.script in 2.8).
  Pass collection.Map instead of Map to BodyLock.map.getOrElse to fix compiler error.
  Replace concat with ++ .
  Replace jcl.Conversions, RichIterator and RichEnumeration with JavaConversions.
  Fix overloading ambiguity when calling ++ on immutable.Set by using mutable.Set and ++=.
  Use new annotations syntax.
  Use take instead of one-arg slice.
  Use capitalized form for AnyVal subclasses.
  Handle removal of Iterator.collect with no arguments.
  • Loading branch information...
2 parents 17dd009 + ff74f3d commit b29d6b405fb0488b5a30f5d6fe1b8a72f01ba538 @ijuma committed Oct 11, 2010
@@ -19,7 +19,7 @@ def superpack(input: String): String = {
def containsSpecialChar(str: String) = str.exists(specialCharsSet.contains(_));
val toks:Array[String] = (
- "@|[a-zA-Z0-9]+|[^@a-zA-Z0-9]{1,3}").r.findAllIn(input).collect.toArray;
+ "@|[a-zA-Z0-9]+|[^@a-zA-Z0-9]{1,3}").r.findAllIn(input).toArray;
val stringCounts = {
val m = new scala.collection.mutable.HashMap[String,Int];
@@ -41,9 +41,9 @@ def superpack(input: String): String = {
val thingsToReplace:Seq[String] = estimatedSavings.map(_._1);
assert(encodeNames.length >= thingsToReplace.length);
- val replacements = Map(thingsToReplace.elements.zipWithIndex.map({
+ val replacements = Map(thingsToReplace.iterator.zipWithIndex.map({
case (str, i) => (str, encodeNames(i));
- }).collect:_*);
+ }).toSeq:_*);
def encode(tk: String) = if (replacements.contains(tk)) replacements(tk) else tk;
val afterReplace = toks.map(encode(_)).mkString.replaceAll(
@@ -117,7 +117,7 @@ def doMake {
val buf = new Array[Char](1024);
var numRead = 0;
while({ numRead = reader.read(buf); numRead } != -1) {
- builder.append(buf, 0, numRead);
+ builder.appendAll(buf, 0, numRead);
}
reader.close;
return builder.toString;
@@ -304,7 +304,7 @@ def remakeLoop {
filter(! _.getName.endsWith("~")).
filter(! _.getName.endsWith("#")).
filter(! _.getName.startsWith(".")).map(_.lastModified).
- reduceLeft(Math.max(_:Long,_:Long)));
+ reduceLeft(math.max(_:Long,_:Long)));
}
var madeStamp:Long = 0;
@@ -126,7 +126,7 @@ function genappserver {
-target 1.5 \
$APPSERVERJAVAFILES
$CC \
- -classpath $CP \
+ -classpath $CP:$1 \
-d $1 \
-target:jvm-1.5 \
$ARGS \
@@ -135,7 +135,7 @@ object OpenOfficeService {
"txt" -> "Text"
);
- def createTempFile(bytes: Array[byte], suffix: String) = {
+ def createTempFile(bytes: Array[Byte], suffix: String) = {
var f = File.createTempFile("ooconvert-", if (suffix == null) { null } else if (suffix == "") { "" } else { "."+suffix });
if (bytes != null) {
val fos = new FileOutputStream(f);
@@ -157,7 +157,7 @@ object OpenOfficeService {
openOfficeServerPort = port;
}
- def convertFile(from: String, to: String, bytes: Array[byte]): Array[byte] = {
+ def convertFile(from: String, to: String, bytes: Array[Byte]): Array[Byte] = {
if (from == to) {
return bytes;
}
@@ -213,21 +213,21 @@ object OpenOfficeService {
}
// Query format:
- // from: String, to: String, count: Int, bytes: Array[byte]
+ // from: String, to: String, count: Int, bytes: Array[Byte]
// Response format:
// status: Int, <data>
- // status 0 (success) - <data>: count: Int, bytes: Array[byte]
+ // status 0 (success) - <data>: count: Int, bytes: Array[Byte]
// status 1 (temporary failure) - <data>: <none>
// status 2 (permanent failure) - <data>: type: Int
// type - 0: unknown failure.
// - 1: unsupported format
val handler = new SarsMessageHandler {
- override def handle(b: Array[byte]): Option[Array[byte]] = {
+ override def handle(b: Array[Byte]): Option[Array[Byte]] = {
val is = new DataInputStream(new ByteArrayInputStream(b));
val from = is.readUTF;
val to = is.readUTF;
val len = is.readInt;
- val bytes = new Array[byte](len);
+ val bytes = new Array[Byte](len);
is.readFully(bytes);
var status = 0;
var permfailuretype = 0;
@@ -157,7 +157,7 @@ object Licensing {
case "testascii" => {
val one = 17;
val two = -1L;
- val three = (Math.random*Math.pow(10, (Math.random*10).toInt)).toInt;
+ val three = (math.random*math.pow(10, (math.random*10).toInt)).toInt;
println(List(one, two, three).mkString(", "));
println(List(toInt(toBytes(one)), toLong(toBytes(two)), toInt(toBytes(three))).mkString(", "));
val bytes = Encryptomatic.asciiToBytes(Encryptomatic.bytesToAscii(Array.concat[Byte](Array(1.toByte), toBytes(one), toBytes(two), toBytes(three))));
@@ -96,7 +96,7 @@ object md5 {
val bytes = input.getBytes("UTF-8");
md5(bytes);
}
- def md5(bytes: Array[byte]): String = {
+ def md5(bytes: Array[Byte]): String = {
var md = MessageDigest.getInstance("MD5");
var digest = md.digest(bytes);
var builder = new StringBuilder();
@@ -17,6 +17,7 @@
package net.appjet.ajstdlib;
import scala.collection.mutable.{Queue, HashMap, SynchronizedMap, ArrayBuffer};
+import scala.collection.JavaConversions.asIterator;
import javax.servlet.http.{HttpServletRequest, HttpServletResponse, HttpServlet};
import org.mortbay.jetty.servlet.{ServletHolder, Context};
import org.mortbay.jetty.{HttpConnection, Handler, RetryRequest};
@@ -30,7 +31,6 @@ import java.lang.ref.WeakReference;
import org.mozilla.javascript.{Context => JSContext, Scriptable};
import net.appjet.oui._;
-import net.appjet.oui.Util.enumerationToRichEnumeration;
import net.appjet.common.util.HttpServletRequestFactory;
trait SocketConnectionHandler {
@@ -233,7 +233,7 @@ class StreamingSocket(val id: String, handler: SocketConnectionHandler) {
lazy val attributes = new HashMap[String, String] with SynchronizedMap[String, String];
def channel(typ: String, create: Boolean, subType: String): Option[Channel] = {
- val channelType = ChannelType.valueOf(typ);
+ val channelType = ChannelType.withNameOpt(typ);
if (channelType.isEmpty) {
streaminglog(Map(
"type" -> "error",
@@ -254,7 +254,7 @@ class StreamingSocket(val id: String, handler: SocketConnectionHandler) {
var lastConfirmedSeqNumber = 0;
// external API
- def sendMessage(isControl: boolean, body: String) {
+ def sendMessage(isControl: Boolean, body: String) {
if (hasConnected && ! shutdown) {
synchronized {
lastSentSeqNumber += 1;
@@ -311,7 +311,7 @@ class StreamingSocket(val id: String, handler: SocketConnectionHandler) {
}
}
}
- def getUnconfirmedMessages(channel: Channel): Collection[SocketMessage] = {
+ def getUnconfirmedMessages(channel: Channel): Iterable[SocketMessage] = {
synchronized {
if (currentChannel.isDefined && currentChannel.get == channel) {
for (i <- lastConfirmedSeqNumber+1 until lastSentSeqNumber+1)
@@ -337,7 +337,7 @@ class StreamingSocket(val id: String, handler: SocketConnectionHandler) {
def useChannel(seqNo: Int, channelType0: String, req: HttpServletRequest) = synchronized {
if (seqNo <= lastChannelUpdate) false else {
lastChannelUpdate = seqNo;
- val channelType = ChannelType.valueOf(channelType0);
+ val channelType = ChannelType.withNameOpt(channelType0);
if (channelType.isDefined) {
val channel = activeChannels.get(channelType.get);
if (channel.isDefined) {
@@ -424,6 +424,10 @@ class StreamingSocket(val id: String, handler: SocketConnectionHandler) {
object ChannelType extends Enumeration("shortpolling", "longpolling", "streaming") {
val ShortPolling, LongPolling, Streaming = Value;
+
+ /* Enumeration.valueOf is deprecated in Scala 2.8, but the replacement (withName) is not suitable for the
+ * case where we don't know if an Enumeration exists with the provided name */
+ def withNameOpt(s: String): Option[ChannelType.Value] = values.find(_.toString == s)
}
object Channels {
@@ -525,7 +529,7 @@ trait IFrameChannel extends StreamingChannel {
def header(req: HttpServletRequest) = {
val document_domain =
- "\""+req.getHeader("Host").split("\\.").slice(2).mkString(".").split(":")(0)+"\"";
+ "\""+req.getHeader("Host").split("\\.").take(2).mkString(".").split(":")(0)+"\"";
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>f</title></head><body id="thebody" onload="(!parent.closed)&&d()"><script type="text/javascript">document.domain = """+document_domain+""";
@@ -789,7 +793,7 @@ class StreamingSocketServlet extends HttpServlet {
"type" -> "event",
"event" -> "restart-failure",
"connection" -> socketId));
- val failureChannel = ChannelType.valueOf(channelType).map(Channels.createNew(_, null, subType));
+ val failureChannel = ChannelType.withNameOpt(channelType).map(Channels.createNew(_, null, subType));
if (failureChannel.isDefined) {
failureChannel.get.sendRestartFailure(ec);
} else {
@@ -861,7 +865,7 @@ class StreamingSocketServlet extends HttpServlet {
val msgParts = msg.split(":");
socket.get.useChannel(java.lang.Integer.parseInt(msgParts(1)), msgParts(2), req);
} else if (msg.startsWith("kill")) {
- socket.get.kill("client request: "+msg.substring(Math.min(msg.length, "kill:".length)));
+ socket.get.kill("client request: "+msg.substring(math.min(msg.length, "kill:".length)));
} else {
streaminglog(Map(
"type" -> "error",
@@ -21,7 +21,7 @@ import java.util.concurrent.locks.ReentrantLock;
object timer {
- var _timings = new HashMap[String,ListBuffer[double]];
+ var _timings = new HashMap[String,ListBuffer[Double]];
var _lock = new ReentrantLock;
var _callstack = new ThreadLocal[ListBuffer[String]];
@@ -33,18 +33,18 @@ object timer {
}
_localcallstack += opname;
var _oplabel = _localcallstack.mkString(".");
- val startTime: long = System.nanoTime();
+ val startTime: Long = System.nanoTime();
new {
def done() {
- val elapsedTimeMs: double = (System.nanoTime() - startTime) / 1.0e6;
+ val elapsedTimeMs: Double = (System.nanoTime() - startTime) / 1.0e6;
_lock.lock();
try {
- var times = _timings.getOrElse(_oplabel, new ListBuffer[double]);
+ var times = _timings.getOrElse(_oplabel, new ListBuffer[Double]);
/*
if (times.size > 100000) {
- times = new ListBuffer[double];
+ times = new ListBuffer[Double];
}*/
times += elapsedTimeMs;
_timings.put(_oplabel, times);
@@ -65,11 +65,11 @@ object timer {
}
}
- def getStats(opname: String): Array[double] = {
+ def getStats(opname: String): Array[Double] = {
_lock.lock();
try {
- var times:ListBuffer[double] = _timings(opname);
+ var times:ListBuffer[Double] = _timings(opname);
var total = times.foldRight(0.0)(_ + _);
return Array(times.size, total, (total / times.size));
} finally {
@@ -79,7 +79,7 @@ object timer {
def reset() {
_lock.lock();
- _timings = new HashMap[String,ListBuffer[double]];
+ _timings = new HashMap[String,ListBuffer[Double]];
_lock.unlock();
}
}
@@ -43,10 +43,10 @@ class JSRuntimeException(val message: String, val cause: Throwable) extends Exec
ab += new JSStackFrame {
val errorLine = elt.getLineNumber;
val name = elt.getFileName;
- val code = BodyLock.map.getOrElse(Map[String, String]()).getOrElse(elt.getFileName, "").split("\n"); // 0-indexed.
+ val code = BodyLock.map.getOrElse(collection.Map[String, String]()).getOrElse(elt.getFileName, "").split("\n"); // 0-indexed.
def errorContext(rad: Int) = {
- val start_i = Math.max(errorLine-rad, 1)-1;
- val end_i = Math.min(errorLine+rad, code.length)-1;
+ val start_i = math.max(errorLine-rad, 1)-1;
+ val end_i = math.min(errorLine+rad, code.length)-1;
(start_i+1, end_i+1, code.slice(start_i, end_i+1));
}
}
@@ -61,13 +61,13 @@ class JSCompileException(message: String, cause: org.mozilla.javascript.Evaluato
List(new JSStackFrame {
val errorLine = cause.lineNumber();
val name = cause.sourceName();
- val code = BodyLock.map.getOrElse(Map[String, String]()).getOrElse(cause.sourceName(), "").split("\n"); // 0-indexed.
+ val code = BodyLock.map.getOrElse(collection.Map[String, String]()).getOrElse(cause.sourceName(), "").split("\n"); // 0-indexed.
def errorContext(rad: Int) = {
- val start_i = Math.max(errorLine-rad, 1)-1;
- val end_i = Math.min(errorLine+rad, code.length)-1;
+ val start_i = math.max(errorLine-rad, 1)-1;
+ val end_i = math.min(errorLine+rad, code.length)-1;
(start_i+1, end_i+1, code.slice(start_i, end_i+1));
}
- }).concat(List(super.frames: _*));
+ }) ++ super.frames;
}
private[bodylock] class InnerExecutable(val code: String, val script: Script) extends Executable {
@@ -147,7 +147,7 @@ object BodyLock {
compilationutils.compileToScript(source, sourceName, lineNumber, className);
}
- def executableFromBytes(bytes: Array[byte], className: String) =
+ def executableFromBytes(bytes: Array[Byte], className: String) =
new InnerExecutable("(source not available)", compilationutils.bytesToScript(bytes, className));
def unwrapExceptionIfNecessary(e: Throwable): Throwable = {
@@ -45,7 +45,7 @@ class CliParser(predef: Array[CliOption]) {
def usage = {
val sb = new StringBuilder();
- var maxLength = predef.map(opt => 2 + opt.name.length + opt.argName.map(_.length + 1).getOrElse(0) ).reduceRight(Math.max)+2;
+ var maxLength = predef.map(opt => 2 + opt.name.length + opt.argName.map(_.length + 1).getOrElse(0) ).reduceRight(math.max)+2;
for ((n, opt) <- options) {
sb.append(" --"+n+opt.argName.map("=<"+_+">").getOrElse("")+"\n");
sb.append(" "+WordUtils.wrap(opt.description, displayWidth-5).split("\n").mkString("\n "));
@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
trait SarsMessageHandler {
def handle(s: String): Option[String] = None;
- def handle(b: Array[byte]): Option[Array[byte]] = None;
+ def handle(b: Array[Byte]): Option[Array[Byte]] = None;
}
class SarsException(m: String) extends RuntimeException(m);
@@ -44,7 +44,7 @@ private[sars] trait SarsMessageReaderWriter {
if (messageType == byteArray) {
try {
val len = inputStream.readInt;
- val bytes = new Array[byte](len);
+ val bytes = new Array[Byte](len);
inputStream.readFully(bytes);
Some(bytes);
} catch {
@@ -64,11 +64,11 @@ private[sars] trait SarsMessageReaderWriter {
val m = readMessage;
m.filter(_.isInstanceOf[String]).asInstanceOf[Option[String]];
}
- def readBytes: Option[Array[byte]] = {
+ def readBytes: Option[Array[Byte]] = {
val m = readMessage;
- m.filter(_.isInstanceOf[Array[byte]]).asInstanceOf[Option[Array[byte]]];
+ m.filter(_.isInstanceOf[Array[Byte]]).asInstanceOf[Option[Array[Byte]]];
}
- def writeMessage(bytes: Array[byte]) {
+ def writeMessage(bytes: Array[Byte]) {
outputStream.writeInt(byteArray);
outputStream.writeInt(bytes.length);
outputStream.write(bytes);
@@ -126,8 +126,8 @@ class SarsClient(authKey: String, host: String, port: Int) {
def message(s: String): String =
message[String](s, readerWriter.writeMessage, Unit => readerWriter.readString);
- def message(b: Array[byte]): Array[byte] =
- message[Array[byte]](b, readerWriter.writeMessage, Unit => readerWriter.readBytes);
+ def message(b: Array[Byte]): Array[Byte] =
+ message[Array[Byte]](b, readerWriter.writeMessage, Unit => readerWriter.readBytes);
def close() {
if (! s.isClosed) {
@@ -166,7 +166,7 @@ class SarsClient(authKey: String, host: String, port: Int) {
client.message(q);
}
- def message(b: Array[byte]) = {
+ def message(b: Array[Byte]) = {
if (! socket.isConnected || socket.isClosed) {
connect();
}
@@ -195,7 +195,7 @@ class SarsServer(authKey: String, handler: SarsMessageHandler, host: Option[Stri
val inputStream = new DataInputStream(cs.getInputStream());
val outputStream = new DataOutputStream(cs.getOutputStream());
}
- val challenge = Math.random*1e20;
+ val challenge = math.random*1e20;
readerWriter.writeMessage(String.valueOf(challenge));
val res = readerWriter.readString;
@@ -210,8 +210,8 @@ class SarsServer(authKey: String, handler: SarsMessageHandler, host: Option[Stri
} else {
q.get match {
case s: String => readerWriter.writeMessage(handler.handle(s).getOrElse(""));
- case b: Array[byte] =>
- readerWriter.writeMessage(handler.handle(b).getOrElse(new Array[byte](0)));
+ case b: Array[Byte] =>
+ readerWriter.writeMessage(handler.handle(b).getOrElse(new Array[Byte](0)));
case x: AnyRef => throw new UnknownTypeException(x.getClass.getName);
}
}
@@ -320,7 +320,7 @@ object test {
None;
}
}
- override def handle(b: Array[byte]) = {
+ override def handle(b: Array[Byte]) = {
var actually = new String(b, "UTF-8");
println("SERVER: "+actually);
if (actually == "hello!") {
Oops, something went wrong.

0 comments on commit b29d6b4

Please sign in to comment.