package jdk.statement;

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * 
 * @since 2017-07-27
 * @author fixalot
 */
public class EnumTest {
	private static final Logger logger = LoggerFactory.getLogger(EnumTest.class);

	public static void main(String[] args) {
		System.out.println(Color.RED); // RED
		System.out.println(Color.RED.toString()); // RED
		System.out.println(Color.RED.name()); // RED

		// Display price of Winsap.
		System.out.println(Apple.A.getPrice());
		// Display all apples and prices.
		System.out.println("All apple prices:");
		for (Apple ele : Apple.values()) {
			System.out.println(ele + " costs " + ele.getPrice() + " cents.");
		}

		SystemDivision var1 = SystemDivision.BACK_OFFICE;
		SystemDivision var2 = SystemDivision.FRONT_OFFICE;

		System.out.println(var1); // BACK_OFFICE
		System.out.println(var2); // FRONT_OFFICE
		System.out.println(var2.name()); // FRONT_OFFICE
		System.out.println(var2.getOptionalField()); // front office system
	}

	@Test
	public void useSwitch() {
		String div = "back_office";
		switch (SystemDivision.valueOf(div.toUpperCase())) {
		case BACK_OFFICE:
			logger.debug("백");
			break;
		case FRONT_OFFICE:
			logger.debug("프론트");
			break;
		}
	}

	@Test
	public void fromString() {
		Class<Color> clazz = Color.class;
		String source = "red";
		Enum<Color> color = Enum.valueOf(clazz, source.trim().toUpperCase());
		Assert.assertEquals(Color.RED, color);
	}

	private enum SystemDivision {
		BACK_OFFICE, FRONT_OFFICE("front office system");

		private SystemDivision() {} // 기본 생성자

		private String optionalField;

		private SystemDivision(final String option) {
			this.optionalField = option;
		}

		public String getOptionalField() {
			return this.optionalField;
		}
	}

	private enum Apple {
		A(10), B(9), C(12), D(15), E(8);

		private int price; // price of each apple

		// Constructor
		private Apple(int p) {
			price = p;
		}

		public int getPrice() {
			return price;
		}
	}

	private enum Color {
		RED, BLUE, GREEN, YELLOW
	}
}
@@ -730,32 +730,28 @@
 %09%7D%0A%0A%09%09System
-Division
+Type
  var1 = Syst
@@ -752,24 +752,20 @@
 = System
-Division
+Type
 .BACK_OF
@@ -778,24 +778,20 @@
 %09%09System
-Division
+Type
  var2 = 
@@ -796,24 +796,20 @@
 = System
-Division
+Type
 .FRONT_O
@@ -1024,24 +1024,236 @@
  system%0A%09%7D%0A%0A
+%09@Test%0A%09public void testValueOfWithoutIAE() %7B%0A%09%09String txt = %22NOT_BACK_OFFICE%22;%0A%09%09SystemType systemType = SystemType.valueOfWithoutIAE(txt);%0A%09%09Assert.assertEquals(%22BACK_OFFICE%22, String.valueOf(systemType));%0A%09%7D%0A%09%0A
 %09@Test%0A%09publ
@@ -1320,24 +1320,20 @@
  (System
-Division
+Type
 .valueOf
@@ -1703,24 +1703,20 @@
 m System
-Division
+Type
  %7B%0A%09%09BAC
@@ -1779,24 +1779,20 @@
 e System
-Division
+Type
 () %7B%7D //
@@ -1853,16 +1853,12 @@
 stem
-Division
+Type
 (fin
@@ -1981,24 +1981,240 @@
 lField;%0A%09%09%7D%0A
+%09%09%0A%09%09public static SystemType valueOfWithoutIAE(String arg) %7B%0A%09%09%09try %7B%0A%09%09%09%09return SystemType.valueOf(arg);%0A%09%09%09%7D catch (IllegalArgumentException e) %7B%0A%09%09%09%09logger.debug(e.getMessage());%0A%09%09%09%09return BACK_OFFICE;%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%0A%09private

update daily daily daily