blob: 33d22c608376021b1342c21c0e0e7e1bb1c07738 [file] [log] [blame]
Dennis Tuf43d0b32023-02-10 01:22:50 +00001/*
2 * Copyright 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.appactions.interaction.capabilities.core
18
Dennis Tuc3a7d2a2023-02-10 19:53:27 +000019import java.util.Objects
Dennis Tuf43d0b32023-02-10 01:22:50 +000020/**
Jaaz Meribole9065d402023-03-31 13:28:38 -070021 * Class that represents the response after a Capability fulfills an action.
Dennis Tuf43d0b32023-02-10 01:22:50 +000022 */
Dennis Tuc3a7d2a2023-02-10 19:53:27 +000023class ExecutionResult<OutputT> internal constructor(
Michael Kucharskieebe9362023-04-06 15:45:21 -070024 @get:JvmName("shouldStartDictation")
25 val shouldStartDictation: Boolean,
Dennis Tuf43d0b32023-02-10 01:22:50 +000026 val output: OutputT?,
27) {
Dennis Tuc3a7d2a2023-02-10 19:53:27 +000028 override fun toString() =
Michael Kucharskieebe9362023-04-06 15:45:21 -070029 "ExecutionResult(shouldStartDictation=$shouldStartDictation,output=$output)"
Dennis Tuc3a7d2a2023-02-10 19:53:27 +000030
31 override fun equals(other: Any?): Boolean {
32 return other is ExecutionResult<*> && output == other.output
33 }
34
Michael Kucharskieebe9362023-04-06 15:45:21 -070035 override fun hashCode() = Objects.hash(shouldStartDictation, output)
Dennis Tuc3a7d2a2023-02-10 19:53:27 +000036
Dennis Tuf43d0b32023-02-10 01:22:50 +000037 /**
38 * Builder for ExecutionResult.
Dennis Tuf43d0b32023-02-10 01:22:50 +000039 */
40 class Builder<OutputT> {
Michael Kucharskieebe9362023-04-06 15:45:21 -070041 private var shouldStartDictation: Boolean = false
Dennis Tuf43d0b32023-02-10 01:22:50 +000042 private var output: OutputT? = null
43
44 /** Sets whether or not this fulfillment should start dictation. */
45 fun setStartDictation(startDictation: Boolean) = apply {
Michael Kucharskieebe9362023-04-06 15:45:21 -070046 this.shouldStartDictation = startDictation
Dennis Tuf43d0b32023-02-10 01:22:50 +000047 }
48
49 /** Sets the execution output. */
50 fun setOutput(output: OutputT) = apply {
51 this.output = output
52 }
53
54 /** Builds and returns the ExecutionResult instance. */
Michael Kucharskieebe9362023-04-06 15:45:21 -070055 fun build() = ExecutionResult(shouldStartDictation, output)
Dennis Tuf43d0b32023-02-10 01:22:50 +000056 }
Dennis Tuf43d0b32023-02-10 01:22:50 +000057}