• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala MutableList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中scala.collection.mutable.MutableList的典型用法代码示例。如果您正苦于以下问题:Scala MutableList类的具体用法?Scala MutableList怎么用?Scala MutableList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MutableList类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Game

//设置package包名称以及导入依赖的类
package pl.writeonly.babel.beans

import pl.writeonly.babel.entities.User
import pl.writeonly.babel.entities.Record
import pl.writeonly.babel.entities.Word

import scala.collection.mutable.MutableList
import scala.collection.mutable.HashMap

//@org.springframework.stereotype.Component
class Game(val drawn: Array[Record]) {
  val priv = drawn(0)
  val key = priv.relation.key
  val map= new HashMap[Word, Record] //tra zgadn?? co tam da?
  val lambda = (ml: MutableList[Word], r: Record) => {
    val word = r.relation.value
    this.map + (word -> r)
    ml += word
  }
  val values = drawn.foldLeft(new MutableList[Word])(lambda).toArray
  val tuple = key -> values

} 
开发者ID:writeonly,项目名称:babel,代码行数:24,代码来源:Game.scala


示例2: RecordBean

//设置package包名称以及导入依赖的类
package pl.writeonly.babel.beans
import javax.annotation.Resource
import java.io.BufferedReader
import org.springframework.stereotype.Service
import pl.writeonly.babel.daos.DaoCrud
import pl.writeonly.babel.entities.Record
import pl.writeonly.babel.entities.User
import pl.writeonly.scala.util.ToBoolean
import scala.collection.mutable.MutableList
import pl.writeonly.babel.entities.Relation

@org.springframework.stereotype.Service
class RecordBean(@Resource(name = "daoImpl") val dao: DaoCrud) extends ToBoolean {
  val clazz = classOf[Record]
  def persist(record: Record) = dao.persist(record)
  def persistAll(records: List[Record]) = dao.persistAll(records)
  def find(user: User) = dao.find(clazz);
  def find() = dao.find(clazz)
  def merge(record: Record) = dao.merge(record);

  def parse(reader: BufferedReader): MutableList[Record] = {
    val list = new MutableList[Record]
    do {
      val line: String = reader.readLine
      if (!line) return list
      list += new Record(line)
      var i: Int = new Integer(line).toInt
    } while (true)
    return null
  }
  
  def toRecordAll(relations : List[Relation]) = {
    
  }
} 
开发者ID:writeonly,项目名称:babel,代码行数:36,代码来源:RecordBean.scala


示例3: Assignment2RDD

//设置package包名称以及导入依赖的类
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import scala.collection.mutable.MutableList

object Assignment2RDD {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("Assignment 2").setMaster("local[*]")
    val sc = new SparkContext(conf)
    val filePath = "Path\\to\\textfiles\\*.txt"
    val file = sc.textFile(filePath)
    val ftm = file.map(x => x.split(","))
    val ftm1 = ftm.map(x => (x(0).toInt,x(1).toInt,x(2).trim))
    var y0 = MutableList(0)
    var y1 = MutableList(0)
    var y2 = MutableList(0)
    var y3 = MutableList(0)
    var y4 = MutableList(0)
    val grouped_data = ftm1.groupBy(_._1).collect()
    val grouped_data0 = List(grouped_data).foreach(x => x(0)._2.foreach(x => y0+=x._2))
    val grouped_data1 = List(grouped_data).foreach(x => x(1)._2.foreach(x => y1+=x._2))
    val grouped_data2 = List(grouped_data).foreach(x => x(2)._2.foreach(x => y2+=x._2))
    val grouped_data3 = List(grouped_data).foreach(x => x(3)._2.foreach(x => y3+=x._2))
    val grouped_data4 = List(grouped_data).foreach(x => x(4)._2.foreach(x => y4+=x._2))
    println("1001 ", y0.max)
    println("1002 ", y1.max)
    println("1003 ", y2.max)
    println("1004 ", y3.max)
    println("1005 ", y4.max)
  }
} 
开发者ID:vaibhawvipul,项目名称:LearningApacheSpark,代码行数:31,代码来源:Assignment2RDD.scala


示例4: ParallelCoordinates

//设置package包名称以及导入依赖的类
import org.jfree.chart._
import org.jfree.data.xy._
import scala.math._
import scala.collection.mutable.{MutableList, Map}
import java.io.{FileReader, BufferedReader}

object ParallelCoordinates {
  def readCSVFile(filename: String): Map[String, MutableList[String]] = {
    val file = new FileReader(filename)
    val reader = new BufferedReader(file)
    val csvdata: Map[String, MutableList[String]] = Map()
    try {
      val alldata = new MutableList[Array[String]]
      var line:String = null
      while ({line = reader.readLine(); line} != null) {
        if (line.length != 0) {
          val delimiter: String = ","
          var splitline: Array[String] = line.split(delimiter).map(_.trim)
          alldata += splitline
        }
      }
      val labels = MutableList("sepal length", "sepal width",
        "petal length", "petal width", "class")
      val labelled = labels.zipWithIndex.map {
        case (label, index) => label -> alldata.map(x => x(index))
      }
      for (pair <- labelled) {
        csvdata += pair
      }
    } finally {
      reader.close()
    }
    csvdata
  }

  def main(args: Array[String]) {
    val data = readCSVFile("iris.csv")
    val dataset = new DefaultXYDataset
    for (i <- 0 until data("sepal length").size) {
      val x = Array(0.0, 1.0, 2.0, 3.0)
      val y1 = data("sepal length")(i).toDouble
      val y2 = data("sepal width")(i).toDouble
      val y3 = data("petal length")(i).toDouble
      val y4 = data("petal width")(i).toDouble
      val y = Array(y1, y2, y3, y4)
      val cls = data("class")(i)
      dataset.addSeries(cls + i, Array(x, y))
    }
    val frame = new ChartFrame("Parallel Coordinates",
      ChartFactory.createXYLineChart("Parallel Coordinates", "x", "y",
      dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL,
      false, false, false))
    frame.pack()
    frame.setVisible(true)
  }
} 
开发者ID:PacktPublishing,项目名称:Scientific-Computing-with-Scala,代码行数:57,代码来源:plot.scala


示例5: CSVReader

//设置package包名称以及导入依赖的类
import scala.collection.mutable.{MutableList, Map}
import java.io.{FileReader, BufferedReader}

object CSVReader {
 def main(args: Array[String]) {
   val file = new FileReader("iris.csv")
   val reader = new BufferedReader(file)
   try {
     val alldata = new MutableList[Array[String]]
     var line:String = null
     while ({line = reader.readLine(); line} != null) {
       if (line.length != 0) {
         val delimiter: String = ","
         var splitline: Array[String] = line.split(delimiter).map(_.trim)
         alldata += splitline
       }
     }
     val labels = MutableList("sepal length", "sepal width",
       "petal length", "petal width", "class")
     val labelled = labels.zipWithIndex.map {
       case (label, index) => label -> alldata.map(x => x(index))
     }
     val csvdata: Map[String, MutableList[String]] = Map()
     for (pair <- labelled) {
       csvdata += pair                                           
     }
   }
   finally {
     reader.close()
   }
 }
} 
开发者ID:PacktPublishing,项目名称:Scientific-Computing-with-Scala,代码行数:33,代码来源:CSVReader.scala



注:本文中的scala.collection.mutable.MutableList类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala IOResult类代码示例发布时间:2022-05-23
下一篇:
Scala Left类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap