It should work to match on the class:

    partitioner match {
      case _: CanonicalRandomVertexCut => // rest of method
      case _ => // throw exception
    }