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

Scala Entry类代码示例

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

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



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

示例1: JavaIterable

//设置package包名称以及导入依赖的类
package mesosphere.marathon
package stream

import java.util
import java.util.AbstractMap.SimpleImmutableEntry
import java.util.Map.Entry

import scala.collection.JavaConverters._
import scala.collection.immutable.Seq


trait JavaConversions {
  implicit class JavaIterable[T](sc: Iterable[T]) extends util.AbstractCollection[T] {
    override def size(): Int = sc.size
    override def iterator(): util.Iterator[T] = sc.toIterator.asJava
  }

  implicit class JavaImmutableList[T](sc: Seq[T]) extends util.AbstractList[T] {
    override def get(i: Int): T = sc(i)
    override def size(): Int = sc.size
  }

  implicit class JavaSet[T](sc: Set[T]) extends util.AbstractSet[T] {
    override def size(): Int = sc.size
    override def iterator(): util.Iterator[T] = sc.toIterator.asJava
  }

  implicit class JavaMap[K, V](m: Map[K, V]) extends util.AbstractMap[K, V] {
    lazy val entries: Set[Entry[K, V]] =
      m.map { case (k, v) => new SimpleImmutableEntry[K, V](k, v) }(collection.breakOut)
    override def entrySet(): util.Set[Entry[K, V]] = entries
  }
}

object JavaConversions extends JavaConversions 
开发者ID:xiaozai512,项目名称:marathon,代码行数:36,代码来源:JavaConversions.scala


示例2: Cache

//设置package包名称以及导入依赖的类
package org.argus.jc.incremental.jawa.local

import java.lang.ref.SoftReference
import java.util
import java.util.Map.Entry


class Cache[K, V](capacity: Int) {
  private val lock = new Object()

  private val map = new util.LinkedHashMap[K, SoftReference[V]](capacity, 0.75F, true) {
    override def removeEldestEntry(eldest: Entry[K, SoftReference[V]]) = size > capacity
  }

  def getOrUpdate(key: K)(value: => V): V = lock.synchronized {
    Option(map.get(key)).flatMap(reference => Option(reference.get())).getOrElse {
      val v = value
      map.put(key, new SoftReference(v))
      v
    }
  }
} 
开发者ID:arguslab,项目名称:argus-cit-intellij,代码行数:23,代码来源:Cache.scala


示例3: Netty4HeaderMap

//设置package包名称以及导入依赖的类
package com.twitter.finagle.netty4.http

import com.twitter.finagle.http.HeaderMap
import io.netty.handler.codec.http.HttpHeaders
import java.util.Map.Entry
import scala.collection.JavaConverters._


private[http] class Netty4HeaderMap(private[http] val underlying: HttpHeaders) extends HeaderMap {
  import Netty4HeaderMap._

  def getAll(key: String): Iterable[String] = underlying.getAll(key).asScala

  def set(k: String, v: String): HeaderMap = {
    underlying.set(k, v)
    this
  }

  def add(k: String, v: String): HeaderMap = {
    underlying.add(k, v)
    this
  }

  def +=(kv: (String, String)): Netty4HeaderMap.this.type = {
    underlying.add(kv._1, kv._2)
    this
  }

  def -=(key: String): Netty4HeaderMap.this.type = {
    underlying.remove(key)
    this
  }

  def get(key: String): Option[String] = Option(underlying.get(key))

  def iterator: Iterator[(String, String)] =
    underlying.iteratorAsString().asScala.map(entryToTuple)

}

