本文整理汇总了Scala中java.util.ArrayList类的典型用法代码示例。如果您正苦于以下问题:Scala ArrayList类的具体用法?Scala ArrayList怎么用?Scala ArrayList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayList类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: UsingScalaTest
//设置package包名称以及导入依赖的类
import org.scalatest._
import java.util.ArrayList
class UsingScalaTest extends FlatSpec with Matchers {
trait EmptyArrayList {
val list = new ArrayList[String]
}
"a list" should "be empty on create" in new EmptyArrayList {
list.size should be (0)
}
"a list" should "increase in size upon add" in new EmptyArrayList {
list.add("Milk")
list add "Sugar"
list.size should be (2)
}
}
示例2: TestUtils
//设置package包名称以及导入依赖的类
package org.apache.spark.sql
import java.nio.ByteBuffer
import java.util.{ArrayList, HashMap}
import scala.util.Random
object TestUtils {
def generateRandomByteBuffer(rand: Random, size: Int): ByteBuffer = {
val bb = ByteBuffer.allocate(size)
val arrayOfBytes = new Array[Byte](size)
rand.nextBytes(arrayOfBytes)
bb.put(arrayOfBytes)
}
def generateRandomMap(rand: Random, size: Int): java.util.Map[String, Int] = {
val jMap = new HashMap[String, Int]()
for (i <- 0 until size) {
jMap.put(rand.nextString(5), i)
}
jMap
}
def generateRandomArray(rand: Random, size: Int): ArrayList[Boolean] = {
val vec = new ArrayList[Boolean]()
for (i <- 0 until size) {
vec.add(rand.nextBoolean())
}
vec
}
}
示例3: SendTwilio
//设置package包名称以及导入依赖的类
package com.trn.sms
import com.twilio.sdk.TwilioRestClient
import com.twilio.sdk.TwilioRestException
import com.twilio.sdk.resource.factory.MessageFactory
import com.twilio.sdk.resource.instance.Message
import org.apache.http.NameValuePair
import org.apache.http.message.BasicNameValuePair
import java.util.ArrayList
import java.util.List
object SendTwilio extends App {
val ACCOUNT_SID = "AC270965dc1d10bbe8aa812f944c351e2c"
val AUTH_TOKEN = "57a39ded3bd4b43913fb47703ad5cd65"
val client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
// Build a filter for the MessageList
val params = new ArrayList[NameValuePair]()
params.add(new BasicNameValuePair("Body", "Test Twilio messagessssss"))
params.add(new BasicNameValuePair("To", "+447441907695"))
params.add(new BasicNameValuePair("From", "+441618504732"))
val messageFactory = client.getAccount().getMessageFactory()
val message = messageFactory.create(params)
println(message.getSid())
}
示例4: MetroCar
//设置package包名称以及导入依赖的类
package models
import java.util.ArrayList
class MetroCar(
var id: Int = 0,
var capacity: Int = 0,
var departure_station: String = null,
var destination_station: String = null,
var route: Int,
var amountPassengers: Int = 0
) {
var currentSchedule: Schedule = new Schedule()
var schedules: ArrayList[Schedule] = new ArrayList[Schedule]()
override def toString(): String = "MetroCar: " + id + ". " + departure_station + " -> " + destination_station + " (" + capacity + ")"
}
示例5: Application
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.functional.syntax._
import models.{Passenger, Station, DensityPassenger}
import java.util.{ArrayList}
import main.{PassengerUtils, StartUtils}
class Application @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
def getName(station_id: Int) = Action {
case class DensityPassengerJson(range: String, amountPassengersEntering: Int, amountPassengersLeaving: Int)
case class Content(station: String, data: Seq[DensityPassengerJson])
implicit val densityPassengerWrites = new Writes[DensityPassengerJson] {
def writes(dto: DensityPassengerJson) = Json.obj(
"range" -> dto.range,
"amount_entering" -> dto.amountPassengersEntering,
"amount_leaving" -> dto.amountPassengersLeaving
)
}
implicit val contentWrites = new Writes[Content] {
def writes(dto: Content) = Json.obj(
"station" -> dto.station,
"data" -> dto.data
)
}
var rs: ArrayList[DensityPassenger] = PassengerUtils.densityPassenger(station_id)
var data = Seq(DensityPassengerJson(rs.get(0).range, rs.get(0).amountPassengersEntering, rs.get(0).amountPassengersLeaving))
for(index <- 1 until rs.size) {
data = (data):+DensityPassengerJson(rs.get(index).range, rs.get(index).amountPassengersEntering, rs.get(index).amountPassengersLeaving)
}
var station_ent: Station = StartUtils.searchStationById(station_id)
var station = ""
if(station_ent != null)
station = station_ent.name
Ok(Json.toJson(Content(station, data)))
}
}
示例6: UrlUtilsTest
//设置package包名称以及导入依赖的类
import java.util
import java.util.{ArrayList, Date, HashSet}
import data.SyncData
import utils.{RedisUtils, UrlUtils, Utils}
object UrlUtilsTest extends App {
SpeedFilter.filter(null)
def test(): Unit = {
syncData()
def materialMap = new util.HashMap[String, HashSet[CampMaterial]]()
def materialSet = new util.HashSet[CampMaterial]()
materialMap.put("1", materialSet)
SpeedFilter.filter(materialMap)
}
def redisTest(): Unit = {
val keyList = new ArrayList[String]()
val k1 = (1000 + ":" + "imp" + ":" + Utils.getYYYYMMDD(new Date()))
val k2 = (1001 + ":" + "imp" + ":" + Utils.getYYYYMMDD(new Date()))
keyList.add(k1)
keyList.add(k2)
val value = RedisUtils.mget(keyList)
println(value)
}
def syncData(): Unit = {
SyncData.sync()
}
}
示例7: TypeInference
//设置package包名称以及导入依赖的类
package org.precompiler.scala101.ch05
import java.util.ArrayList
object TypeInference {
def main(args: Array[String]): Unit = {
var list1 = new ArrayList
//compilation error
//if parametric type is omitted, type "Nothing" will be used
//list1.add("")
var list2 = new ArrayList[String]
list2.add("elem1")
}
}
示例8: Public
//设置package包名称以及导入依赖的类
package de.dangoe.freda.jooq.generated.public
import de.dangoe.freda.jooq.generated.DefaultCatalog
import de.dangoe.freda.jooq.generated.public.tables.Accounts
import de.dangoe.freda.jooq.generated.public.tables.Users
import java.util.ArrayList
import java.util.Arrays
import java.util.List
import javax.annotation.Generated
import org.jooq.Catalog
import org.jooq.Table
import org.jooq.impl.SchemaImpl
import scala.Array
object Public {
@Generated(
value = Array(
"http://www.jooq.org",
"jOOQ version:3.9.4"
),
comments = "This class is generated by jOOQ"
)
class Public extends SchemaImpl("PUBLIC", DefaultCatalog.DEFAULT_CATALOG) {
override def getCatalog : Catalog = DefaultCatalog.DEFAULT_CATALOG
override def getTables : List[Table[_]] = {
val result = new ArrayList[Table[_]]
result.addAll(getTables0)
result
}
private def getTables0(): List[Table[_]] = {
return Arrays.asList[Table[_]](
Accounts.ACCOUNTS,
Users.USERS)
}
}
示例9: DocumentMerger
//设置package包名称以及导入依赖的类
package eu.tznvy.jancy.modulesgen.helpers
import java.util.{ArrayList, LinkedHashMap}
import scala.collection.JavaConverters._
object DocumentMerger {
def merge(
document: LinkedHashMap[String, Object],
fragment: LinkedHashMap[String, Object]
): LinkedHashMap[String, Object] = {
val result = new LinkedHashMap[String, Object](document)
for(key <- fragment.keySet().asScala) {
val bothHaveKey = result.keySet().contains(key)
val areMaps = (bothHaveKey
&& result.get(key).isInstanceOf[LinkedHashMap[_, _]]
&& fragment.get(key).isInstanceOf[LinkedHashMap[_, _]])
val areLists = (!areMaps && bothHaveKey
&& result.get(key).isInstanceOf[ArrayList[_]]
&& fragment.get(key).isInstanceOf[ArrayList[_]])
if (areMaps) {
val curMap = result.get(key).asInstanceOf[LinkedHashMap[String, Object]]
val fragmentMap = fragment.get(key).asInstanceOf[LinkedHashMap[String, Object]]
val merged = merge(curMap, fragmentMap)
result.put(key, merged)
} else if (areLists) {
val curList = result.get(key).asInstanceOf[ArrayList[Object]]
val curListCopy = new ArrayList[Object](curList)
val fragmentList = fragment.get(key).asInstanceOf[ArrayList[Object]]
curListCopy.addAll(fragmentList)
result.put(key, curListCopy)
} else {
result.put(key, fragment.get(key))
}
}
result
}
}