make vars final
This commit is contained in:
parent
d0dc275914
commit
8c9348700a
@ -87,16 +87,13 @@ public class Dao {
|
|||||||
|
|
||||||
public String addStore(Store store) {
|
public String addStore(Store store) {
|
||||||
// just overwrite it if we already know that store
|
// just overwrite it if we already know that store
|
||||||
withRedis(redis -> {
|
withRedis(redis ->
|
||||||
redis.del(STORE_PREFIX + store.name());
|
redis.del(STORE_PREFIX + store.name()) + // <- this plus doesn’t actually add anything.
|
||||||
|
// It just allows us to do both steps in one statement in the lambda body.
|
||||||
redis.rpush(
|
redis.rpush(
|
||||||
STORE_PREFIX + store.name(),
|
STORE_PREFIX + store.name(),
|
||||||
store.sections().map(Section::name).toJavaArray(String[]::new)
|
store.sections().map(Section::name).toJavaArray(String[]::new)
|
||||||
);
|
)
|
||||||
// There needs to be some kind of return type unless I make a second util function with Consumer<Jedis>.
|
|
||||||
// Why doesn’t Java just have a `Unit` type?
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return "Registered new store “%s” with the sections [%s]".formatted(store.name(), store.sections());
|
return "Registered new store “%s” with the sections [%s]".formatted(store.name(), store.sections());
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class Nouritsu extends NanoHTTPD {
|
|||||||
|
|
||||||
private static Resp processRequest(IHTTPSession session, Dao dao) {
|
private static Resp processRequest(IHTTPSession session, Dao dao) {
|
||||||
// Type inference can’t handle this :feelsBadMan:
|
// Type inference can’t handle this :feelsBadMan:
|
||||||
BiFunction<Map<String, String>, Dao, Resp> handler =
|
final BiFunction<Map<String, String>, Dao, Resp> handler =
|
||||||
switch (session.getUri().replaceAll("/", "").toLowerCase()) {
|
switch (session.getUri().replaceAll("/", "").toLowerCase()) {
|
||||||
case "addstore" -> Nouritsu::addStore;
|
case "addstore" -> Nouritsu::addStore;
|
||||||
case "additem" -> Nouritsu::addItem;
|
case "additem" -> Nouritsu::addItem;
|
||||||
@ -103,11 +103,14 @@ public class Nouritsu extends NanoHTTPD {
|
|||||||
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
|
return first.flatMap(f -> second.map(s -> Tuple.of(f, s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This kind of breaks the style,
|
||||||
|
// but I can’t come up with a more elegant solution,
|
||||||
|
// so lots of locals it is.
|
||||||
private static String sortBySection(HashSet<ShoppingItem> items, Store store) {
|
private static String sortBySection(HashSet<ShoppingItem> items, Store store) {
|
||||||
var itemsBySection = items.groupBy(ShoppingItem::section);
|
final var itemsBySection = items.groupBy(ShoppingItem::section);
|
||||||
var sorted = store.sections().flatMap(s -> itemsBySection.get(s).getOrElse(HashSet.empty()));
|
final var sorted = store.sections().flatMap(s -> itemsBySection.get(s).getOrElse(HashSet.empty()));
|
||||||
var rest = items.removeAll(sorted);
|
final var rest = items.removeAll(sorted);
|
||||||
var formattedItems = sorted.map(ShoppingItem::name).mkString(", ");
|
final var formattedItems = sorted.map(ShoppingItem::name).mkString(", ");
|
||||||
if (rest.isEmpty()) {
|
if (rest.isEmpty()) {
|
||||||
return formattedItems;
|
return formattedItems;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user