All Downloads are FREE. Search and download functionalities are using the official Maven repository.

epic.models.ModelSelector.scala Maven / Gradle / Ivy

The newest version!
package epic.models

import scala.collection.JavaConverters._
import java.util.ServiceLoader
import scala.reflect.ClassTag

/**
 * TODO
 *
 * @author dlwh
 **/
trait ModelSelector[+T, Loader <: ModelLoader[T]] {

  protected def classLoader = this.getClass.getClassLoader
  protected def manifest: ClassTag[Loader]

  private lazy val serviceLoader = ServiceLoader.load(manifest.runtimeClass.asInstanceOf[Class[Loader]], classLoader)

  def findModel(features: String*):Option[Loader] = {
    findModel{x => lazy val a = x.capabilities.toSet; features.forall(a)}
  }

  def findModel(filter: Loader=>Boolean) = serviceLoader.synchronized {
    serviceLoader.asScala.find(filter)
  }


}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy