MCPcopy
hub / github.com/google/dagger / Produced

Class Produced

dagger-producers/main/java/dagger/producers/Produced.java:47–153  ·  view source on GitHub ↗

An interface that represents the result of a plain Producer production of type T, or an exception that was thrown during that production. For any type T that can be injected, you can also inject Produced , which enables handling of any exceptions that were thrown dur

Source from the content-addressed store, hash-verified

45 * @since 2.0
46 */
47@Beta
48@CheckReturnValue
49public abstract class Produced<T> {
50 /**
51 * Returns the result of a production.
52 *
53 * @throws ExecutionException if the production threw an exception
54 */
55 public abstract T get() throws ExecutionException;
56
57 /**
58 * Two {@code Produced} objects compare equal if both are successful with equal values, or both
59 * are failed with equal exceptions.
60 */
61 @Override
62 public abstract boolean equals(Object o);
63
64 /** Returns an appropriate hash code to match {@link #equals(Object)}. */
65 @Override
66 public abstract int hashCode();
67
68 /** Returns a successful {@code Produced}, whose {@link #get} will return the given value. */
69 public static <T> Produced<T> successful(@NullableDecl T value) {
70 return new Successful<T>(value);
71 }
72
73 /**
74 * Returns a failed {@code Produced}, whose {@link #get} will throw an
75 * {@code ExecutionException} with the given cause.
76 */
77 public static <T> Produced<T> failed(Throwable throwable) {
78 return new Failed<T>(checkNotNull(throwable));
79 }
80
81 private static final class Successful<T> extends Produced<T> {
82 @NullableDecl private final T value;
83
84 private Successful(@NullableDecl T value) {
85 this.value = value;
86 }
87
88 @Override
89 @NullableDecl
90 public T get() {
91 return value;
92 }
93
94 @Override
95 public boolean equals(Object o) {
96 if (o == this) {
97 return true;
98 } else if (o instanceof Successful) {
99 Successful<?> that = (Successful<?>) o;
100 return Objects.equal(this.value, that.value);
101 } else {
102 return false;
103 }
104 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected