MCPcopy Index your code
hub / github.com/graphql-java/graphql-java / Single

Class Single

src/main/java/graphql/execution/Async.java:122–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 private static class Single<T> implements CombinedBuilder<T> {
123
124 // avoiding array allocation as there is only 1 CF
125 private Object value;
126 private int ix;
127
128 @Override
129 public void add(CompletableFuture<T> completableFuture) {
130 this.value = completableFuture;
131 this.ix++;
132 }
133
134 @Override
135 public void addObject(Object object) {
136 this.value = object;
137 this.ix++;
138 }
139
140 @Override
141 public CompletableFuture<List<T>> await() {
142 commonSizeAssert();
143 if (value instanceof CompletableFuture) {
144 @SuppressWarnings("unchecked")
145 CompletableFuture<T> cf = (CompletableFuture<T>) value;
146 return cf.thenApply(Collections::singletonList);
147 }
148 //noinspection unchecked
149 return CompletableFuture.completedFuture(Collections.singletonList((T) value));
150 }
151
152 @Override
153 public Object awaitPolymorphic() {
154 commonSizeAssert();
155 if (value instanceof CompletableFuture) {
156 @SuppressWarnings("unchecked")
157 CompletableFuture<T> cf = (CompletableFuture<T>) value;
158 return cf.thenApply(Collections::singletonList);
159 }
160 //noinspection unchecked
161 return Collections.singletonList((T) value);
162 }
163
164 private void commonSizeAssert() {
165 Assert.assertTrue(ix == 1, () -> "expected size was " + 1 + " got " + ix);
166 }
167 }
168
169 private static class Many<T> implements CombinedBuilder<T> {
170

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…