本文整理汇总了Scala中java.io.Serializable类的典型用法代码示例。如果您正苦于以下问题:Scala Serializable类的具体用法?Scala Serializable怎么用?Scala Serializable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Serializable类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Nucleobases
//设置package包名称以及导入依赖的类
package bio.populator
import java.io.Serializable
object Nucleobases {
sealed abstract class Nucleobase(symbol: String) extends Serializable {
def reverse: Nucleobase
override def toString: String = symbol
}
case object Adenine extends Nucleobase("A") {
override def reverse: Nucleobase = Thymine
}
case object Thymine extends Nucleobase("T") {
override def reverse: Nucleobase = Adenine
}
case object Cytosine extends Nucleobase("C") {
override def reverse: Nucleobase = Guanine
}
case object Guanine extends Nucleobase("G") {
override def reverse: Nucleobase = Cytosine
}
val parseString: Map[String, Nucleobase] = Map(
"A" -> Adenine,
"T" -> Thymine,
"C" -> Cytosine,
"G" -> Guanine
)
def otherBases(s: Char): Seq[Char] = {
s match {
case 'A' => Seq('T', 'C', 'G')
case 'T' => Seq('A', 'C', 'G')
case 'C' => Seq('A', 'T', 'G')
case 'G' => Seq('A', 'T', 'C')
}
}
}
示例2: CocoaParameters
//设置package包名称以及导入依赖的类
package optimizers
import java.io.Serializable
import breeze.linalg.DenseVector
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.rdd.RDD
class CocoaParameters(var n: Int,
var numRounds: Int,
var localIterFrac: Double,
var lambda: Double,
var beta: Double,
var gamma: Double,
var numParts: Int,
var wInit: DenseVector[Double]) extends Serializable {
def this(train: RDD[LabeledPoint], test: RDD[LabeledPoint]) {
this(train.count().toInt,
200,
1.0,
0.01,
1.0,
1.0,
train.partitions.size,
DenseVector.zeros[Double](train.first().features.size))
}
def getLocalIters() = (localIterFrac * n / numParts).toInt
def getDistOptPar(): distopt.utils.Params ={
val loss = distopt.utils.OptUtils.hingeLoss _
return distopt.utils.Params(loss, n, wInit, numRounds, getLocalIters, lambda, beta, gamma)
}
override def toString = s"CocoaParameters(n: $n, numRounds: $numRounds, localIters: $getLocalIters, " +
s"lambda: $lambda, beta: $beta, gamma: $gamma, wInit: $wInit)"
}
示例3: ProxCocoaParameters
//设置package包名称以及导入依赖的类
package optimizers
import java.io.Serializable
import breeze.linalg.SparseVector
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.rdd.RDD
class ProxCocoaParameters(var n: Int,
var iterations: Int,
var localIterFrac: Double,
var lambda: Double,
var eta: Double,
var numFeature: Int,
var numParts: Int,
var alphaInit: SparseVector[Double]) extends Serializable {
def this(train: RDD[LabeledPoint], test: RDD[LabeledPoint], eta: Double = 0.5) {
this(train.count().toInt,
100,
0.9,
0.1,
eta,
train.first().features.size,
train.partitions.size,
SparseVector.zeros[Double](train.first().features.size))
}
def getLocalIters = Math.max(1, (localIterFrac * numFeature / numParts).toInt)
def getL1DistOptPar(): l1distopt.utils.Params = {
return l1distopt.utils.Params(alphaInit, n, iterations, getLocalIters, lambda, eta)
}
override def toString = s"ProxCocoaParameters(n: $n, iterations: $iterations, " +
s"localIters: $getLocalIters, lambda: $lambda, eta: $eta, alphaInit: $alphaInit)"
}
示例4: CliftonInjector
//设置package包名称以及导入依赖的类
package clifton.graph
import java.io.Serializable
import java.util.concurrent.atomic.AtomicInteger
import api.Injector
import clifton.graph.exceptions.InjectException
import exonode.clifton.config.ProtocolConfig
import exonode.clifton.node.SpaceCache
import exonode.clifton.node.entries.DataEntry
import exonode.clifton.signals.Log.{Log, LogInjected}
class CliftonInjector(uuid: String, marker: String, rootActivities: List[String], val canInject: () => Boolean,
config: ProtocolConfig = ProtocolConfig.Default) extends Injector {
private val dataSpace = SpaceCache.getDataSpace
private val dataTemplates: List[DataEntry] =
rootActivities.map(rootActivity => DataEntry(rootActivity, marker, null, null, null))
private val nextIndex = new AtomicInteger(0)
def inject(input: Serializable): Int = {
if (!canInject())
throw new InjectException("Internal Inject Error")
val currentIndex = nextIndex.getAndIncrement()
val injectId = s"$uuid:$currentIndex"
val dataEntries = dataTemplates.map(_.setInjectId(injectId).setOrderId(s"$currentIndex").setData(Some(input)))
try {
for (dataEntry <- dataEntries)
dataSpace.write(dataEntry, config.DataLeaseTime)
Log.writeLog(LogInjected(injectId))
} catch {
case _: Exception => throw new InjectException("Internal Inject Error")
}
currentIndex
}
def inject(occurrences: Int, input: Serializable): Iterable[Int] = {
if (occurrences < 1)
throw new InjectException("Too few occurrences. Occurrences should be >= 1")
else
(0 until occurrences).map(_ => inject(input))
}
def injectMany(inputs: Iterable[Serializable]): Vector[Int] = {
inputs.map(x => inject(x)).toVector
}
}
示例5: ConfirmDialog
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui.dialog
import java.io.Serializable
import android.app.{Dialog, DialogFragment}
import android.content.DialogInterface
import android.content.DialogInterface.OnClickListener
import android.os.Bundle
import android.support.v7.app.AlertDialog
object ConfirmDialog {
def newInstance(title: Option[String], msg: String, iconResId: Option[Int], lis: ClickListener) = {
val instance = new ConfirmDialog
val bun = new Bundle
bun.putString("msg", msg)
bun.putSerializable("listener", lis)
title foreach { bun.putString("title", _) }
iconResId foreach { bun.putInt("icon", _)}
instance.setArguments(bun)
instance
}
trait ClickListener extends Serializable {
def onClick()
}
}
class ConfirmDialog extends DialogFragment {
override def onCreateDialog(savedInstanceState: Bundle): Dialog = {
val builder = new AlertDialog.Builder(getActivity)
.setMessage(getArguments.getString("msg"))
.setPositiveButton("OK", new OnClickListener {
override def onClick(dialogInterface: DialogInterface, i: Int) =
getArguments.getSerializable("listener").asInstanceOf[ConfirmDialog.ClickListener].onClick()
})
Option(getArguments.getString("title")) foreach { builder.setTitle(_) }
val icon = getArguments.getInt("icon", 0)
if (icon > 0) builder.setIcon(icon)
builder.create
}
}
示例6: log
//设置package包名称以及导入依赖的类
import java.io.Serializable
trait Logger {
def log(msg: String) // An abstract method
}
class ConsoleLogger extends Logger // Use extends, not implements
with Cloneable with Serializable { // Use with to add multiple traits
def log(msg: String) { println(msg) } // No override needed
}
object Main extends App {
val logger = new ConsoleLogger
logger.log("Exiting Main")
}
示例7: catchError
//设置package包名称以及导入依赖的类
package traits
import java.io.Serializable
import scala.language.postfixOps
trait Arg extends App {
private lazy val argsbool0 = args filter (x => x.endsWith("=y") || x.endsWith("=n"))
private lazy val argsnumb0 = args filter (x => x.split('=').last.filter(x => x != '.' && x != '-').forall(x => x.isDigit))
private lazy val argslist0 = args filter (x => x.contains(","))
private lazy val argstext0 = args //diff argsbool0 diff argsnumb0 diff argslist0
lazy val argsall = args map parse toMap
lazy val argsbool1 = argsbool0 map parse toMap
lazy val argsnumb1 = argsnumb0 map parse toMap
lazy val argslist1 = argsall.toList map { case (k, v) => k -> v.split(',').toList } toMap
lazy val argstext1 = argstext0 map parse toMap
lazy val consistent = args.length == (args map parse).map(_._1).distinct.length
def catchError[T](argsmap: Map[String, T], k: String): T = if (consistent) argsmap.getOrElse(k, {
if (argsall.contains(k)) println(s"Invalid value '${argsall(k)}' for argument '$k'.")
else println(s"Missing argument '$k'.")
sys.exit(0)
}) else {
println(s"Inconsistent list of arguments '${args.mkString("\n")}'.")
sys.exit(0)
}
def argsbool(k: String): String = catchError(argsbool1, k)
def argsnumb(k: String): String = catchError(argsnumb1, k)
def argslist(k: String): Serializable = catchError(argslist1, k)
def argstext(k: String): String = catchError(argstext1, k)
def parse(s: String): (String, String) = {
val Seq(a, b) = s.split('=').toSeq
a -> b
}
}
示例8: random
//设置package包名称以及导入依赖的类
package worker
import java.io.Serializable
import java.util.concurrent.ThreadLocalRandom
sealed trait Device extends Serializable {
def random = ThreadLocalRandom.current
def getId: String
def getState: String
}
// Thermostat with random id & state
class Thermostat extends Device {
val states = List("HEAT", "COOL")
val id = "thermostat-" + (1000 + super.random.nextInt(0, 100)).toString
val state = states(super.random.nextInt(0, states.size))
def getId: String = id
def getState: String = state
}
// Lamp with random id & state
class Lamp extends Device {
val states = List("ON", "OFF")
val id = "lamp-" + (5000 + super.random.nextInt(0, 500)).toString
val state = states(super.random.nextInt(0, states.size))
def getId: String = id
def getState: String = state
}
// Security alarm with random id & state
class SecurityAlarm extends Device {
val states = List("ON", "OFF")
val id = "security-alarm-" + (9000 + super.random.nextInt(0, 100)).toString
val state = states(super.random.nextInt(0, states.size))
def getId: String = id
def getState: String = state
}
示例9: Zone
//设置package包名称以及导入依赖的类
package tas.prediction.zones
import java.io.Serializable
import tas.types.{
TimedTick,
Buy,
Sell
}
case class Zone(start:TimedTick, end:TimedTick) extends Serializable {
@transient
lazy val upDiff = Buy.closePrice(end.price) - Buy.openPrice(start.price)
@transient
lazy val downDiff = Sell.openPrice(start.price) - Sell.closePrice(end.price)
override def equals(o:Any) = o match {
case that:Zone => that.start == start && that.end == end
case _ => false
}
override def toString() = "Zone(" + start + ", " + end + ")"
}
示例10: LinearMethod
//设置package包名称以及导入依赖的类
import java.io.Serializable
import breeze.linalg.{DenseVector, Vector}
import optimizers.Optimizer
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.rdd.RDD
import utils.Functions.{LossFunction, Regularizer}
abstract class LinearMethod(val loss: LossFunction,
val regularizer: Regularizer) extends Serializable {
val optimizer: Optimizer
var elapsed: Option[Long] = None
def optimize(): Vector[Double] = {
val start = System.nanoTime()
val w: Vector[Double] = optimizer.optimize()
val elap = System.nanoTime() - start
elapsed = Some(elap)
return w;
}
def predict(w: Vector[Double], test: RDD[org.apache.spark.mllib.linalg.Vector]): RDD[Double]
def error(trueLabels: RDD[Double], predictions: RDD[Double]): Double
def testError(w: Vector[Double], test: RDD[org.apache.spark.mllib.linalg.Vector], trueLabels: RDD[Double]): Double = {
val predictions = predict(w, test)
val err = error(trueLabels, predictions)
return err
}
def getObjective(w: DenseVector[Double], x: RDD[LabeledPoint]): Double = {
val n: Double = x.count()
val sum = x.map(p => loss.loss(w, DenseVector(p.features.toArray), p.label)).reduce(_ + _)
return regularizer.lambda * regularizer.value(w) + (sum / n);
}
}