1 /*
2  * Copyright (C) 2022 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 com.android.libraries.pcc.chronicle.api.operation
18 
19 /** Representation of the result of an [Operation] as an action to be performed by the caller. */
20 sealed class Action<B> {
21   /**
22    * An [Operation] which returns [Update] is requesting the caller to use the [newValue] in place
23    * the input to the [Operation].
24    *
25    * TODO(b/205183415): Consider using an object pool to help reduce the number of allocations
26    * incurred when Update results are used.
27    */
28   data class Update<B>(val newValue: B) : Action<B>()
29 
30   /**
31    * An [Operation] which returns [OmitFromRoot] would like the caller to remove the entity from
32    * within which the [OmitFromRoot] was returned from the highest possible level of nesting.
33    */
34   object OmitFromRoot : Action<Nothing>()
35 
36   /**
37    * An [Operation] which returns [OmitFromParent] would like the caller to remove the entity from
38    * within which the [OmitFromParent] was returned from the nearest collection containing that
39    * entity.
40    */
41   object OmitFromParent : Action<Nothing>()
42 
43   /**
44    * An [Operation] which returns [Throw] would like the caller to throw the [exception] on its
45    * behalf.
46    */
47   data class Throw(val exception: Throwable) : Action<Nothing>()
48 }
49