Skip to content

Commit 2a90300

Browse files
committed
refactored AggregatorProvider back
1 parent 751321e commit 2a90300

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators/Aggregator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal class Aggregator<in Value : Any, out Return : Any?>(
7878
aggregationHandler: AggregatorAggregationHandler<Value, Return>,
7979
inputHandler: AggregatorInputHandler<Value, Return>,
8080
multipleColumnsHandler: AggregatorMultipleColumnsHandler<Value, Return>,
81-
): AggregatorProvider<Aggregator<Value, Return>> =
81+
): AggregatorProvider<Value, Return> =
8282
AggregatorProvider { name ->
8383
Aggregator(
8484
aggregationHandler = aggregationHandler,

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators/AggregatorOptionSwitch.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ package org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators
77
* @see AggregatorOptionSwitch2
88
*/
99
@PublishedApi
10-
internal class AggregatorOptionSwitch1<in Param1, out AggregatorType : Aggregator<*, *>>(
10+
internal class AggregatorOptionSwitch1<in Param1, in Value : Any, out Return : Any?>(
1111
val name: String,
12-
val getAggregator: (param1: Param1) -> AggregatorProvider<AggregatorType>,
12+
val getAggregator: (param1: Param1) -> AggregatorProvider<Value, Return>,
1313
) {
1414

15-
private val cache: MutableMap<Param1, AggregatorType> = mutableMapOf()
15+
private val cache: MutableMap<Param1, Aggregator<Value, Return>> = mutableMapOf()
1616

17-
operator fun invoke(param1: Param1): AggregatorType =
17+
operator fun invoke(param1: Param1): Aggregator<Value, Return> =
1818
cache.getOrPut(param1) {
1919
getAggregator(param1).create(name)
2020
}
@@ -31,8 +31,8 @@ internal class AggregatorOptionSwitch1<in Param1, out AggregatorType : Aggregato
3131
* MyAggregator.Factory(param1)
3232
* }
3333
*/
34-
fun <Param1, AggregatorType : Aggregator<*, *>> Factory(
35-
getAggregator: (param1: Param1) -> AggregatorProvider<AggregatorType>,
34+
fun <Param1, Value : Any, Return : Any?> Factory(
35+
getAggregator: (param1: Param1) -> AggregatorProvider<Value, Return>,
3636
) = Provider { name -> AggregatorOptionSwitch1(name, getAggregator) }
3737
}
3838
}
@@ -44,14 +44,14 @@ internal class AggregatorOptionSwitch1<in Param1, out AggregatorType : Aggregato
4444
* @see AggregatorOptionSwitch1
4545
*/
4646
@PublishedApi
47-
internal class AggregatorOptionSwitch2<in Param1, in Param2, out AggregatorType : Aggregator<*, *>>(
47+
internal class AggregatorOptionSwitch2<in Param1, in Param2, in Value : Any, out Return : Any?>(
4848
val name: String,
49-
val getAggregator: (param1: Param1, param2: Param2) -> AggregatorProvider<AggregatorType>,
49+
val getAggregator: (param1: Param1, param2: Param2) -> AggregatorProvider<Value, Return>,
5050
) {
5151

52-
private val cache: MutableMap<Pair<Param1, Param2>, AggregatorType> = mutableMapOf()
52+
private val cache: MutableMap<Pair<Param1, Param2>, Aggregator<Value, Return>> = mutableMapOf()
5353

54-
operator fun invoke(param1: Param1, param2: Param2): AggregatorType =
54+
operator fun invoke(param1: Param1, param2: Param2): Aggregator<Value, Return> =
5555
cache.getOrPut(param1 to param2) {
5656
getAggregator(param1, param2).create(name)
5757
}
@@ -68,8 +68,8 @@ internal class AggregatorOptionSwitch2<in Param1, in Param2, out AggregatorType
6868
* MyAggregator.Factory(param1, param2)
6969
* }
7070
*/
71-
fun <Param1, Param2, AggregatorType : Aggregator<*, *>> Factory(
72-
getAggregator: (param1: Param1, param2: Param2) -> AggregatorProvider<AggregatorType>,
71+
fun <Param1, Param2, Value : Any, Return : Any?> Factory(
72+
getAggregator: (param1: Param1, param2: Param2) -> AggregatorProvider<Value, Return>,
7373
) = Provider { name -> AggregatorOptionSwitch2(name, getAggregator) }
7474
}
7575
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators/AggregatorProvider.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ internal operator fun <T> Provider<T>.getValue(obj: Any?, property: KProperty<*>
2424
* ```kt
2525
* val myAggregator by MyAggregator.Factory
2626
* ```
27-
*
28-
* TODO change back to AggregatorProvider<Value, Return>
2927
*/
30-
internal fun interface AggregatorProvider<out AggregatorType : Aggregator<*, *>> : Provider<AggregatorType>
28+
internal fun interface AggregatorProvider<in Value : Any, out Return : Any?> : Provider<Aggregator<Value, Return>>

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/aggregators/Aggregators.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ internal object Aggregators {
3030
private fun <Value : Return & Any, Return : Any?> twoStepSelecting(
3131
reducer: Reducer<Value, Return>,
3232
indexOfResult: IndexOfResult<Value>,
33-
): AggregatorProvider<Aggregator<Value, Return>> =
34-
Aggregator(
35-
aggregationHandler = SelectingAggregationHandler(reducer, indexOfResult, preserveReturnTypeNullIfEmpty),
36-
inputHandler = AnyInputHandler(),
37-
multipleColumnsHandler = TwoStepMultipleColumnsHandler(),
38-
)
33+
) = Aggregator(
34+
aggregationHandler = SelectingAggregationHandler(reducer, indexOfResult, preserveReturnTypeNullIfEmpty),
35+
inputHandler = AnyInputHandler(),
36+
multipleColumnsHandler = TwoStepMultipleColumnsHandler(),
37+
)
3938

4039
/**
4140
* Factory for a simple aggregator that changes the type of the input values.
@@ -95,13 +94,13 @@ internal object Aggregators {
9594
)
9695

9796
/** @include [AggregatorOptionSwitch1] */
98-
private fun <Param1, AggregatorType : Aggregator<*, *>> withOneOption(
99-
getAggregator: (Param1) -> AggregatorProvider<AggregatorType>,
97+
private fun <Param1, Value : Any, Return : Any?> withOneOption(
98+
getAggregator: (Param1) -> AggregatorProvider<Value, Return>,
10099
) = AggregatorOptionSwitch1.Factory(getAggregator)
101100

102101
/** @include [AggregatorOptionSwitch2] */
103-
private fun <Param1, Param2, AggregatorType : Aggregator<*, *>> withTwoOptions(
104-
getAggregator: (Param1, Param2) -> AggregatorProvider<AggregatorType>,
102+
private fun <Param1, Param2, Value : Any, Return : Any?> withTwoOptions(
103+
getAggregator: (Param1, Param2) -> AggregatorProvider<Value, Return>,
105104
) = AggregatorOptionSwitch2.Factory(getAggregator)
106105

107106
// T: Comparable<T> -> T?

0 commit comments

Comments
 (0)