iota-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonyfaust...@apache.org
Subject [15/31] incubator-iota git commit: Removed scalastyle in TrieNode
Date Tue, 29 Nov 2016 23:29:14 GMT
Removed scalastyle in TrieNode


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/15ab0a81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/15ab0a81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/15ab0a81

Branch: refs/heads/master
Commit: 15ab0a8126e010ef6af20eec4016aaf159154d70
Parents: 6f4e0be
Author: Shivansh <shiv4nsh@gmail.com>
Authored: Fri Nov 4 00:30:40 2016 +0530
Committer: Shivansh <shiv4nsh@gmail.com>
Committed: Fri Nov 4 00:30:40 2016 +0530

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/TrieNode.scala    | 28 +++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/15ab0a81/fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala b/fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala
index 4de3da7..5afd3ee 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/TrieNode.scala
@@ -17,7 +17,7 @@
 
 package org.apache.iota.fey
 
-import play.api.libs.json.{JsArray, JsObject, JsValue, Json}
+import play.api.libs.json.{JsObject, JsValue, Json}
 
 import scala.annotation.tailrec
 import scala.collection.mutable.ArrayBuffer
@@ -29,25 +29,27 @@ case class TrieNode(path: String, children: ArrayBuffer[TrieNode], events:ArrayB
 
 protected class Trie(systemName: String){
 
+  val DEFAULT_NULL = null
+
   private val root: TrieNode = TrieNode(systemName, ArrayBuffer.empty, ArrayBuffer.empty)
   var elements: Int = 0
 
-  def append(path: String, event: Monitor.MonitorEvent = null): Unit = {
+  def append(path: String, event: Monitor.MonitorEvent = DEFAULT_NULL): Unit = {
     append(path.replaceFirst("akka://","").split("/"),root,1,event)
   }
 
   @tailrec private def append(path: Array[String], root: TrieNode, index: Int, event: Monitor.MonitorEvent):
Unit = {
-    if(root != null && index < path.length){
+    if (Option(root).isDefined && index < path.length) {
       var nextRoot = root.children.filter(child => child.path == path(index))
       if(nextRoot.isEmpty){
         nextRoot = ArrayBuffer(TrieNode(path(index), ArrayBuffer.empty, ArrayBuffer.empty))
         root.children += nextRoot(0)
         elements += 1
       }
-      if(event != null && index == path.length - 1){
+      if (Option(event).isDefined && index == path.length - 1) {
         nextRoot(0).events += event
       }
-      append(path, nextRoot(0),index+1, event)
+      append(path, nextRoot(0), index + 1, event)
     }
   }
 
@@ -56,7 +58,7 @@ protected class Trie(systemName: String){
   }
 
   @tailrec private def recHasPath(root: TrieNode, path: Array[String], index: Int): Boolean
= {
-    if(root != null && index < path.length) {
+    if (Option(root).isDefined && index < path.length) {
       var nextRoot = root.children.filter(child => child.path == path(index))
       if(nextRoot.isEmpty){
         false
@@ -73,7 +75,7 @@ protected class Trie(systemName: String){
   }
 
   @tailrec private def recGetNode(root: TrieNode, path: Array[String], index: Int): Option[TrieNode]=
{
-    if(root != null && index < path.length) {
+    if (Option(root).isDefined && index < path.length) {
       var nextRoot = root.children.filter(child => child.path == path(index))
       if(nextRoot.isEmpty){
         None
@@ -99,11 +101,11 @@ protected class Trie(systemName: String){
   }
 
   def print:JsValue = {
-    getObject(root, null)
+    getObject(root, DEFAULT_NULL)
   }
 
   def printWithEvents:JsValue = {
-    getObjectEvent(root, null)
+    getObjectEvent(root, DEFAULT_NULL)
   }
 
   def getRootChildren():ArrayBuffer[TrieNode] = {
@@ -111,9 +113,9 @@ protected class Trie(systemName: String){
   }
 
   private def getObject(root: TrieNode, parent: TrieNode):JsObject = {
-    if(root != null) {
+    if (Option(root).isDefined) {
      Json.obj("name" -> root.path,
-       "parent" -> (if(parent != null) parent.path else "null"),
+       "parent" -> (if (Option(parent).isDefined) parent.path else "null"),
         "children" -> root.children.map(getObject(_, root))
      )
     }else{
@@ -122,9 +124,9 @@ protected class Trie(systemName: String){
   }
 
   private def getObjectEvent(root: TrieNode, parent: TrieNode):JsObject = {
-    if(root != null) {
+    if (Option(root).isDefined) {
       Json.obj("name" -> root.path,
-        "parent" -> (if(parent != null) parent.path else "null"),
+        "parent" -> (if (Option(parent).isDefined) parent.path else "null"),
         "events" -> root.events.map(event => {
           Json.obj("type" -> event.event,
           "timestamp" -> event.timestamp,


Mime
View raw message