第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 java lambda 謂詞移植到 scala

將 java lambda 謂詞移植到 scala

侃侃無(wú)極 2023-06-04 19:45:55
我如何移植Iterables.filter(tree? ? ? ? ? ? ? ? // do the first search using the bounds? ? ? ? ? ? ? ? .search(bounds),? ? ? ? ? ? ? ? // refine using the exact distance? ? ? ? ? ? ? ? entry -> {? ? ? ? ? ? ? ? ? ? Point p = entry.geometry();? ? ? ? ? ? ? ? ? ? Position position = Position.create(p.y(), p.x());? ? ? ? ? ? ? ? ? ? return from.getDistanceToKm(position) < distanceKm;? ? ? ? ? ? ? ? });從 Java 到 Scala?我的以下方法失敗了:import com.github.davidmoten.grumpy.core.Positionimport com.github.davidmoten.rtree2.{Iterables, RTree}import com.github.davidmoten.rtree2.geometry.{Geometries, Point}val sydney = Geometries.point(151.2094, -33.86)val canberra = Geometries.point(149.1244, -35.3075)val brisbane = Geometries.point(153.0278, -27.4679)val bungendore = Geometries.point(149.4500, -35.2500)var tree = RTree.star.create[String, Point]tree = tree.add("Sydney", sydney)tree = tree.add("Brisbane", brisbane)val distanceKm = 300val list = Iterables.toList(search(tree, canberra, distanceKm))def createBounds(from: Position, distanceKm: Double) = { // this calculates a pretty accurate bounding box. Depending on the? // performance you require you wouldn't have to be this accurate because? // accuracy is enforced later? val north = from.predict(distanceKm, 0)? val south = from.predict(distanceKm, 180)? val east = from.predict(distanceKm, 90)? val west = from.predict(distanceKm, 270)? Geometries.rectangle(west.getLon, south.getLat, east.getLon, north.getLat)}因?yàn)轭愋蚭ntry似乎沒(méi)有明確定義。
查看完整描述

1 回答

?
喵喵時(shí)光機(jī)

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊

tree類型RTree[String, Point]為T(mén)=String, S=Point. 所以tree.search(bounds)有 type Iterable[Entry[String, Point]]。所以entry有 type Entry[String, Point]。


嘗試


(entry: Entry[String,Point]) => {

  def foo(entry: Entry[String,Point]) = {

    val p = entry.geometry

    val position = Position.create(p.y, p.x)

    from.getDistanceToKm(position) < distanceKm

  }


  foo(entry)

})

在 Scala 2.13.0、rtree2 0.9-RC1、grumpy-core 0.2.4 中測(cè)試。


在 2.11 中,這應(yīng)該只是


import scala.compat.java8.FunctionConverters._


((entry: Entry[String,Point]) => {

  def foo(entry: Entry[String,Point]) = {

    val p = entry.geometry

    val position = Position.create(p.y, p.x)

    from.getDistanceToKm(position) < distanceKm

  }


  foo(entry)

}).asJava

libraryDependencies += "org.scala-lang.modules" %% "scala-java8-compat" % "0.9.0"


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)