private[http] object Netty4HeaderMap {
  val entryToTuple: (Entry[String, String]) => (String, String) =
    { entry: Entry[String, String] => entry.getKey -> entry.getValue }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:45,代码来源:Netty4HeaderMap.scala


示例4: WorkflowDao

//设置package包名称以及导入依赖的类
// Copyright (C) 2017 Grier Forensics. All Rights Reserved.
package com.grierforensics.danesmimeatoolset.persist

import java.util
import java.util.Map.Entry

import com.grierforensics.danesmimeatoolset.model.Workflow


object WorkflowDao {
  val cacheSize = 2000
  val memoryWorkFlowCache = new util.LinkedHashMap[String, Workflow](cacheSize + 1, .75F, true) {
    override def removeEldestEntry(eldest: Entry[String, Workflow]): Boolean = {
      return size() >= cacheSize; //size exceeded the max allowed
    }
  }

  def persist(workflow: Workflow): Unit = {
    memoryWorkFlowCache.synchronized(memoryWorkFlowCache.put(workflow.id, workflow))
  }

  def fetch(id: String): Option[Workflow] = {
    memoryWorkFlowCache.synchronized(Option(memoryWorkFlowCache.get(id)))
  }
} 
开发者ID:grierforensics,项目名称:Great-DANE-Toolset,代码行数:26,代码来源:WorkflowDao.scala


示例5: FeeSettings

//设置package包名称以及导入依赖的类
package com.wavesplatform.settings

import java.util.Map.Entry
import scala.collection.JavaConverters._
import scala.util.Try
import com.google.common.base.CaseFormat
import com.typesafe.config.ConfigException.BadValue
import com.typesafe.config.{Config, ConfigValue}
import scorex.transaction.TransactionParser.TransactionType

case class FeeSettings(asset: String, fee: Long)

case class FeesSettings(fees: Map[Int, List[FeeSettings]])

object FeesSettings {
  val configPath: String = "waves.fees"

  private val converter = CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.UPPER_CAMEL)
  private def toTxType(key: String): TransactionType.Value =
    TransactionType.withName(s"${converter.convert(key)}Transaction")

  def fromConfig(config: Config): FeesSettings = {
    val feesEntries = config.entrySet().asScala.filter(_.getKey startsWith configPath)
    val fees = feesEntries.foldLeft(Map[Int, List[FeeSettings]]()) { (map, e) =>
      val p = toFeeSettings(e)
      map.updated(p._1, map.getOrElse(p._1, List()) :+ p._2)
    }

    FeesSettings(fees)
  }

  private def toFeeSettings(e: Entry[String, ConfigValue]): (Int, FeeSettings) = {
    val s = e.getKey.replace(s"$configPath.", "").trim
    val parts = s.split("\\.", 2)
    val (transactionTypeName, asset) = (parts(0), parts(1))
    val transactionType = toTxType(transactionTypeName).id

    val feeString = e.getValue.render
    val triedFee = Try(feeString.toLong)

    if (triedFee.isFailure) throw new BadValue(e.getKey, s"Failed to convert $feeString to long value", triedFee.failed.get)

    transactionType -> FeeSettings(asset, triedFee.get)
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:46,代码来源:FeesSettings.scala


示例6: LruCache

//设置package包名称以及导入依赖的类
package score.discord.generalbot.collections

import java.util
import java.util.Map.Entry

object LruCache {
  def empty[K, V](maxCapacity: Int, initialCapacity: Option[Int] = None, loadFactor: Float = 0.75f) =
    new LruCache[K, V](maxCapacity, initialCapacity, loadFactor)
}

class LruCache[K, V](val maxCapacity: Int, initialCapacity: Option[Int] = None, loadFactor: Float = 0.75f)
  extends Cache[K, V] {
  // Backing LinkedHashMap which discards at a certain capacity
  // "true" for accessOrder makes it reorder nodes on access to function as a LRU cache
  private[this] val backing = new util.LinkedHashMap[K, V](initialCapacity.getOrElse(64 min maxCapacity), loadFactor, true) {
    override def removeEldestEntry(entry: Entry[K, V]) = size > maxCapacity
  }

  def apply(key: K): Option[V] = Option(backing.get(key))

  def invalidate(key: K) {
    backing.remove(key)
  }

  def update(key: K, value: V) {
    backing.put(key, value)
  }
} 
开发者ID:ScoreUnder,项目名称:canti-bot,代码行数:29,代码来源:LruCache.scala


示例7: JtConfig

//设置package包名称以及导入依赖的类
package com.github.jt.config

import java.util.Map.Entry

import com.typesafe.config.{ConfigValue, Config, ConfigFactory}


object JtConfig {
  private val appConf = ConfigFactory.load()
  private val refConf = ConfigFactory.defaultReference()
  val config = appConf.withFallback(refConf).resolve()

  def checkValid(config: Config, pathPrefix: String): Unit = {
    config.checkValid(refConf, pathPrefix)
    val configKeys = getConfigKeys(config, pathPrefix)
    val refKeys = getConfigKeys(refConf, pathPrefix)
    val keysNotInRef = configKeys.diff(refKeys)
    if (keysNotInRef.nonEmpty) throw new IllegalArgumentException(s"Unknown config keys: ${keysNotInRef.mkString(", ")}")
  }

  private def getConfigKeys(config: Config, pathPrefix: String): Set[String] = {
    val es = config.entrySet()
    val kvArray: Array[Entry[String, ConfigValue]] = es.toArray(new Array(es.size))
    kvArray.map(_.getKey).filter(_.startsWith(pathPrefix)).toSet
  }

} 
开发者ID:joeytsai,项目名称:mysql-starter,代码行数:28,代码来源:JtConfig.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Provides类代码示例发布时间:2022-05-23
下一篇:
Scala ImageIO类代码示例发布时间: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