Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
- Added Scalariform to the project: triggers on compile & test to ref…
Browse files Browse the repository at this point in the history
…ormat cleanly

- As a result, a bit of reformatting of code
  • Loading branch information
Brendan W. McAdams committed Jan 25, 2011
1 parent b902a1d commit 3e9239c
Show file tree
Hide file tree
Showing 23 changed files with 564 additions and 648 deletions.
11 changes: 5 additions & 6 deletions casbah-commons/src/main/scala/Implicits.scala
Expand Up @@ -26,15 +26,15 @@ package commons
import scalaj.collection.Imports._

trait Implicits {
import com.mongodb.{DBObject, BasicDBObject, BasicDBList}
import com.mongodb.{ DBObject, BasicDBObject, BasicDBList }

/*
* Placeholder Type Alias
*
* TODO - Make me a Type Class to define boundaries
*/
type JSFunction = String

/**
* Implicit extension methods for Scala <code>Map[String, Any]</code>
* to convert to Mongo DBObject instances.
Expand All @@ -51,14 +51,13 @@ trait Implicits {

implicit def map2MongoDBObject(map: scala.collection.Map[String, Any]): DBObject = new BasicDBObject(map.asJava)


implicit def wrapDBObj(in: DBObject): MongoDBObject =
implicit def wrapDBObj(in: DBObject): MongoDBObject =
new MongoDBObject { val underlying = in }

implicit def unwrapDBObj(in: MongoDBObject): DBObject =
implicit def unwrapDBObj(in: MongoDBObject): DBObject =
in.underlying

implicit def wrapDBList(in: BasicDBList): MongoDBList =
implicit def wrapDBList(in: BasicDBList): MongoDBList =
new MongoDBList { val underlying = in }

implicit def unwrapDBList(in: MongoDBList): BasicDBList =
Expand Down
72 changes: 37 additions & 35 deletions casbah-commons/src/main/scala/Logger.scala
Expand Up @@ -20,10 +20,10 @@
*
*/

package com.mongodb.casbah
package commons
package com.mongodb.casbah
package commons

import org.slf4j.{Logger => SLFLogger,LoggerFactory => SLFLoggerFactory}
import org.slf4j.{ Logger => SLFLogger, LoggerFactory => SLFLoggerFactory }

import java.io.StringWriter;
import java.io.PrintWriter;
Expand All @@ -36,7 +36,9 @@ import java.net.UnknownHostException;
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Logging {
@transient @volatile protected[casbah] var log = Logger(this.getClass.getName)
@transient
@volatile
protected[casbah] var log = Logger(this.getClass.getName)
}

/**
Expand All @@ -54,110 +56,110 @@ trait Logging {
* http://download-llnw.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)
*/
class Logger(val logger: SLFLogger) {
def name = logger.getName
def name = logger.getName

def trace_? = logger.isTraceEnabled
def debug_? = logger.isDebugEnabled
def info_? = logger.isInfoEnabled
def trace_? = logger.isTraceEnabled
def debug_? = logger.isDebugEnabled
def info_? = logger.isInfoEnabled
def warning_? = logger.isWarnEnabled
def error_? = logger.isErrorEnabled
def error_? = logger.isErrorEnabled

//Trace
def trace(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
trace(t,message(fmt,arg,argN:_*))
trace(t, message(fmt, arg, argN: _*))
}

def trace(t: Throwable, msg: => String) {
if (trace_?) logger.trace(msg,t)
if (trace_?) logger.trace(msg, t)
}

def trace(fmt: => String, arg: Any, argN: Any*) {
trace(message(fmt,arg,argN:_*))
trace(message(fmt, arg, argN: _*))
}

def trace(msg: => String) {
if (trace_?) logger trace msg
if (trace_?) logger trace msg
}

//Debug
def debug(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
debug(t,message(fmt,arg,argN:_*))
debug(t, message(fmt, arg, argN: _*))
}

def debug(t: Throwable, msg: => String) {
if (debug_?) logger.debug(msg,t)
if (debug_?) logger.debug(msg, t)
}

def debug(fmt: => String, arg: Any, argN: Any*) {
debug(message(fmt,arg,argN:_*))
debug(message(fmt, arg, argN: _*))
}

def debug(msg: => String) {
if (debug_?) logger debug msg
if (debug_?) logger debug msg
}

//Info
def info(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
info(t,message(fmt,arg,argN:_*))
info(t, message(fmt, arg, argN: _*))
}

def info(t: Throwable, msg: => String) {
if (info_?) logger.info(msg,t)
if (info_?) logger.info(msg, t)
}

def info(fmt: => String, arg: Any, argN: Any*) {
info(message(fmt,arg,argN:_*))
info(message(fmt, arg, argN: _*))
}

def info(msg: => String) {
if (info_?) logger info msg
if (info_?) logger info msg
}

//Warning
def warning(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
warning(t,message(fmt,arg,argN:_*))
warning(t, message(fmt, arg, argN: _*))
}

def warn(t: Throwable, fmt: => String, arg: Any, argN: Any*) = warning(t, fmt, arg, argN)

def warning(t: Throwable, msg: => String) {
if (warning_?) logger.warn(msg,t)
if (warning_?) logger.warn(msg, t)
}

def warn(t: Throwable, msg: => String) = warning(t, msg)

def warning(fmt: => String, arg: Any, argN: Any*) {
warning(message(fmt,arg,argN:_*))
warning(message(fmt, arg, argN: _*))
}

def warn(fmt: => String, arg: Any, argN: Any*) = warning(fmt, arg, argN:_*)
def warn(fmt: => String, arg: Any, argN: Any*) = warning(fmt, arg, argN: _*)

def warning(msg: => String) {
if (warning_?) logger warn msg
if (warning_?) logger warn msg
}

def warn(msg: => String) = warning(msg)

//Error
def error(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
error(t,message(fmt,arg,argN:_*))
error(t, message(fmt, arg, argN: _*))
}

def error(t: Throwable, msg: => String) {
if (error_?) logger.error(msg,t)
if (error_?) logger.error(msg, t)
}

def error(fmt: => String, arg: Any, argN: Any*) {
error(message(fmt,arg,argN:_*))
error(message(fmt, arg, argN: _*))
}

def error(msg: => String) {
if (error_?) logger error msg
if (error_?) logger error msg
}

protected def message(fmt: String, arg: Any, argN: Any*) : String = {
protected def message(fmt: String, arg: Any, argN: Any*): String = {
if ((argN eq null) || argN.isEmpty) fmt.format(arg)
else fmt.format((arg +: argN):_*)
else fmt.format((arg +: argN): _*)
}
}

Expand All @@ -183,7 +185,7 @@ object Logger {
StatusPrinter.print(LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext])
}*/

def apply(logger: String) : Logger = new Logger(SLFLoggerFactory getLogger logger)
def apply(clazz: Class[_]) : Logger = apply(clazz.getName)
def root : Logger = apply(SLFLogger.ROOT_LOGGER_NAME)
def apply(logger: String): Logger = new Logger(SLFLoggerFactory getLogger logger)
def apply(clazz: Class[_]): Logger = apply(clazz.getName)
def root: Logger = apply(SLFLogger.ROOT_LOGGER_NAME)
}
31 changes: 14 additions & 17 deletions casbah-commons/src/main/scala/MongoDBList.scala
Expand Up @@ -32,19 +32,17 @@ import scala.reflect._

