Skip to content

Commit b2f0b3f

Browse files
committed
GenericOptions
1 parent 9553abc commit b2f0b3f

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/PipelineTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.google.firebase.firestore.pipeline.Constant;
4949
import com.google.firebase.firestore.pipeline.Field;
5050
import com.google.firebase.firestore.pipeline.Function;
51+
import com.google.firebase.firestore.pipeline.GenericStage;
5152
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
5253
import java.util.Collections;
5354
import java.util.LinkedHashMap;
@@ -284,7 +285,7 @@ public void groupAndAccumulateResultsGeneric() {
284285
"aggregate",
285286
ImmutableMap.of("avgRating", AggregateExpr.avg("rating")),
286287
ImmutableMap.of("genre", Field.of("genre")))
287-
.genericStage("where", gt("avgRating", 4.3))
288+
.genericStage(GenericStage.of("where").withArguments(gt("avgRating", 4.3)))
288289
.genericStage("sort", Field.of("avgRating").descending())
289290
.execute();
290291
assertThat(waitFor(execute).getResults())

firebase-firestore/src/main/java/com/google/firebase/firestore/Pipeline.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ internal constructor(
9999
.addAllStages(stages.map { it.toProtoStage(userDataReader) })
100100
.build()
101101

102-
fun genericStage(name: String, vararg params: Any) =
103-
append(GenericStage(name, params.map(GenericArg::from)))
102+
fun genericStage(name: String, vararg arguments: Any): Pipeline =
103+
append(GenericStage(name, arguments.map(GenericArg::from)))
104+
105+
fun genericStage(stage: GenericStage): Pipeline = append(stage)
104106

105107
fun addFields(vararg fields: Selectable): Pipeline = append(AddFieldsStage(fields))
106108

firebase-firestore/src/main/java/com/google/firebase/firestore/pipeline/stage.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.google.firestore.v1.Pipeline
2222
import com.google.firestore.v1.Value
2323

2424
abstract class Stage
25-
private constructor(private val name: String, private val options: InternalOptions) {
25+
private constructor(protected val name: String, private val options: InternalOptions) {
2626
internal constructor(name: String) : this(name, InternalOptions.EMPTY)
2727
internal constructor(name: String, options: AbstractOptions<*>) : this(name, options.options)
2828
internal fun toProtoStage(userDataReader: UserDataReader): Pipeline.Stage {
@@ -35,10 +35,20 @@ private constructor(private val name: String, private val options: InternalOptio
3535
internal abstract fun args(userDataReader: UserDataReader): Sequence<Value>
3636
}
3737

38-
internal class GenericStage
39-
internal constructor(name: String, private val params: List<GenericArg>) : Stage(name) {
38+
class GenericStage
39+
private constructor(name: String, private val arguments: List<GenericArg>, private val options: GenericOptions) : Stage(name, options) {
40+
internal constructor(name: String, arguments: List<GenericArg>) : this(name, arguments, GenericOptions.DEFAULT)
41+
companion object {
42+
@JvmStatic
43+
fun of(name: String) = GenericStage(name, emptyList())
44+
}
45+
46+
fun withArguments(vararg arguments: Any): GenericStage = GenericStage(name, arguments.map(GenericArg::from), options)
47+
48+
fun withOptions(options: GenericOptions): GenericStage = GenericStage(name, arguments, options)
49+
4050
override fun args(userDataReader: UserDataReader): Sequence<Value> =
41-
params.asSequence().map { it.toProto(userDataReader) }
51+
arguments.asSequence().map { it.toProto(userDataReader) }
4252
}
4353

4454
internal sealed class GenericArg {
@@ -77,6 +87,14 @@ internal sealed class GenericArg {
7787
}
7888
}
7989

90+
class GenericOptions private constructor(options: InternalOptions) : AbstractOptions<GenericOptions>(options) {
91+
companion object {
92+
@JvmField
93+
val DEFAULT = GenericOptions(InternalOptions.EMPTY)
94+
}
95+
override fun self(options: InternalOptions) = GenericOptions(options)
96+
}
97+
8098
internal class DatabaseSource : Stage("database") {
8199
override fun args(userDataReader: UserDataReader): Sequence<Value> = emptySequence()
82100
}

0 commit comments

Comments
 (0)