Skip to content

Commit

Permalink
Fix serialization of MutablePair. Also provide an interface for easy …
Browse files Browse the repository at this point in the history
…updating.
  • Loading branch information
marmbrus committed Mar 14, 2014
1 parent 181b130 commit 8bfd973
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/scala/org/apache/spark/util/MutablePair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ package org.apache.spark.util
* @param _2 Element 2 of this MutablePair
*/
case class MutablePair[@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T1,
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
(var _1: T1, var _2: T2)
extends Product2[T1, T2]
{
/** No-arg constructor for serialization */
def this() = this(null.asInstanceOf[T1], null.asInstanceOf[T2])

/** Updates this pair with new values and returns itself */
def apply(n1: T1, n2: T2): MutablePair[T1, T2] = {
_1 = n1
_2 = n2
this
}

override def toString = "(" + _1 + "," + _2 + ")"

override def canEqual(that: Any): Boolean = that.isInstanceOf[MutablePair[_,_]]
Expand Down

0 comments on commit 8bfd973

Please sign in to comment.