Add some comments

This commit is contained in:
kageru 2020-07-05 00:27:39 +02:00
parent ff16085c59
commit d0dc275914
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 9 additions and 8 deletions

View File

@ -44,6 +44,7 @@ public class Dao {
return "Cleared list of user “%s“".formatted(id);
}
// The .exists() check is necessary because smembers throws an exception instead of returning null or an empty set.
private Option<HashSet<String>> getSet(String key) {
return withRedis(redis ->
redis.exists(key)

View File

@ -98,20 +98,20 @@ public class Nouritsu extends NanoHTTPD {
.fold(Function.identity(), Resp.OK);
}
// Return a Tuple2 containing the values of two eithers if both were Either.Right
private static <L, R1, R2> Either<L, Tuple2<R1, R2>> zip(Either<L, R1> first, Either<L, R2> second) {
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
}
private static String sortBySection(HashSet<ShoppingItem> items, Store store) {
var itemsBySection = items.groupBy(ShoppingItem::section);
var sorted = store.sections().flatMap(s -> itemsBySection.get(s).getOrElse(HashSet.empty()));
var rest = items.removeAll(sorted);
var sortedString = sorted.map(ShoppingItem::name).mkString(", ");
var formattedItems = sorted.map(ShoppingItem::name).mkString(", ");
if (rest.isEmpty()) {
return sortedString;
return formattedItems;
}
return sortedString + rest.mkString("\nItems not available or not classified in this store: ", ", ", "");
}
// Return a Tuple2 containing the values of two eithers if both were Either.Right
private static <L, R1, R2> Either<L, Tuple2<R1, R2>> zip(Either<L, R1> first, Either<L, R2> second) {
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
return formattedItems + rest.mkString("\nItems not available or not classified in this store: ", ", ", "");
}
private static Resp addToList(Map<String, String> params, Dao dao) {