#10 effective java: item 1

This commit is contained in:
haerong22
2022-05-06 01:07:18 +09:00
parent 12c0ec71dc
commit c2a0211113
17 changed files with 560 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.example.effectivejava;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EffectiveJavaApplication {
public static void main(String[] args) {
SpringApplication.run(EffectiveJavaApplication.class, args);
}
}

View File

@@ -0,0 +1,6 @@
package com.example.effectivejava.chapter01.item01;
public enum Difficulty {
EASY, NORMAL, HARD, HELL
}

View File

@@ -0,0 +1,28 @@
package com.example.effectivejava.chapter01.item01;
public interface HelloService {
String hello();
static String hi() {
prepareMessage();
return "hi";
}
static private void prepareMessage() {
}
static String hi1() {
prepareMessage();
return "hi";
}
static String hi2() {
prepareMessage();
return "hi";
}
default String bye() {
return "bye";
}
}

View File

@@ -0,0 +1,15 @@
package com.example.effectivejava.chapter01.item01;
import java.util.Optional;
import java.util.ServiceLoader;
public class HelloServiceFactory {
public static void main(String[] args) {
ServiceLoader<HelloService> loader = ServiceLoader.load(HelloService.class);
Optional<HelloService> helloServiceOptional = loader.findFirst();
helloServiceOptional.ifPresent(h -> {
System.out.println(h.hello());
});
}
}

View File

@@ -0,0 +1,37 @@
package com.example.effectivejava.chapter01.item01;
import java.util.EnumSet;
public class Order {
private boolean prime;
private boolean urgent;
private Product product;
private OrderStatus orderStatus;
public static Order primeOrder(Product product) {
Order order = new Order();
order.prime = true;
order.product = product;
return order;
}
public static Order urgentOrder(Product product) {
Order order = new Order();
order.urgent = true;
order.product = product;
return order;
}
public static void main(String[] args) {
Order order = new Order();
if (order.orderStatus == OrderStatus.DELIVERED) {
System.out.println("delivered");
}
}
}

View File

@@ -0,0 +1,12 @@
package com.example.effectivejava.chapter01.item01;
public enum OrderStatus {
PREPARING(0), SHIPPED(1), DELIVERING(2), DELIVERED(3);
private int number;
OrderStatus(int number) {
this.number = number;
}
}

View File

@@ -0,0 +1,17 @@
package com.example.effectivejava.chapter01.item01;
import java.util.EnumSet;
public class Product {
public static void main(String[] args) {
Settings settings1 = Settings.getInstance();
Settings settings2 = Settings.getInstance();
System.out.println(settings1);
System.out.println(settings2);
Boolean.valueOf(false);
EnumSet.allOf(Difficulty.class);
}
}

View File

@@ -0,0 +1,22 @@
package com.example.effectivejava.chapter01.item01;
/**
* 이 클래스의 인스턴스는 #getInstance()를 통해 사용한다.
* @see #getInstance()
*/
public class Settings {
private boolean useAutoSteering;
private boolean useABS;
private Difficulty difficulty;
private Settings() {}
private static final Settings SETTINGS = new Settings();
public static Settings getInstance() {
return SETTINGS;
}
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,13 @@
package com.example.effectivejava;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class EffectiveJavaApplicationTests {
@Test
void contextLoads() {
}
}