1 package io.github.robertograham.rleparser.domain.enumeration;
 2 
 3 import java.util.EnumSet;
 4 import java.util.stream.Collectors;
 5 
 6 public enum Status {
 7 
 8     ALIVE("o"),
 9     DEAD("b"),
10     LINE_END("$");
11 
12     private final String code;
13 
14     Status(String code) {
15         this.code = code;
16     }
17 
18     public static Status fromCode(String statusCode) {
19         return EnumSet.allOf(Status.class).stream()
20                 .filter(status -> status.code.equals(statusCode))
21                 .findFirst()
22                 .orElseThrow(() -> new IllegalArgumentException("Status code '" + statusCode + "' not found in [" + EnumSet.allOf(Status.class).stream().map(Status::getCode).collect(Collectors.joining(",")) + "]"));
23     }
24 
25     public String getCode() {
26         return code;
27     }
28 }