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

kshark.MetadataExtractor.kt Maven / Gradle / Ivy

package kshark

/**
 * Extracts metadata from a hprof to be reported in [HeapAnalysisSuccess.metadata].
 *
 * This is a functional interface with which you can create a [MetadataExtractor] from a lambda.
 */
fun interface MetadataExtractor {
  fun extractMetadata(graph: HeapGraph): Map

  companion object {

    /**
     * A no-op [MetadataExtractor]
     */
    val NO_OP = MetadataExtractor { emptyMap() }

    /**
     * Utility function to create a [MetadataExtractor] from the passed in [block] lambda instead of
     * using the anonymous `object : MetadataExtractor` syntax.
     *
     * Usage:
     *
     * ```kotlin
     * val inspector = MetadataExtractor { graph ->
     *
     * }
     * ```
     */
    inline operator fun invoke(crossinline block: (HeapGraph) -> Map): MetadataExtractor =
      object : MetadataExtractor {
        override fun extractMetadata(graph: HeapGraph): Map = block(graph)
      }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy