authorities = new ArrayList<>();
31 | authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
32 |
33 | return new User(account.getEmail(), account.getPassword(), authorities);
34 | }
35 |
36 | public Account save(Account account) {
37 | account.setPassword(passwordEncoder.encode(account.getPassword()));
38 | return accounts.save(account);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/demospringbootsecurity/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keesun/study/7f47b9ae5c1b25be31a7e1b0fe7602cc70017031/demospringbootsecurity/src/main/resources/application.properties
--------------------------------------------------------------------------------
/demospringbootsecurity/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | Hello World!
6 |
7 |
8 | Hello [[${#httpServletRequest.remoteUser}]]!
9 |
12 |
13 |
--------------------------------------------------------------------------------
/demospringbootsecurity/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | Click here to see a greeting.
10 |
11 |
--------------------------------------------------------------------------------
/demospringbootsecurity/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | Spring Security Example
6 |
7 |
8 |
9 | Invalid username and password.
10 |
11 |
12 | You have been logged out.
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/demospringbootsecurity/src/test/java/me/whiteship/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.demo;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class DemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/demospringssl/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/demospringssl/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keesun/study/7f47b9ae5c1b25be31a7e1b0fe7602cc70017031/demospringssl/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/demospringssl/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/demospringssl/keystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keesun/study/7f47b9ae5c1b25be31a7e1b0fe7602cc70017031/demospringssl/keystore.p12
--------------------------------------------------------------------------------
/demospringssl/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | me.whiteship
7 | demo
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | demo
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.3.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/demospringssl/src/main/java/me/whiteship/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @SpringBootApplication
10 | @RestController
11 | public class DemoApplication {
12 |
13 | @GetMapping("/")
14 | public String hello() {
15 | return "Hello Spring";
16 | }
17 |
18 | @PostMapping("/post")
19 | public String post() {
20 | return "post";
21 | }
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(DemoApplication.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/demospringssl/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.ssl.key-store: keystore.p12
2 | server.ssl.key-store-password: 123456
3 | server.ssl.keyStoreType: PKCS12
4 | server.ssl.keyAlias: tomcat
5 |
--------------------------------------------------------------------------------
/demospringssl/src/test/java/me/whiteship/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.demo;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class DemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/docker-cmds.md:
--------------------------------------------------------------------------------
1 |
2 | ### 컨테이너 상세 정보 보기
3 |
4 | ```
5 | docker inspect sharp_bartik
6 | ```
7 |
8 | ### 컨테이너 아이디 가져오기
9 |
10 | ```
11 | CID=$(docker run -d monolith:1.0.0)
12 | ```
13 |
14 | ### 컨테이너 아이피 가져오기
15 |
16 | ```
17 | CID=$(docker run -d monolith:1.0.0)
18 | CIP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID})
19 | ```
20 |
21 | ### 컨테이너 전부 멈추기
22 |
23 | ```
24 | stop $(sudo docker ps -aq)
25 | ```
26 |
27 | ### 컨테이너 전부 삭제
28 |
29 | ```
30 | docker rm $(sudo docker ps -aq)
31 | ```
32 |
33 | ### MySQL
34 |
35 | ```
36 | docker run -p 3306:3306 --name mysql_boot -e MYSQL_ROOT_PASSWORD=1 -e MYSQL_DATABASE=springboot -e MYSQL_USER=keesun -e MYSQL_PASSWORD=pass -d mysql
37 |
38 | docker exec -i -t mysql_boot bash
39 |
40 | mysql -u root -p
41 | ```
42 |
--------------------------------------------------------------------------------
/doker-getting-started.md:
--------------------------------------------------------------------------------
1 | # 도커 시작하기
2 |
3 | ## 참고
4 |
5 | [도커 시작하기](https://docs.docker.com/get-started/)
6 | [유툽/백기선/도커](https://www.youtube.com/playlist?list=PLfI752FpVCS84hxOeCyI4SBPUwt4Itd0T)
7 |
8 | ## 유툽 인덱스
9 |
10 | [](https://youtu.be/9tW0QSsrhwc)
11 |
12 | 파트 1에서는 도커에 대한 기본적인 설명과 특징을 살펴봤습니다.
13 |
14 | 파트 2에서는 Dockerfile을 사용해서 간단한 파이썬 이미지를 만들었고, docker run을 사용해서 컨테이너를 실행하고, 이미지를 태깅하고, 도커 레지스트리에 등록하는 것까지 따라해 보았습니다.
15 |
16 | [](https://youtu.be/p58k2_HMWRM)
17 |
18 | 오늘은 시작하기 파트3 과 파트4를 봤습니다. 도커의 서비스라는 개념을 살펴봤으며 docker-compose.yml 파일을 사용해서 간단히 서비스를 정의하고 실행해 봤습니다.
19 |
20 | 파트3에서 실행할 때는 로컬 머신에서 도커 스왐을 만들고 docker stack deploy를 사용했는데, 파트 4에서는 VM을 두개 만들어서 본격적으로 스왐을 구성합니다.
21 |
22 | myvm1은 스왐 매니저로 만들고 myvm2는 워커로 만들었습니다. 스왐 매니저만 도커 명령을 실행할 수 있기 때문에 매번 docker-machine ssh myvm1 "docker ..." 이런식으로 도커를 실행해야 하는 번거로움이 있는데, docker-machine env 를 사용해서 그런 수고를 덜 수 있는 방법을 살펴봤습니다. (그런데 간혹 로컬에 있는 도커랑 햇갈릴듯..)
23 |
24 | 혹시나 맥에서 VirtualBox 설치할 때 문제 있으신 분들은 아래 링크 참고하셔서 해결하시기 바랍니다. 혹은 제 영상 보시면 간략히 설명해 드렸으니까 참고하세요.
25 |
26 | https://stackoverflow.com/questions/46546192/virtualbox-not-installing-on-high-sierra
27 |
28 | [](https://youtu.be/X--WPFfSbFc)
29 |
30 | 마지막은 이전까지 만들었던 docker-compose.yml에 서비스를 두개 더 추가하고 AWS나 Azure에 배포하는 방법을 소개하고 있습니다.
31 |
32 | 기존 서비스와는 독립적인 서비스 (컨테이너 배포 상황을 보여주는 이미지)와 기존 서비스가 사용하는 서비스 (레디스)를 각각 추가해서 동작하는걸 데모로 해봤습니다. 중간에 맥 쓰시는 분들은 아마도 저처럼 문제(비주얼라이저 컨테이너가 잘 안뜨는)가 생길 수 있을텐데요. 영상에서 해결했사오니 궁금하신 분들은 확인해 보세요.
33 |
34 | 아쉽게도 6부 AWS나 Azure에 배포하는건 따라해보지 못했습니다. 차마 그쪽까지 세팅할만큼 부지런하질 못해서... 대신 개념적으로만 살펴봤는데요. 결국엔 AWS든 Azure든 도커 스왐으로 묶어서 docker-compose.yml 파일을 배포하는건 똑같더라구요. 대신 손만 조금 더 많이 가게 생겼더군요.
35 |
36 | 각 서비스 계정 열어야지, 도커 인스턴스 만들어야지, 스왐으로 연결 해야지, 컨테이너 관련된 포트를 열어줘야지.. @_@..
37 |
38 |
--------------------------------------------------------------------------------
/effective-java-3rd/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/effective-java-3rd/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/keesun/study/7f47b9ae5c1b25be31a7e1b0fe7602cc70017031/effective-java-3rd/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/effective-java-3rd/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/effective-java-3rd/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | me.whiteship
7 | effective-java-3rd
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | effective-java-3rd
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.1.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 10
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 | org.apache.maven.plugins
53 | maven-compiler-plugin
54 |
55 | ${java.version}
56 | ${java.version}
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/EffectiveJava3rdApplication.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class EffectiveJava3rdApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(EffectiveJava3rdApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item01/Foo.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item01;
2 |
3 | import java.util.EnumSet;
4 |
5 | import static me.whiteship.effectivejava3rd.item01.Foo.Color.BLUE;
6 | import static me.whiteship.effectivejava3rd.item01.Foo.Color.RED;
7 | import static me.whiteship.effectivejava3rd.item01.Foo.Color.WHITE;
8 |
9 | public class Foo {
10 |
11 | String name;
12 |
13 | String address;
14 |
15 | public Foo() {
16 | }
17 |
18 | private static final Foo GOOD_NIGHT = new Foo();
19 |
20 | public Foo(String name) {
21 | this.name = name;
22 | }
23 |
24 | public static Foo withName(String name) {
25 | return new Foo(name);
26 | }
27 |
28 | public static Foo withAddress(String address) {
29 | Foo foo = new Foo();
30 | foo.address = address;
31 | return foo;
32 | }
33 |
34 | public static Foo getFoo() {
35 | return GOOD_NIGHT;
36 | }
37 |
38 | public static Foo getFoo(boolean flag) {
39 | Foo foo = new Foo();
40 |
41 | // TODO 어떤 특정 약속 되어 있는 텍스트 파일에서 Foo의 구현체의 FQCN 을 읽어온다.
42 | // TODO FQCN 에 해당하는 인스턴스를 생성한다.
43 | // TODO foo 변수를 해당 인스턴스를 가리키도록 수정한다.
44 |
45 | return foo;
46 | }
47 |
48 | public static void main(String[] args) {
49 | Foo foo = new Foo("keesun");
50 |
51 | Foo foo1 = Foo.withName("keesun");
52 |
53 | Foo foo2 = Foo.getFoo();
54 |
55 | Foo foo3 = Foo.getFoo(false);
56 |
57 | EnumSet colors = EnumSet.allOf(Color.class);
58 |
59 | EnumSet blueAndWhite = EnumSet.of(BLUE, WHITE);
60 | }
61 |
62 | enum Color {
63 | RED, BLUE, WHITE
64 | }
65 |
66 | // private static method가 필요한 이유
67 | public static void doSomething() {
68 | // TODO 청소를 한다.
69 | // TODO 애들이랑 놀아준다.
70 | // TODO 저녁 약속에 간다.
71 | 게임을하고잔다();
72 | }
73 |
74 | public static void doSomethingTomorrow() {
75 | // TODO 애들 데리고 수영장에 간다.
76 | // TODO 밥을 먹는다.
77 | 게임을하고잔다();
78 | }
79 |
80 | private static void 게임을하고잔다() {
81 | // TODO 게임을 한다.
82 | // TODO 잔다.
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item01/FooInterface.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item01;
2 |
3 | public interface FooInterface {
4 |
5 | public static Foo getFoo() {
6 | return new Foo();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item01/MyFoo.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item01;
2 |
3 | public class MyFoo extends Foo {
4 | }
5 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item02/Calzone.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item02;
2 |
3 | public class Calzone extends Pizza {
4 |
5 | private final boolean sauceInside;
6 |
7 | public static class Builder extends Pizza.Builder {
8 | private boolean sauceInside = false;
9 |
10 | public Builder sauceInde() {
11 | sauceInside = true;
12 | return this;
13 | }
14 |
15 | @Override
16 | public Calzone build() {
17 | return new Calzone(this);
18 | }
19 |
20 | @Override
21 | protected Builder self() {
22 | return this;
23 | }
24 | }
25 |
26 | private Calzone(Builder builder) {
27 | super(builder);
28 | sauceInside = builder.sauceInside;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item02/NutritionFacts.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item02;
2 |
3 | //import lombok.Builder;
4 | //import lombok.Singular;
5 | //
6 | //import java.util.List;
7 |
8 | //@Builder
9 | public class NutritionFacts {
10 |
11 | // @Builder.Default private int servingSize = 10;
12 | private int sodium;
13 | private int carbohydrate;
14 | private int servings;
15 | // @Singular private List names;
16 |
17 | public static void main(String[] args) {
18 | // NutritionFacts nutritionFacts = NutritionFacts.builder()
19 | // .servings(10)
20 | // .carbohydrate(100)
21 | // .name("keesun")
22 | // .clearNames()
23 | // .build();
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item02/NyPizza.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item02;
2 |
3 | import java.util.Objects;
4 |
5 | public class NyPizza extends Pizza {
6 |
7 | public enum Size {
8 | SMALL, MEDIUM, LARGE
9 | }
10 |
11 | private final Size size;
12 |
13 | public static class Builder extends Pizza.Builder {
14 | private final Size size;
15 |
16 | public Builder(Size size) {
17 | this.size = Objects.requireNonNull(size);
18 | }
19 |
20 | @Override
21 | public NyPizza build() {
22 | return new NyPizza(this);
23 | }
24 |
25 | @Override
26 | protected Builder self() {
27 | return this;
28 | }
29 | }
30 |
31 | private NyPizza(Builder builder) {
32 | super(builder);
33 | size = builder.size;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item02/Pizza.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item02;
2 |
3 | import java.util.EnumSet;
4 | import java.util.Objects;
5 |
6 | public abstract class Pizza {
7 |
8 | public enum Topping {
9 | HAM, MUSHROOM, ONION
10 | }
11 |
12 | final EnumSet toppings;
13 |
14 | abstract static class Builder> {
15 | EnumSet toppings = EnumSet.noneOf(Topping.class);
16 |
17 | public T addTopping(Topping topping) {
18 | toppings.add(Objects.requireNonNull(topping));
19 | return self();
20 | }
21 |
22 | abstract Pizza build();
23 |
24 | protected abstract T self();
25 | }
26 |
27 | Pizza(Builder> builder) {
28 | toppings = builder.toppings;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item02/PizzaClient.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item02;
2 |
3 | public class PizzaClient {
4 |
5 | public static void main(String[] args) {
6 | NyPizza nyPizza = new NyPizza.Builder(NyPizza.Size.MEDIUM)
7 | .addTopping(Pizza.Topping.HAM)
8 | .addTopping(Pizza.Topping.ONION)
9 | .build();
10 |
11 | Calzone calzone = new Calzone.Builder()
12 | .addTopping(Pizza.Topping.ONION)
13 | .sauceInde()
14 | .build();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/Config.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @ComponentScan(basePackageClasses = Config.class)
8 | public class Config {
9 | }
10 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/SingleTest.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | public class SingleTest {
7 |
8 | public static void main(String[] args) throws NoSuchMethodException {
9 | ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class);
10 | UserService userService1 = applicationContext.getBean(UserService.class);
11 | UserService userService2 = applicationContext.getBean(UserService.class);
12 |
13 | System.out.println(userService1 == userService2);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/Singleton1.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | public class Singleton1 {
4 |
5 | public static final Singleton1 instance = new Singleton1();
6 |
7 | int count;
8 |
9 | private Singleton1() {
10 | count++;
11 | if (count != 1) {
12 | throw new IllegalStateException("this object should be singleton");
13 | }
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/Singleton2.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Singleton2 implements Serializable {
6 |
7 | private static final Singleton2 instance = new Singleton2();
8 |
9 | private Singleton2() {
10 |
11 | }
12 |
13 | public static Singleton2 getInstance() {
14 | return instance;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/Singleton3.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import java.io.Serializable;
4 |
5 | public enum Singleton3 {
6 |
7 | INSTANCE;
8 |
9 | public String getName() {
10 | return "keesun";
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/UserRepository.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import org.springframework.stereotype.Repository;
4 |
5 | @Repository
6 | public class UserRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item03/UserService.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item03;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Scope;
5 | import org.springframework.stereotype.Service;
6 |
7 | import java.io.Serializable;
8 |
9 | @Service
10 | public class UserService implements Serializable {
11 |
12 | @Autowired
13 | UserRepository userRepository;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item04/UtilClass.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item04;
2 |
3 | public abstract class UtilClass {
4 |
5 | public static String getName() {
6 | return "keesun";
7 | }
8 |
9 | public static void main(String[] args) {
10 |
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usecase1/SpellChecker.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usecase1;
2 |
3 | import java.util.List;
4 |
5 | public class SpellChecker {
6 |
7 | private static final Lexicon dictionary = new KoreanDicationry();
8 |
9 | private SpellChecker() {
10 | // Noninstantiable
11 | }
12 |
13 | public static boolean isValid(String word) {
14 | throw new UnsupportedOperationException();
15 | }
16 |
17 | public static List suggestions(String typo) {
18 | throw new UnsupportedOperationException();
19 | }
20 |
21 | public static void main(String[] args) {
22 | SpellChecker.isValid("hello");
23 | }
24 | }
25 |
26 |
27 | interface Lexicon {}
28 |
29 | class KoreanDicationry implements Lexicon {}
30 |
31 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usecase2/SpellChecker.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usecase2;
2 |
3 | import java.util.List;
4 |
5 | public class SpellChecker {
6 |
7 | private final Lexicon dictionary = new KoreanDicationry();
8 |
9 | private SpellChecker() {
10 | }
11 |
12 | public static final SpellChecker INSTANCE = new SpellChecker() {
13 | };
14 |
15 | public boolean isValid(String word) {
16 | throw new UnsupportedOperationException();
17 | }
18 |
19 |
20 | public List suggestions(String typo) {
21 | throw new UnsupportedOperationException();
22 | }
23 |
24 | public static void main(String[] args) {
25 | SpellChecker.INSTANCE.isValid("hello");
26 | }
27 |
28 | }
29 |
30 |
31 | interface Lexicon {}
32 |
33 | class KoreanDicationry implements Lexicon {}
34 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usecase3/SpellChecker.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usecase3;
2 |
3 | import java.util.List;
4 | import java.util.Objects;
5 | import java.util.function.Supplier;
6 |
7 | public class SpellChecker {
8 |
9 | private final Lexicon dictionary;
10 |
11 | public SpellChecker(Supplier dictionary) {
12 | this.dictionary = Objects.requireNonNull(dictionary.get());
13 | }
14 |
15 | public boolean isValid(String word) {
16 | throw new UnsupportedOperationException();
17 | }
18 |
19 | public List suggestions(String typo) {
20 | throw new UnsupportedOperationException();
21 | }
22 |
23 | public static void main(String[] args) {
24 | Lexicon lexicon = new TestDictionary();
25 | SpellChecker spellChecker = new SpellChecker(() -> lexicon);
26 | spellChecker.isValid("hello");
27 | }
28 |
29 | }
30 |
31 | interface Lexicon {}
32 |
33 | class KoreanDictionary implements Lexicon {}
34 |
35 | class TestDictionary implements Lexicon {}
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usercase4/Config.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usercase4;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @ComponentScan(basePackageClasses = Config.class)
8 | public class Config {
9 | }
10 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usercase4/KoreanDictionary.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usercase4;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | public class KoreanDictionary implements Lexicon {
7 |
8 | @Override
9 | public void print() {
10 | System.out.println("Korean");
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usercase4/Lexicon.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usercase4;
2 |
3 | public interface Lexicon {
4 | void print();
5 | }
6 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usercase4/SpellChecker.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usercase4;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import java.util.List;
6 |
7 | @Component
8 | public class SpellChecker {
9 |
10 | private Lexicon lexicon;
11 |
12 | public SpellChecker(Lexicon lexicon) {
13 | this.lexicon = lexicon;
14 | }
15 |
16 | public boolean isValid(String word) {
17 | lexicon.print();
18 | return true;
19 | }
20 |
21 | public List suggestions(String typo) {
22 | throw new UnsupportedOperationException();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item05/usercase4/SpellCheckerClient.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item05.usercase4;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | public class SpellCheckerClient {
7 |
8 | public static void main(String[] args) {
9 | ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class);
10 | SpellChecker spellChecker = applicationContext.getBean(SpellChecker.class);
11 | spellChecker.isValid("hello");
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item06/autoboxing/AutoBoxingExample.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item06.autoboxing;
2 |
3 | public class AutoBoxingExample {
4 |
5 | public static void main(String[] args) {
6 | long start = System.currentTimeMillis();
7 | long sum = 0l;
8 | for (long i = 0 ; i <= Integer.MAX_VALUE ; i++) {
9 | sum += i;
10 | }
11 | System.out.println(sum);
12 | System.out.println(System.currentTimeMillis() - start);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item06/expensiveobject01/RomanNumber.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item06.expensiveobject01;
2 |
3 | public class RomanNumber {
4 |
5 | static boolean isRomanNumeral(String s) {
6 | return s.matches("^(?=.)M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$");
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item06/expensiveobject02/RomanNumber.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item06.expensiveobject02;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | public class RomanNumber {
6 |
7 | private static final Pattern ROMAN = Pattern.compile("^(?=.)M*(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$");
8 |
9 | static boolean isRomanNumeral(String s) {
10 | return ROMAN.matcher(s).matches();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item06/map/UsingKeySet.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item06.map;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Set;
6 |
7 | public class UsingKeySet {
8 |
9 | public static void main(String[] args) {
10 | Map menu = new HashMap<>();
11 | menu.put("Burger", 8);
12 | menu.put("Pizza", 9);
13 |
14 | Set names1 = menu.keySet();
15 | Set names2 = menu.keySet();
16 |
17 | names1.remove("Burger");
18 | System.out.println(names2.size()); // 1
19 | System.out.println(menu.size()); // 1
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item06/strings/StringTest.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item06.strings;
2 |
3 | public class StringTest {
4 |
5 | public static void main(String[] args) {
6 | Boolean true1 = Boolean.valueOf("true");
7 | Boolean true2 = Boolean.valueOf("true");
8 |
9 | System.out.println(true1 == true2);
10 | System.out.println(true1 == Boolean.TRUE);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/effective-java-3rd/src/main/java/me/whiteship/effectivejava3rd/item07/cache/CacheSample.java:
--------------------------------------------------------------------------------
1 | package me.whiteship.effectivejava3rd.item07.cache;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 | import java.util.WeakHashMap;
7 |
8 | public class CacheSample {
9 |
10 | public static void main(String[] args) {
11 | Object key1 = new Object();
12 | Object value1 = new Object();
13 |
14 | Map