Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package androidx.appactions.interaction.capabilities.core |
| 18 | |
Dennis Tu | c3a7d2a | 2023-02-10 19:53:27 +0000 | [diff] [blame] | 19 | import java.util.Objects |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 20 | /** |
Jaaz Meribole | 9065d40 | 2023-03-31 13:28:38 -0700 | [diff] [blame] | 21 | * Class that represents the response after a Capability fulfills an action. |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 22 | */ |
Dennis Tu | c3a7d2a | 2023-02-10 19:53:27 +0000 | [diff] [blame] | 23 | class ExecutionResult<OutputT> internal constructor( |
Michael Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 24 | @get:JvmName("shouldStartDictation") |
| 25 | val shouldStartDictation: Boolean, |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 26 | val output: OutputT?, |
| 27 | ) { |
Dennis Tu | c3a7d2a | 2023-02-10 19:53:27 +0000 | [diff] [blame] | 28 | override fun toString() = |
Michael Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 29 | "ExecutionResult(shouldStartDictation=$shouldStartDictation,output=$output)" |
Dennis Tu | c3a7d2a | 2023-02-10 19:53:27 +0000 | [diff] [blame] | 30 | |
| 31 | override fun equals(other: Any?): Boolean { |
| 32 | return other is ExecutionResult<*> && output == other.output |
| 33 | } |
| 34 | |
Michael Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 35 | override fun hashCode() = Objects.hash(shouldStartDictation, output) |
Dennis Tu | c3a7d2a | 2023-02-10 19:53:27 +0000 | [diff] [blame] | 36 | |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Builder for ExecutionResult. |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 39 | */ |
| 40 | class Builder<OutputT> { |
Michael Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 41 | private var shouldStartDictation: Boolean = false |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 42 | private var output: OutputT? = null |
| 43 | |
| 44 | /** Sets whether or not this fulfillment should start dictation. */ |
| 45 | fun setStartDictation(startDictation: Boolean) = apply { |
Michael Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 46 | this.shouldStartDictation = startDictation |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 47 | } |
| 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 Kucharski | eebe936 | 2023-04-06 15:45:21 -0700 | [diff] [blame] | 55 | fun build() = ExecutionResult(shouldStartDictation, output) |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 56 | } |
Dennis Tu | f43d0b3 | 2023-02-10 01:22:50 +0000 | [diff] [blame] | 57 | } |