30 lines
607 B
Java
30 lines
607 B
Java
package nouritsu.types;
|
|
|
|
import io.vavr.collection.Stream;
|
|
import io.vavr.control.Either;
|
|
|
|
public enum Section {
|
|
CANS,
|
|
FRUITS,
|
|
VEGETABLES,
|
|
PASTA,
|
|
RICE,
|
|
MEAT,
|
|
FISH,
|
|
DAIRY,
|
|
HYGIENE,
|
|
BEVERAGES;
|
|
|
|
public static Either<String, Section> tryParse(String catName) {
|
|
return Stream.of(Section.values())
|
|
.find(c -> c.name().equalsIgnoreCase(catName))
|
|
.toEither("Category “%s” not found".formatted(catName));
|
|
}
|
|
|
|
public static String valuesAsString() {
|
|
return Stream.of(Section.values())
|
|
.map(Section::name)
|
|
.mkString("\nValid values are: ", ", ", "");
|
|
}
|
|
}
|