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.

Author: Michael Armbrust <[email protected]>

Closes apache#141 from marmbrus/mutablePair and squashes the following commits:

f5c4783 [Michael Armbrust] Change function name to update
8bfd973 [Michael Armbrust] Fix serialization of MutablePair.  Also provide an interface for easy updating.
  • Loading branch information
marmbrus authored and James Z.M. Gao committed Mar 15, 2014
1 parent 223fec2 commit 3e9139b
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 @@ -26,10 +26,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 update(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 3e9139b

Please sign in to comment.