Skip to content

Commit

Permalink
GITBOOK-185: No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenPearls authored and gitbook-bot committed Nov 7, 2024
1 parent 7ebeaa4 commit caa2726
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ public enum Phase {
* **ํšจ์œจ์„ฑ**: `EnumMap`์€ ๋‚ด๋ถ€์ ์œผ๋กœ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น ๋ฅด๋ฉด์„œ๋„ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋‹ค.
* (x, y) -> y ๋ถ€๋ถ„์€ ์›๋ž˜ ์ค‘๋ณต๋œ ํ‚ค์— ๊ฐ’์ด ๋“ค์–ด์™”์„ ๋•Œ ์–ด๋–ป๊ฒŒ ํ•ฉ์น ๊นŒ๋ฅผ ๊ด€์—ฌํ•˜๋Š” ๋ถ€๋ถ„์ธ๋ฐ, ์—ฌ๊ธฐ์„œ๋Š” ์ค‘๋ณต๋œ ํ‚ค๊ฐ€ ์—†์œผ๋ฏ€๋กœ ์“ฐ์ด์ง€ ์•Š๊ณ  ์žˆ๋‹ค.

**ํ•˜๋“œ ์ฝ”๋”ฉ์œผ๋กœ ์–ด๋ ค์›€์„ ๊ฒช๊ธฐ์— EnumMap์„ ์”€**

```java
public enum Phase {
SOLID, LIQUID, GAS;

public enum Transition {
MELT, FREEZE, BOIL, CONDENSE, SUBLIME, DEPOSIT;

private static final Transition[][] TRANSITIONS = {
{null, MELT, SUBLIME},
{FREEZE, null, BOIL},
{DEPOSIT, CONDENSE, null}
};

public static Transition from(Phase from, Phase to) {
return TRANSITIONS[from.ordinal()][to.ordinal()];
}
}
}
```



## ํ•ต์‹ฌ ์ •๋ฆฌ

* **๋น„ํŠธ ํ•„๋“œ๋‚˜ `ordinal()`์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฐ์—ด ๊ธฐ๋ฐ˜ ๋ฐฉ์‹**์€ ์˜ค๋ฅ˜ ๋ฐœ์ƒ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๊ณ , ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ๊ณผ ์•ˆ์ „์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. ์ฆ‰, ๋ฐฐ์—ด์˜ ์ธ๋ฑ์Šค๋ฅผ ์œ„ํ•ด `ordinal()`์„ ์“ฐ๋Š” ๊ฒƒ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ์ข‹์ง€ ์•Š๋‹ค.
Expand Down

0 comments on commit caa2726

Please sign in to comment.