Skip to content

Commit

Permalink
Add some code to prevent NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Conrad committed Apr 28, 2010
1 parent 67723c7 commit 65689b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package com.linkedin.norbert.cluster

import scala.reflect.BeanProperty
import com.google.protobuf.InvalidProtocolBufferException
import com.linkedin.norbert.protos.NorbertProtos

/**
* The <code>Node</code> companion object. Provides factory methods and implicits.
*/
object Node {

/**
* Creates a <code>Node</code> instance with no partitions assigned to it.
*
Expand Down Expand Up @@ -86,7 +85,7 @@ object Node {
final case class Node(id: Int, url: String, partitions: Set[Int], available: Boolean) {
if (url == null) throw new NullPointerException("url must not be null")
if (partitions == null) throw new NullPointerException("partitions must not be null")

override def hashCode = id.hashCode

override def equals(other: Any) = other match {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2009-2010 LinkedIn, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.linkedin.norbert.cluster.javaapi

import com.linkedin.norbert.cluster.javaapi.{Node => JNode}
Expand All @@ -6,11 +21,13 @@ import com.linkedin.norbert.cluster.{Node => SNode}
object Implicits {
import collection.jcl.Conversions._

implicit def scalaNodeToJavaNode(node: SNode): JNode = JavaNode(node)
implicit def scalaNodeToJavaNode(node: SNode): JNode = {
if (node == null) null else JavaNode(node)
}

implicit def javaNodeToScalaNode(node: JNode): SNode = {
val s = node.getPartitions.asInstanceOf[java.util.Set[Int]].foldLeft(Set[Int]()) { (set, id) => set + id }
SNode(node.getId, node.getUrl, s, node.isAvailable)
if (node == null) null else SNode(node.getId, node.getUrl,
node.getPartitions.asInstanceOf[java.util.Set[Int]].foldLeft(Set[Int]()) { (set, id) => set + id }, node.isAvailable)
}

implicit def scalaNodeSetToJavaNodeSet(nodes: Set[SNode]): java.util.Set[JNode] = {
Expand Down

0 comments on commit 65689b4

Please sign in to comment.