1 /*
2  * Copyright (C) 2020 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 android.content.pm.parsing.result;
18 
19 import android.annotation.Nullable;
20 
21 /**
22  * The output side of {@link ParseInput}, which must result from a method call on
23  * {@link ParseInput}.
24  *
25  * When using this class, keep in mind that all {@link ParseInput}s and {@link ParseResult}s
26  * are the exact same object, scoped per thread, thrown around and casted for type safety.
27  *
28  * @hide
29  */
30 public interface ParseResult<ResultType> {
31 
32     /**
33      * Returns true if the result is not an error and thus contains a valid object.
34      *
35      * For backwards-compat reasons, it's possible to have a successful result with a null
36      * result object, depending on the behavior of the parsing method.
37      *
38      * It is expected that every method calls this to check for an error state to bubble up
39      * the error to its parent method after every parse method call.
40      *
41      * It is not always necessary to check this, as it is valid to return any ParseResult from
42      * a method so long as the type matches <b>without casting it</b>.
43      *
44      * The infrastructure is set up such that as long as a result is the proper type and
45      * the right side of success vs. error, it can be bubble up through all its parent methods.
46      */
isSuccess()47     boolean isSuccess();
48 
49     /**
50      * Opposite of {@link #isSuccess()} for readability.
51      */
isError()52     boolean isError();
53 
getResult()54     ResultType getResult();
55 
getErrorCode()56     int getErrorCode();
57 
58     @Nullable
getErrorMessage()59     String getErrorMessage();
60 
61     @Nullable
getException()62     Exception getException();
63 }
64