当前位置: 首页>>代码示例>>Scala>>正文


Scala ClassUtils类代码示例

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


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

示例1: ClassOps

//设置package包名称以及导入依赖的类
package com.github.stonexx.scala.util

import java.lang.annotation.Annotation
import java.net.URI
import java.util.{Date, Locale}

import org.apache.commons.lang3.ClassUtils

import scala.reflect.ClassTag

final class ClassOps[T](val self: Class[T]) extends AnyVal {
  import cls._

  def isSimpleType: Boolean = ClassUtils.isPrimitiveOrWrapper(self) ||
    classOf[CharSequence].isAssignableFrom(self) ||
    classOf[Number].isAssignableFrom(self) ||
    classOf[Date].isAssignableFrom(self) ||
    classOf[URI] == self ||
    classOf[Locale] == self ||
    classOf[Class[_]] == self ||
    self.isEnum

  def findAnnotation[A <: Annotation : ClassTag](annotationClass: Class[A]): Option[A] =
    Option(self getAnnotation annotationClass).orElse {
      self.getInterfaces.find(_ isAnnotationPresent annotationClass).flatMap(_.findAnnotation[A])
    }.orElse {
      if (classOf[Annotation] isAssignableFrom self) None
      else self.getAnnotations.map(_.annotationType).find(_ isAnnotationPresent annotationClass).flatMap(_.findAnnotation[A])
    }.orElse {
      Option(self.getSuperclass).filter(_ != classOf[Object]).flatMap(_.findAnnotation[A])
    }

  @inline
  def findAnnotation[A <: Annotation](implicit atag: ClassTag[A]): Option[A] =
    findAnnotation(atag.runtimeClass.asInstanceOf[Class[A]])
}

trait ToClassOps {
  implicit def toClassOps[T](x: Class[T]): ClassOps[T] = new ClassOps(x)
} 
开发者ID:stonexx,项目名称:utils,代码行数:41,代码来源:ClassOps.scala

示例2: TupleRecordMarshaller

//设置package包名称以及导入依赖的类
package com.mnubo.flink.streaming.connectors

import org.apache.commons.lang3.ClassUtils
import org.apache.flink.api.common.ExecutionConfig
import org.apache.flink.api.java.typeutils.TupleTypeInfoBase
import org.apache.flink.api.java.typeutils.runtime.TupleSerializerBase

@SerialVersionUID(1L)
class TupleRecordMarshaller[T](typeInfo: TupleTypeInfoBase[T]) extends RecordMarshaller[T] {
  private val serializer = typeInfo
    .createSerializer(new ExecutionConfig)
    .asInstanceOf[TupleSerializerBase[T]]

  override def typeInformation =
    typeInfo

  override def configureFields(types: Seq[MarshallerFieldDescriptor]) = {
    require(
      typeInfo.getArity == types.length,
      s"The number of fields selected in the tuple of type ${typeInfo.getTypeClass.getName} (${typeInfo.getArity}) does not match the number of fields returned by the Dataset (${types.size})"
    )

    (0 until typeInfo.getArity)
      .foreach { i =>
        val recordFieldClass = typeInfo.getTypeAt(i).getTypeClass
        require(
          ClassUtils.isAssignable(
            recordFieldClass,
            types(i).fieldClass
          ),
          s"Tuple field $i of type ${recordFieldClass.getName} is not assignable from DataSet field $i of type ${types(i).fieldClass.getName}"
        )
      }
  }

  override def createOrReuseInstance(fields: Seq[AnyRef], reuse: T): T =
    serializer.createOrReuseInstance(fields.toArray, reuse)
} 
开发者ID:mnubo,项目名称:flink-elasticsearch-source-connector,代码行数:39,代码来源:TupleRecordMarshaller.scala


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