fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. System.out.println(Rara.getValue(Arrays.asList("MGST", "PHYS")));
  14. // Optional[MAG_STRIPE_MANUAL]
  15.  
  16. System.out.println(Rara.getValue(Arrays.asList("MGST")));
  17. // Optional[MAG_STRIPE_ONLY]
  18.  
  19. }
  20. }
  21.  
  22. // From this Stack Overflow answer:
  23. // https://stackoverflow.com/a/70115626/642706
  24. enum Rara {
  25. MAG_STRIPE_ONLY("MGST"),
  26. MAG_STRIPE_MANUAL("MGST", "PHYS"),
  27. MAG_STRIPE_MANUAL_CHIP("MGST", "PHYS", "CICC"),
  28. BARCODE("BRCD");
  29.  
  30. Rara(String... codes) {
  31. this.codes = List.of(codes);
  32. }
  33.  
  34. private List<String> codes;
  35.  
  36. public static Optional<Rara> getValue(List<String> values){
  37. return Arrays.stream(values())
  38. .filter(rara -> rara.codes.containsAll(values))
  39. .findFirst();
  40. }
  41.  
  42. }
  43.  
Success #stdin #stdout 0.11s 48980KB
stdin
Standard input is empty
stdout
Optional[MAG_STRIPE_MANUAL]
Optional[MAG_STRIPE_ONLY]