|
12 | 12 | import java.util.concurrent.ExecutionException; |
13 | 13 |
|
14 | 14 | public class ConversionResult { |
15 | | - private final CompletableFuture<ConversionResponse> responseFuture; |
| 15 | + private final ConversionResponse response; |
16 | 16 |
|
17 | | - public ConversionResult(CompletableFuture<ConversionResponse> responseFuture) { |
18 | | - this.responseFuture = responseFuture; |
| 17 | + public ConversionResult(ConversionResponse responseFuture) { |
| 18 | + this.response = responseFuture; |
19 | 19 | } |
20 | 20 |
|
21 | | - public CompletableFuture<Integer> fileCount() throws ExecutionException, InterruptedException { |
22 | | - return responseFuture.thenApplyAsync(r -> r.Files.length); |
| 21 | + public Integer fileCount() throws ExecutionException, InterruptedException { |
| 22 | + return response.Files.length; |
23 | 23 | } |
24 | 24 |
|
25 | | - public CompletableFuture<List<String>> urls() throws ExecutionException, InterruptedException { |
26 | | - return responseFuture.thenApplyAsync(r -> { |
27 | | - List<String> valueList = new ArrayList(); |
28 | | - for (ConversionResponseFile file: r.Files) valueList.add(file.Url); |
29 | | - return valueList; |
30 | | - }); |
| 25 | + public List<String> urls() { |
| 26 | + List<String> valueList = new ArrayList(); |
| 27 | + for (ConversionResponseFile file: response.Files) valueList.add(file.Url); |
| 28 | + return valueList; |
31 | 29 | } |
32 | 30 |
|
33 | | - public CompletableFuture<Integer> conversionCost() throws ExecutionException, InterruptedException { |
34 | | - return responseFuture.thenApplyAsync(r -> r.ConversionCost); |
| 31 | + public Integer conversionCost() throws ExecutionException, InterruptedException { |
| 32 | + return response.ConversionCost; |
35 | 33 | } |
36 | 34 |
|
37 | | - public CompletableFuture<ConversionResultFile> getFile(int index) { |
38 | | - return responseFuture.thenApplyAsync(r -> new ConversionResultFile(r.Files[index])); |
| 35 | + public ConversionResultFile getFile(int index) { |
| 36 | + return new ConversionResultFile(response.Files[index]); |
39 | 37 | } |
40 | 38 |
|
41 | | - public Path saveFile(Path file) throws ExecutionException, InterruptedException { |
42 | | - return getFile(0).thenCompose(f -> f.saveFile(file)).get(); |
| 39 | + public CompletableFuture<Path> saveFile(Path file) { |
| 40 | + return getFile(0).saveFile(file); |
43 | 41 | } |
44 | 42 |
|
45 | | - public List<Path> saveFiles(Path directory) throws ExecutionException, InterruptedException, NotDirectoryException { |
46 | | - if (!Files.isDirectory(directory)) throw new NotDirectoryException(directory.toString()); |
47 | | - List<Path> paths = new ArrayList<Path>(); |
48 | | - for (int i = 0; i < responseFuture.get().Files.length; i++) { |
49 | | - paths.add(getFile(i).thenCompose(f -> f.saveFile(directory)).get()); |
| 43 | + public List<CompletableFuture<Path>> saveFiles(Path directory) { |
| 44 | + if (!Files.isDirectory(directory)) throw new RuntimeException("Directory expected, but received: " + directory.toString()); |
| 45 | + List<CompletableFuture<Path>> paths = new ArrayList(); |
| 46 | + for (int i = 0; i < response.Files.length; i++) { |
| 47 | + paths.add(getFile(i).saveFile(directory)); |
50 | 48 | } |
51 | 49 | return paths; |
52 | 50 | } |
|
0 commit comments