Skip to content

Commit

Permalink
Merge pull request apache#68 from jtescher/scalastyle-data
Browse files Browse the repository at this point in the history
Fix data to be consistent with scalastyle
  • Loading branch information
dszeto committed Mar 8, 2015
2 parents 64531a8 + ccc7d03 commit a32e753
Show file tree
Hide file tree
Showing 33 changed files with 267 additions and 197 deletions.
2 changes: 1 addition & 1 deletion data/src/main/scala/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ private[prediction] object Utils {
}

def dateTimeToString(dt: DateTime): String = dateTimeFormatter.print(dt)
//dt.toString
// dt.toString

}
29 changes: 16 additions & 13 deletions data/src/main/scala/api/EventAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import akka.event.Logging
import akka.pattern.ask
import akka.util.Timeout

import org.json4s.DefaultFormats
import org.json4s.{Formats, DefaultFormats}
import org.json4s.ext.JodaTimeSerializers
import org.json4s.native.JsonMethods.parse

Expand All @@ -49,7 +49,7 @@ import spray.routing._
import spray.routing.authentication.Authentication
import spray.routing.Directives._

import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
import scala.collection.mutable.{ HashMap => MHashMap }
import scala.collection.mutable

Expand Down Expand Up @@ -117,7 +117,7 @@ class EventServiceActor(
val stats: Boolean) extends HttpServiceActor {

object Json4sProtocol extends Json4sSupport {
implicit def json4sFormats = DefaultFormats +
implicit def json4sFormats: Formats = DefaultFormats +
new EventJson4sSupport.APISerializer ++
JodaTimeSerializers.all
}
Expand All @@ -128,7 +128,7 @@ class EventServiceActor(

// we use the enclosing ActorContext's or ActorSystem's dispatcher for our
// Futures
implicit def executionContext = actorRefFactory.dispatcher
implicit def executionContext: ExecutionContext = actorRefFactory.dispatcher
implicit val timeout = Timeout(5, TimeUnit.SECONDS)

// for better message response
Expand Down Expand Up @@ -241,8 +241,9 @@ class EventServiceActor(
case Right(id) =>
(StatusCodes.Created, Map("eventId" -> s"${id}"))
}
if (stats)
if (stats) {
statsActorRef ! Bookkeeping(appId, result._1, event)
}
result
}
data
Expand Down Expand Up @@ -300,11 +301,12 @@ class EventServiceActor(
(StatusCodes.InternalServerError,
Map("message" -> message))
case Right(eventIter) =>
if (eventIter.hasNext)
if (eventIter.hasNext) {
(StatusCodes.OK, eventIter.toArray)
else
} else {
(StatusCodes.NotFound,
Map("message" -> "Not Found"))
}
}
}
data
Expand All @@ -324,24 +326,25 @@ class EventServiceActor(
handleRejections(rejectionHandler) {
authenticate(withAccessKey) { appId =>
respondWithMediaType(MediaTypes.`application/json`) {
if (stats)
if (stats) {
complete {
statsActorRef ? GetStats(appId) map {
_.asInstanceOf[Map[String, StatsSnapshot]]
}
}
else
} else {
complete(
StatusCodes.NotFound,
parse("""{"message": "To see stats, launch Event Server """ +
"""with --stats argument."}"""))
}
}
}
}
} // stats.json get
}

def receive = runRoute(route)
def receive: Actor.Receive = runRoute(route)

}

Expand Down Expand Up @@ -379,7 +382,7 @@ class StatsActor extends Actor {
longLiveStats.update(appId, statusCode, event)
}

