1 /* 2 * Copyright 2024 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.pdf.service; 18 19 import androidx.annotation.RestrictTo; 20 import androidx.pdf.data.PdfStatus; 21 import androidx.pdf.util.Preconditions; 22 23 import org.jspecify.annotations.NonNull; 24 import org.jspecify.annotations.Nullable; 25 26 /** 27 * A struct that holds either a successfully loaded PdfDocument, or the reason why it failed. 28 */ 29 @RestrictTo(RestrictTo.Scope.LIBRARY) 30 public class LoadPdfResult { 31 32 private final PdfStatus mStatus; 33 private final @Nullable PdfDocument mPdfDocument; 34 LoadPdfResult(int status, @Nullable PdfDocument pdfDocument)35 public LoadPdfResult(int status, @Nullable PdfDocument pdfDocument) { 36 if (status == PdfStatus.LOADED.getNumber()) { 37 Preconditions.checkArgument(pdfDocument != null, "Missing pdfDocument"); 38 } else { 39 Preconditions.checkArgument(pdfDocument == null, 40 "Shouldn't construct " + "broken pdfDocument"); 41 } 42 this.mStatus = PdfStatus.values()[status]; 43 this.mPdfDocument = pdfDocument; 44 } 45 getStatus()46 public @NonNull PdfStatus getStatus() { 47 return mStatus; 48 } 49 getPdfDocument()50 public @Nullable PdfDocument getPdfDocument() { 51 return mPdfDocument; 52 } 53 isLoaded()54 public boolean isLoaded() { 55 return mStatus == PdfStatus.LOADED; 56 } 57 } 58