java 7中java.util.function.Function的替代实现

时间:2017-06-09 04:22:07

标签: scala java-8 java-7

我正在尝试在jdk 1.7和scala 2.10下重建GeoMesa源代码。但它使用java 8中的新功能,如下面代码中的“java.util.function.Function”。有什么替代方法可以在java 8中替换这样的函数吗?

/**
    * Gets table names and converters for each table (e.g. index) that supports the sft\n
    *
    * @param sft simple feature type
    * @param ds data store
    * @param indices indices to write/delete
    * @return (table names, write converters, remove converters)
    */ 

def getTablesAndConverters[DS <: GeoMesaDataStore[DS, F, W], F<:WrappedFeature,W] (
      sft: SimpleFeatureType,
      ds: DS,
      indices: Option[Seq[GeoMesaFeatureIndex[DS, F, W]]] = None): (IndexedSeq[String], IndexedSeq[(F) => Seq[W]], IndexedSeq[(F) => Seq[W]]) = {

    val toWrite = indices.getOrElse(ds.manager.indices(sft, IndexMode.Write)).toIndexedSeq

    val key = s"${ds.config.catalog};${CacheKeyGenerator.cacheKey(sft)};${toWrite.map(_.identifier).mkString(",")}"
    val load = new java.util.function.Function[String, (IndexedSeq[String], IndexedSeq[(Any) => Seq[Any]], IndexedSeq[(Any) => Seq[Any]])] {
      override def apply(ignored: String): (IndexedSeq[String], IndexedSeq[(Any) => Seq[Any]], IndexedSeq[(Any) => Seq[Any]]) = {
        val tables = toWrite.map(_.getTableName(sft.getTypeName, ds))
        val writers = toWrite.map(_.writer(sft, ds))
        val removers = toWrite.map(_.remover(sft, ds))
        (tables, writers.asInstanceOf[IndexedSeq[(Any) => Seq[Any]]], removers.asInstanceOf[IndexedSeq[(Any) => Seq[Any]]])
      }
    }

    converterCache.get(key, load).asInstanceOf[(IndexedSeq[String], IndexedSeq[(F) => Seq[W]], IndexedSeq[(F) => Seq[W]])]
  }

0 个答案:

没有答案