本文整理汇总了Scala中java.util.Objects类的典型用法代码示例。如果您正苦于以下问题:Scala Objects类的具体用法?Scala Objects怎么用?Scala Objects使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Objects类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Subnet
//设置package包名称以及导入依赖的类
package com.github.shadowsocks.acl
import java.net.InetAddress
import java.util.Objects
import com.github.shadowsocks.utils.Utils
@throws[IllegalArgumentException]
class Subnet(val address: InetAddress, val prefixSize: Int) extends Comparable[Subnet] {
private def addressLength = address.getAddress.length << 3
if (prefixSize < 0 || prefixSize > addressLength) throw new IllegalArgumentException
override def toString: String =
if (prefixSize == addressLength) address.getHostAddress else address.getHostAddress + '/' + prefixSize
override def compareTo(that: Subnet): Int = {
val addrThis = address.getAddress
val addrThat = that.address.getAddress
var result = addrThis lengthCompare addrThat.length // IPv4 address goes first
if (result != 0) return result
for ((x, y) <- addrThis zip addrThat) {
result = (x & 0xFF) compare (y & 0xFF) // undo sign extension of signed byte
if (result != 0) return result
}
prefixSize compare that.prefixSize
}
override def equals(other: Any): Boolean = other match {
case that: Subnet => address == that.address && prefixSize == that.prefixSize
case _ => false
}
override def hashCode: Int = Objects.hash(address, prefixSize: Integer)
}
object Subnet {
@throws[IllegalArgumentException]
def fromString(value: String): Subnet = {
val parts = value.split("/")
val addr = Utils.parseNumericAddress(parts(0))
parts.length match {
case 1 => new Subnet(addr, addr.getAddress.length << 3)
case 2 => new Subnet(addr, parts(1).toInt)
case _ => throw new IllegalArgumentException()
}
}
}
开发者ID:likky,项目名称:shadowsocks_android_build,代码行数:48,代码来源:Subnet.scala
示例2: Date
//设置package包名称以及导入依赖的类
package com.nthportal.euler.util.calendar
import java.util.Objects
case class Date(month: Month, day: Int, dayOfWeek: DayOfWeek) {
Objects.requireNonNull(month)
Objects.requireNonNull(dayOfWeek)
if (day <= 0 || day > month.days) throw new IllegalArgumentException("Invalid day '" + day + "' for month: " + month)
def year: Int = month.year
def nextDay: Date = {
if (day == month.days) Date(month.nextMonth, 1, dayOfWeek.nextDay)
else Date(month, day + 1, dayOfWeek.nextDay)
}
override def toString: String = month + " " + day + ", " + dayOfWeek
}
开发者ID:NthPortal,项目名称:euler-n-scala,代码行数:19,代码来源:Date.scala
示例3: Candidate
//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.candidate
import java.util.{Locale, Objects}
import org.pdfextractor.db.domain.dictionary.PaymentFieldType
import scala.beans.BeanProperty
case class Candidate(@BeanProperty // for dependent RESTful API in Java
value: Any,
x: Integer,
y: Integer,
bold: Boolean,
height: Integer,
pageNo: Integer,
locale: Locale,
paymentFieldType: PaymentFieldType,
properties: Map[CandidateMetadata, Any])
extends Comparable[Candidate] {
Objects.requireNonNull(value)
override def compareTo(other: Candidate): Int = compare(this, other)
override def equals(other: Any): Boolean = {
other match {
case that: Candidate => this.value == that.value
case _ => false
}
}
override def hashCode(): Int = value.hashCode()
}
开发者ID:kveskimae,项目名称:pdfalg,代码行数:36,代码来源:Candidate.scala
示例4: TypeWrapper
//设置package包名称以及导入依赖的类
package com.avsystem.scex.util
import java.util.Objects
import java.{lang => jl, util => ju}
import scala.collection.mutable.ListBuffer
import scala.reflect.api.Universe
class TypeWrapper(universeWithTpe: (u.type, u.Type) forSome {val u: Universe}) {
private val u = universeWithTpe._1
private val tpe = universeWithTpe._2.asInstanceOf[u.Type]
import u._
private def getSymbols(tpe: Type): List[Symbol] = {
val b = new ListBuffer[Symbol]
def symbolsIn(tpe: Type): Unit = tpe match {
case SingleType(pre, sym) =>
b += sym
symbolsIn(pre)
case TypeRef(pre, sym, args) =>
b += sym
symbolsIn(pre)
args.foreach(symbolsIn)
case _ =>
b += tpe.typeSymbol
}
symbolsIn(tpe)
b.result()
}
private val symbols = getSymbols(tpe)
override def equals(other: Any) = other match {
case other: TypeWrapper =>
(u eq other.u) && symbols == other.symbols && tpe =:= other.tpe.asInstanceOf[Type]
case _ => false
}
override val hashCode = Objects.hash(u, symbols)
}
object TypeWrapper {
def apply(u: Universe)(tpe: u.Type) = new TypeWrapper((u, tpe): (u.type, u.Type))
}
开发者ID:AVSystem,项目名称:scex,代码行数:48,代码来源:TypeWrapper.scala
注:本文中的java.util.Objects类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论