Skip to content
Snippets Groups Projects
Commit 3d271a62 authored by Florian Meissner's avatar Florian Meissner
Browse files

initial commit; print works but is unelegant (switch from CompletableFuture to Stream)

parent 599c9562
Branches
No related tags found
No related merge requests found
......@@ -2,14 +2,17 @@ package ohm.softa.a11;
import ohm.softa.a11.openmensa.OpenMensaAPI;
import ohm.softa.a11.openmensa.OpenMensaAPIService;
import ohm.softa.a11.openmensa.model.Canteen;
import ohm.softa.a11.openmensa.model.PageInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* @author Peter Kurfer
......@@ -55,6 +58,26 @@ public class App {
* at first get a page without an index to be able to extract the required pagination information
* afterwards you can iterate the remaining pages
* keep in mind that you should await the process as the user has to select canteen with a specific id */
OpenMensaAPI api = OpenMensaAPIService.getInstance().getOpenMensaAPI();
var response = api.getCanteens();
try {
var pageInfo = PageInfo.extractFromResponse(response.get());
var firstCanteenPage = response.get().body();
var N = pageInfo.getTotalCountOfPages();
var canteens = IntStream.range(2, N).parallel()
.mapToObj((n) -> api.getCanteens(n).join())
.flatMap(Collection::stream)
.collect(Collectors.toList());
canteens.addAll(0, firstCanteenPage);
canteens.sort(Comparator.comparingInt(Canteen::getId));
//canteens = canteens.thenCombine(api.getCanteens(Integer.parseInt(pageN.get())), (l1, l2) -> Stream.concat(l1.parallelStream(), l2.parallelStream()))
canteens.forEach((c) -> System.out.println(c.toString()));
} catch (InterruptedException | ExecutionException | NumberFormatException e) {
e.printStackTrace();
System.out.println("WHYYYYYYYYYYy!!!!");
}
}
private static void printMeals() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment