Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataFetchResult.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
20 
21 import java.util.function.Function;
22 
26 public final class DataFetchResult<R> {
27 
31  public enum ResultType {
32  SUCCESS, ERROR
33  }
34 
47  public static <I, O> DataFetchResult<O> getSubResult(DataFetchResult<I> inputResult, Function<I, O> getSubResult) {
48  if (inputResult == null) {
49  return null;
50  } else if (inputResult.getResultType() == ResultType.SUCCESS) {
51  O innerData = (inputResult.getData() == null) ? null : getSubResult.apply(inputResult.getData());
52  return DataFetchResult.getSuccessResult(innerData);
53  } else {
54  return DataFetchResult.getErrorResult(inputResult.getException());
55  }
56  }
57 
65  public static <R> DataFetchResult<R> getSuccessResult(R data) {
66  return new DataFetchResult<>(ResultType.SUCCESS, data, null);
67  }
68 
76  public static <R> DataFetchResult<R> getErrorResult(Throwable e) {
77  return new DataFetchResult<>(ResultType.ERROR, null, e);
78  }
79 
80  private final ResultType state;
81  private final R data;
82  private final Throwable exception;
83 
91  private DataFetchResult(ResultType state, R data, Throwable exception) {
92  this.state = state;
93  this.data = data;
94  this.exception = exception;
95  }
96 
101  return state;
102  }
103 
107  public R getData() {
108  return data;
109  }
110 
114  public Throwable getException() {
115  return exception;
116  }
117 }
static< I, O > DataFetchResult< O > getSubResult(DataFetchResult< I > inputResult, Function< I, O > getSubResult)
static< R > DataFetchResult< R > getErrorResult(Throwable e)
DataFetchResult(ResultType state, R data, Throwable exception)
static< R > DataFetchResult< R > getSuccessResult(R data)

Copyright © 2012-2022 Basis Technology. Generated on: Thu Dec 8 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.