import scalaj.collection.Imports._


import com.mongodb.BasicDBList


trait MongoDBList extends Buffer[AnyRef] {
val underlying: BasicDBList

def apply(i: Int) = underlying.get(i)
def update(i: Int, elem: AnyRef) =

def update(i: Int, elem: AnyRef) =
underlying.set(i, elem)

def +=:(elem: AnyRef): this.type = {
def +=:(elem: AnyRef): this.type = {
underlying.subList(0, 0).add(elem)
this
}
Expand All @@ -56,7 +54,7 @@ trait MongoDBList extends Buffer[AnyRef] {

def insertAll(i: Int, elems: Traversable[AnyRef]) = {
val ins = underlying.subList(0, i)
elems.foreach(x => ins.add(x))
elems.foreach(x => ins.add(x))
}

def remove(i: Int) = underlying.remove(i)
Expand All @@ -72,15 +70,15 @@ trait MongoDBList extends Buffer[AnyRef] {
}

object MongoDBList {
def empty: BasicDBList =

def empty: BasicDBList =
new MongoDBList { val underlying = new BasicDBList }

def apply[A <: Any](elems: A*): BasicDBList = {
val b = newBuilder[A]
for (xs <- elems) xs match {
case p: Tuple2[String, _] => b += MongoDBObject(p)
case _ => b += xs
case p: Tuple2[String, _] => b += MongoDBObject(p)
case _ => b += xs
}
b.result
}
Expand All @@ -94,25 +92,24 @@ object MongoDBList {
b.result
}


def newBuilder[A <: Any]: MongoDBListBuilder =
def newBuilder[A <: Any]: MongoDBListBuilder =
new MongoDBListBuilder

}

sealed class MongoDBListBuilder
extends scala.collection.mutable.Builder[Any, BasicDBList] {
sealed class MongoDBListBuilder
extends scala.collection.mutable.Builder[Any, BasicDBList] {

protected val empty = new BasicDBList

protected var elems = empty

override def +=(x: Any) = {
override def +=(x: Any) = {
val v = x match {
case _ => x.asInstanceOf[AnyRef]
}
elems.add(v)
this
this
}

def clear() { elems = empty }
Expand Down

0 comments on commit 3e9239c

Please sign in to comment.