def receive = {
def receive: Actor.Receive = {
case Bookkeeping(appId, statusCode, event) =>
bookkeeping(appId, statusCode, event)
case GetStats(appId) => sender() ! Map(
Expand All @@ -406,7 +409,7 @@ class EventServerActor(
"EventServiceActor")
implicit val system = context.system

def receive = {
def receive: Actor.Receive = {
case StartServer(host, portNum) => {
IO(Http) ! Http.Bind(child, interface = host, port = portNum)
}
Expand All @@ -422,7 +425,7 @@ case class EventServerConfig(
stats: Boolean = false)

object EventServer {
def createEventServer(config: EventServerConfig) = {
def createEventServer(config: EventServerConfig): Unit = {
implicit val system = ActorSystem("EventServerSystem")

val eventClient = Storage.getLEvents()
Expand Down
14 changes: 7 additions & 7 deletions data/src/main/scala/examples/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ object SerializerTest {
appId = appId,
prId = prId)
}
/*case JObject(
JField("a", JInt(a)) ::
JField("b", JString(b)) ::
Nil) => new A(a.intValue,b)*/
/* case JObject(
JField("a", JInt(a)) ::
JField("b", JString(b)) ::
Nil) => new A(a.intValue,b) */
},
{
case d: Event =>
Expand All @@ -86,15 +86,15 @@ object SerializerTest {
test()
}

def test() = {
def test(): Unit = {
implicit val formats = DefaultFormats.lossless +
new EventSeriliazer

val j = parse("""{
"a": 1, "b": "some"} """)

/*val w = read[A]("""{"b": 1,
"a": 1 } """)*/
/* val w = read[A]("""{"b": 1,
"a": 1 } """) */
val w = read[Event]("""{
"event" : "my_event",
"entityId" : "my_entity_id",
Expand Down
31 changes: 16 additions & 15 deletions data/src/main/scala/examples/TestEvents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import io.prediction.data.storage.hbase
import io.prediction.data.storage.StorageClientConfig
import io.prediction.data.storage.Storage

//import io.prediction.data.storage.elasticsearch.ESStorageClient
//import io.prediction.data.storage.hbase.HBStorageClient
// import io.prediction.data.storage.elasticsearch.ESStorageClient
// import io.prediction.data.storage.hbase.HBStorageClient

import io.prediction.data.storage.elasticsearch.ESLEvents
import io.prediction.data.storage.hbase.HBLEvents
Expand Down Expand Up @@ -65,14 +65,15 @@ object TestLEvents {

def testESLEvents() {

/*val config = StorageClientConfig(Seq("localhost"), Seq(9300))
val storageClient = new ESStorageClient(config)
val client = storageClient.client
val eventConnector = storageClient.eventClient*/
val eventConnector = Storage.getDataObject[LEvents]("predictionio_events_es").asInstanceOf[ESLEvents]
/* val config = StorageClientConfig(Seq("localhost"), Seq(9300))
val storageClient = new ESStorageClient(config)
val client = storageClient.client
val eventConnector = storageClient.eventClient */
val eventConnector = Storage.getDataObject[LEvents]("predictionio_events_es").
asInstanceOf[ESLEvents]
implicit val formats = eventConnector.formats

//client.prepareGet("testindex", "events", "Abcdef").get()
// client.prepareGet("testindex", "events", "Abcdef").get()

val x = write(e)
println(x)
Expand Down Expand Up @@ -100,7 +101,7 @@ object TestLEvents {
println(i3)

// force refresh index for testing, else get may not have result
//client.admin().indices().prepareRefresh("testindex").get()
// client.admin().indices().prepareRefresh("testindex").get()

val all = eventConnector.getByAppId(4)
println(all.right.map{ x =>
Expand All @@ -112,17 +113,17 @@ object TestLEvents {
println(delAll)
val all2 = eventConnector.getByAppId(4)
println(all2)
//client.close()
// client.close()
}

def testHBLEvents() = {
def testHBLEvents(): Unit = {

println("testHBLEvents")

/*val config = StorageClientConfig(Seq("localhost"), Seq(9300))
val storageClient = new HBStorageClient(config)
val client = storageClient.client
val eventConnector = storageClient.eventClient*/
/* val config = StorageClientConfig(Seq("localhost"), Seq(9300))
val storageClient = new HBStorageClient(config)
val client = storageClient.client
val eventConnector = storageClient.eventClient */
val storageClient = new hbase.StorageClient(StorageClientConfig(
hosts = Seq("localhost"),
ports = Seq(1234)))
Expand Down
12 changes: 6 additions & 6 deletions data/src/main/scala/storage/BiMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class BiMap[K, V] private[prediction] (

def size: Int = m.size

def take(n: Int) = BiMap(m.take(n))
def take(n: Int): BiMap[K, V] = BiMap(m.take(n))

override def toString = m.toString
override def toString: String = m.toString
}

object BiMap {
Expand Down Expand Up @@ -136,8 +136,8 @@ object BiMap {
* @return a String to Double BiMap
*/
def stringDouble(keys: Set[String]): BiMap[String, Double] = {
//val hm = HashMap(keys.toSeq.zipWithIndex.map(_.toDouble) : _*)
//new BiMap(hm)
// val hm = HashMap(keys.toSeq.zipWithIndex.map(_.toDouble) : _*)
// new BiMap(hm)
stringDoubleImpl(keys.toSeq)
}

Expand All @@ -148,8 +148,8 @@ object BiMap {
* @return a String to Double BiMap
*/
def stringDouble(keys: Array[String]): BiMap[String, Double] = {
//val hm = HashMap(keys.zipWithIndex.mapValues(_.toDouble) : _*)
//new BiMap(hm)
// val hm = HashMap(keys.zipWithIndex.mapValues(_.toDouble) : _*)
// new BiMap(hm)
stringDoubleImpl(keys.toSeq)
}

Expand Down
22 changes: 12 additions & 10 deletions data/src/main/scala/storage/DataMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class DataMap (
*
* @param name The property name
*/
def require(name: String) = {
if (!fields.contains(name))
def require(name: String): Unit = {
if (!fields.contains(name)) {
throw new DataMapException(s"The field ${name} is required.")
}
}

/** Check if this DataMap contains a specific property.
Expand Down Expand Up @@ -96,7 +97,7 @@ class DataMap (
* @param default The default property value of type T
* @return Return the property value of type T
*/
def getOrElse[T: Manifest](name: String, default: T) = {
def getOrElse[T: Manifest](name: String, default: T): T = {
getOpt[T](name).getOrElse(default)
}

Expand All @@ -106,28 +107,28 @@ class DataMap (
* @param that Right hand side DataMap
* @return A new DataMap
*/
def ++ (that: DataMap) = DataMap(this.fields ++ that.fields)
def ++ (that: DataMap): DataMap = DataMap(this.fields ++ that.fields)

/** Creates a new DataMap from this DataMap by removing all elements of
* another collection.
*
* @param that A collection containing the removed property names
* @return A new DataMap
*/
def -- (that: GenTraversableOnce[String]) =
def -- (that: GenTraversableOnce[String]): DataMap =
DataMap(this.fields -- that)

/** Tests whether the DataMap is empty.
*
* @return true if the DataMap is empty, false otherwise.
*/
def isEmpty = fields.isEmpty
def isEmpty: Boolean = fields.isEmpty

/** Collects all property names of this DataMap in a set.
*
* @return a set containing all property names of this DataMap.
*/
def keySet = this.fields.keySet
def keySet: Set[String] = this.fields.keySet

/** Converts this DataMap to a List.
*
Expand Down Expand Up @@ -170,17 +171,18 @@ object DataMap {
* @param fields a Map of String to JValue
* @return a new DataMap initialized by fields
*/
def apply(fields: Map[String, JValue]) = new DataMap(fields)
def apply(fields: Map[String, JValue]): DataMap = new DataMap(fields)

/** Create an DataMap from a JObject
* @param jObj JObject
* @return a new DataMap initialized by a JObject
*/
def apply(jObj: JObject): DataMap = {
if (jObj == null)
if (jObj == null) {
apply()
else
} else {
new DataMap(jObj.obj.toMap)
}
}

/** Create an DataMap from a JSON String
Expand Down
8 changes: 4 additions & 4 deletions data/src/main/scala/storage/EntityMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class EntityIdIxMap(val idToIx: BiMap[String, Long]) extends Serializable {

def toMap: Map[String, Long] = idToIx.toMap

def size = idToIx.size
def size: Long = idToIx.size

def take(n: Int) = new EntityIdIxMap(idToIx.take(n))
def take(n: Int): EntityIdIxMap = new EntityIdIxMap(idToIx.take(n))

override def toString = idToIx.toString
override def toString: String = idToIx.toString
}

/** :: Experimental :: */
Expand Down Expand Up @@ -92,7 +92,7 @@ class EntityMap[A](val idToData: Map[String, A],
new EntityMap[A](idToData.filterKeys(newIdToIx.contains(_)), newIdToIx)
}

override def toString = {
override def toString: String = {
s"idToData: ${idToData.toString} " + s"idToix: ${idToIx.toString}"
}
}
8 changes: 4 additions & 4 deletions data/src/main/scala/storage/Event.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ case class Event(
val prId: Option[String] = None,
val creationTime: DateTime = DateTime.now
) {
override def toString() = {
override def toString(): String = {
s"Event(id=$eventId,event=$event,eType=$entityType,eId=$entityId," +
s"tType=$targetEntityType,tId=$targetEntityId,p=$properties,t=$eventTime," +
s"tags=$tags,pKey=$prId,ct=$creationTime)"
Expand All @@ -67,7 +67,7 @@ private[prediction] object EventValidation {

def isSpecialEvents(name: String): Boolean = specialEvents.contains(name)

def validate(e: Event) = {
def validate(e: Event): Unit = {

require(!e.event.isEmpty, "event must not be empty.")
require(!e.entityType.isEmpty, "entityType must not be empty string.")
Expand Down Expand Up @@ -102,9 +102,9 @@ private[prediction] object EventValidation {
val builtinEntityTypes: Set[String] = Set("pio_pr")
val builtinProperties: Set[String] = Set()

def isBuiltinEntityTypes(name: String) = builtinEntityTypes.contains(name)
def isBuiltinEntityTypes(name: String): Boolean = builtinEntityTypes.contains(name)

def validateProperties(e: Event) = {
def validateProperties(e: Event): Unit = {
e.properties.keySet.foreach { k =>
require(!isReservedPrefix(k) || builtinProperties.contains(k),
s"The property ${k} is not allowed. " +
Expand Down
Loading

0 comments on commit a32e753

Please sign in to comment.