title
๋ถ๋์ด ๋ง์์ง๋ฉด ๋ณ๋์ ๋ฌธ์๋ก ์ ๋ฆฌ
๋๋ฑ์ฑ (equality)
- ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฒด๋
Object.equals(Object)๋ฅผ ํ์ฉํ๋ค. - Hash ๋ฅ์ ์๋ฃ๊ตฌ์กฐ๋ ๊ฐ์ฒด์
hashcode()๋ฅผ ํ์ฉํ๋ค. ์ด๋ฌํ ์ด์ ๋กequalsํจ์๋ฅผ ์ฌ์ ์ํ๋ฉดhashcode๋ ๊ฐ์ด ํ๋ผ๊ณ ๋ฆฐํฐ์์ ๊ถ๊ณ ํ๋ค. - Sorted ๋ฅ์ ์๋ฃ๊ตฌ์กฐ๋
Comparable<T>์ธํฐํ์ด์ค์compareTo(T)๋ฅผ ํ์ฉํ๋ค.
์ด ๊ธฐ๋ก์ ๋จ๊ธฐ๋ ์ด์ ๋ Map<K, V>์ ํค๋ฅผ ํ ๋น๋ ์์๋ก ์ํํ๊ณ ์ถ์ด์, SortedMap๊ณผ K์ Wrapper๋ฅผ ํ์ฉํ๋ค ์คํจํ๊ธฐ ๋๋ฌธ์ด๋ค. ํค๋ฅผ ํ ๋นํ ๋๋ง๋ค id๋ฅผ ์ฆ๊ฐ์ํค๊ณ TreeMap์ผ๋ก id์ ๋ํด ์ค๋ฆ์ฐจ์์ผ๋ก ์ํํ๋ ค๊ณ ํ๋ค. ํ์ง๋ง ์์ ๋งํ ๋๋ฑ์ฑ์ ๋ํ ๊ธฐ์ค ๋๋ฌธ์, ํค์ ๋๋ฑ์ฑ์ด ๋ด๋ถ ๋ฐ์ดํฐ๊ฐ ์๋, ์ค๋ก์ง id๋ก๋ง ํ๊ฐ๋์ด ๊ธฐ์กด ๊ธฐ๋ฅ์ด ๋ชจ๋ ํ
์คํธ ์คํจํ๊ฒ ๋์๋ค.
SortedMap ์ธํฐํ์ด์ค ๋์ SequencedMap ์ธํฐํ์ด์ค๋ฅผ ํ์ฉํ๋ฉด ํด๊ฒฐํ ์ ์๋ค.
[!info] SequencedMap ์ธํฐํ์ด์ค ์ค๋ช
A Map that has a well-defined encounter order, that supports operations at both ends, and that is reversible. The encounter order of a SequencedMap is similar to that of the elements of a SequencedCollection, but the ordering applies to mappings instead of individual elements.
๊ฐ๋จํ๊ฒ ๊ตฌํ์ฒด๋ง LinkedHashMap์ผ๋ก ๋ณ๊ฒฝํ๋ฉด ๋๋ค.