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

org.jetbrains.kotlin.gradle.plugin.statistics.NonSynchronizedMetricsContainer.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.gradle.plugin.statistics

import org.jetbrains.kotlin.statistics.metrics.*
import java.io.Serializable
import kotlin.collections.HashMap

class NonSynchronizedMetricsContainer : StatisticsValuesConsumer, Serializable {
    data class MetricDescriptor>(val name: T, val subprojectName: String?) : Comparable> {
        override fun compareTo(other: MetricDescriptor): Int {
            val compareNames = name.compareTo(other.name)
            return when {
                compareNames != 0 -> compareNames
                subprojectName == other.subprojectName -> 0
                else -> (subprojectName ?: "").compareTo(other.subprojectName ?: "")
            }
        }
    }

    private val numericalMetrics = HashMap, IMetricContainer>()

    private val booleanMetrics = HashMap, IMetricContainer>()

    private val stringMetrics = HashMap, IMetricContainer>()

    override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?, weight: Long?): Boolean {
        booleanMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
        return true
    }

    override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?, weight: Long?): Boolean {
        numericalMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
        return true
    }

    override fun report(metric: StringMetrics, value: String, subprojectName: String?, weight: Long?): Boolean {
        stringMetrics.getOrPut(MetricDescriptor(metric, subprojectName)) { metric.type.newMetricContainer() }.addValue(value, weight)
        return true
    }

    fun sendToConsumer(metricConsumer: StatisticsValuesConsumer) {
        booleanMetrics.forEach { metricConsumer.report(it.key.name, it.value.getValue()!!, it.key.subprojectName) }
        numericalMetrics.forEach { metricConsumer.report(it.key.name, it.value.getValue()!!, it.key.subprojectName) }
        stringMetrics.forEach { metricConsumer.report(it.key.name, it.value.getValue()!!, it.key.subprojectName) }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy