1 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file 2 // for details. All rights reserved. Use of this source code is governed by a 3 // BSD-style license that can be found in the LICENSE file. 4 package switchmaps; 5 6 public class Switches { 7 main(String... args)8 public static void main(String... args) { 9 for (Days value : Days.values()) { 10 switchWithDefault(value); 11 switchFull(value); 12 } 13 for (Colors color : Colors.values()) { 14 switchOnColors(color); 15 } 16 } 17 switchOnColors(Colors color)18 private static void switchOnColors(Colors color) { 19 System.out.println(color.toString()); 20 switch (color) { 21 case GRAY: 22 System.out.println("not really"); 23 break; 24 case GREEN: 25 System.out.println("sooo green"); 26 break; 27 default: 28 System.out.println("colorful"); 29 } 30 } 31 switchWithDefault(Days day)32 private static void switchWithDefault(Days day) { 33 switch (day) { 34 case WEDNESDAY: 35 case FRIDAY: 36 System.out.println("3 or 5"); 37 break; 38 case SUNDAY: 39 System.out.println("7"); 40 break; 41 default: 42 System.out.println("other"); 43 } 44 } 45 switchFull(Days day)46 private static void switchFull(Days day) { 47 switch (day) { 48 case MONDAY: 49 case WEDNESDAY: 50 case THURSDAY: 51 System.out.println("1, 3 or 4"); 52 case TUESDAY: 53 case FRIDAY: 54 System.out.println("2 or 5"); 55 break; 56 case SUNDAY: 57 System.out.println("7"); 58 break; 59 case SATURDAY: 60 System.out.println("6"); 61 break; 62 default: 63 System.out.println("other"); 64 } 65 } 66 } 67