티스토리 뷰
반응형
-
mulityKeyMap
- com.google.guava에서 제공되는 map 인터페이스로, 각 key에 해당되는 콜렉션을 보유합니다.
-
mulityKeyMap.get()
hashmap, MultiMap의 경우 get(key)로 데이터를 가지고 왔을때 매핑 되는 정보가 없다면 null을 리턴해준다.
mulityKeyMap도 매핑된 데이터가 없을 경우 null을 리턴한다고 생각하고 null 체크를 하고 테스트를 돌려봤다.
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
public class Test {
@Test
public void multiKeyMapNullCheck_test() {
Multimap<String, String> nullMap = ArrayListMultimap.create();
assertNull(nullMap.get("noneMatchedkey"));
}
}
java.lang.AssertionError: expected null, but was:<\[\]>
at org.junit.Assert.failNotNull(Assert.java:664)
at org.junit.Assert.assertNull(Assert.java:646)
at org.junit.Assert.assertNull(Assert.java:656)
at CommonTest.multiKeyMapNullCheck_test(CommonTest.java:1242)
/**
* Returns a view collection of the values associated with {@code key} in this
* multimap, if any. Note that when {@code containsKey(key)} is false, this
* returns an empty collection, not {@code null}.
*
* <p>Changes to the returned collection will update the underlying multimap,
* and vice versa.
*/
Collection<V> get(@Nullable K key);
-
guava의 mulityKeyMap.get 메서드의 설명을 확인해보니 매핑 데이터가 없을 시에 empty Collection을 전달 해주고 있다.
-
multimap에서 get한 키값을 체크할경우에 empty로 체크해줘야 할듯 하다..
-
org.apache.commons.collections4에서도 MultiMap(MultiValuedMap) 동일한 기능을 해주는 인터페이스가 제공되는거 같은데 요 친구는 매핑 데이터 없을때 null 반환 해주고 있다.
-
참고
https://www.baeldung.com/guava-multimap
https://guava.dev/releases/23.0/api/docs/com/google/common/collect/Multimap.html
https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/MultiValuedMap.html
반응형
'[JAVA]' 카테고리의 다른 글
[Jave] 자바 스레드와 동시성(1) - 스레드 적용 방법, 상태 (0) | 2022.09.29 |
---|---|
[java] Cannot resolve symbol 'Resource' 에러 (0) | 2022.09.19 |
[java] for문 조건문 내 함수 사용시 주의 사항. (0) | 2020.11.15 |
[java] servlet 등록 방법 (0) | 2020.11.04 |
[java] Anonymous Classes(익명 클래스) (0) | 2019.06.12 |
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 파스칼 표기법
- IntelliJ
- java11
- spring
- aspectj
- JUnit
- 한글깨짐
- 카멜 표기법
- jdk13
- Jenkins
- ThreadPool
- Executor
- Mockito
- JetBrains Mono
- JAVA8
- Visual Studio 2022
- spring-security
- jdk12
- java
- junit5
- Thread
- chmod
- gradle
- hot-deploy
- thread priority
- JPA
- sgw
- 확인창
- codepoint
- Redis
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함