|
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Arrays; |
| 5 | +import java.util.Collection; |
5 | 6 | import java.util.Collections; |
| 7 | +import java.util.HashMap; |
6 | 8 | import java.util.HashSet; |
7 | 9 | import java.util.List; |
| 10 | +import java.util.Map; |
8 | 11 | import java.util.Set; |
9 | 12 |
|
10 | 13 | import org.apache.commons.collections4.CollectionUtils; |
@@ -140,4 +143,45 @@ public final void givenUsingCommonsCollections_whenSetConvertedToList_thenCorrec |
140 | 143 | CollectionUtils.addAll(targetList, sourceSet); |
141 | 144 | } |
142 | 145 |
|
| 146 | + // Map (values) -> Array, List, Set |
| 147 | + |
| 148 | + @Test |
| 149 | + public final void givenUsingCoreJava_whenMapValuesConvertedToArray_thenCorrect() { |
| 150 | + final Map<Integer, String> sourceMap = createMap(); |
| 151 | + |
| 152 | + final Collection<String> values = sourceMap.values(); |
| 153 | + final String[] targetArray = values.toArray(new String[values.size()]); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + public final void givenUsingCoreJava_whenMapValuesConvertedToList_thenCorrect() { |
| 158 | + final Map<Integer, String> sourceMap = createMap(); |
| 159 | + |
| 160 | + final List<String> targetList = new ArrayList<>(sourceMap.values()); |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + public final void givenUsingGuava_whenMapValuesConvertedToList_thenCorrect() { |
| 165 | + final Map<Integer, String> sourceMap = createMap(); |
| 166 | + |
| 167 | + final List<String> targetList = Lists.newArrayList(sourceMap.values()); |
| 168 | + } |
| 169 | + |
| 170 | + @Test |
| 171 | + public final void givenUsingCoreJava_whenMapValuesConvertedToS_thenCorrect() { |
| 172 | + final Map<Integer, String> sourceMap = createMap(); |
| 173 | + |
| 174 | + final Set<String> targetSet = new HashSet<>(sourceMap.values()); |
| 175 | + } |
| 176 | + |
| 177 | + // UTIL |
| 178 | + |
| 179 | + private final Map<Integer, String> createMap() { |
| 180 | + final Map<Integer, String> sourceMap = new HashMap<>(3); |
| 181 | + sourceMap.put(0, "zero"); |
| 182 | + sourceMap.put(1, "one"); |
| 183 | + sourceMap.put(2, "two"); |
| 184 | + return sourceMap; |
| 185 | + } |
| 186 | + |
143 | 187 | } |
0 commit comments