Code Snippet for BidiMap BAEL-963 (#2204)

* added updated example codes

* updated example code StringToCharStream

* deleted StringToCharStream.java locally

* removed redundant file

* added code for apache commons collection SetUtils

* refactored example code
This commit is contained in:
Seun Matt 2017-07-06 00:17:17 +01:00 committed by Zeger Hendrikse
parent 178af4e049
commit 8ea31542ed
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package com.baeldung.commons.collections;
import org.apache.commons.collections4.BidiMap;
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
import org.apache.commons.collections4.bidimap.DualLinkedHashBidiMap;
import org.apache.commons.collections4.bidimap.DualTreeBidiMap;
import org.apache.commons.collections4.bidimap.TreeBidiMap;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by smatt on 03/07/2017.
*/
public class BidiMapUnitTest {
@Test
public void givenKeyValue_whenPut_thenAddEntryToMap() {
BidiMap<String, String> map = new DualHashBidiMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
assertEquals(map.size(), 2);
}
@Test
public void whenInverseBidiMap_thenInverseKeyValue() {
BidiMap<String, String> map = new DualHashBidiMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
BidiMap<String, String> rMap = map.inverseBidiMap();
assertTrue(rMap.containsKey("value1") && rMap.containsKey("value2"));
}
@Test
public void givenValue_whenRemoveValue_thenRemoveMatchingMapEntry() {
BidiMap<String, String> map = new DualHashBidiMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
map.removeValue("value2");
assertFalse(map.containsKey("key2"));
}
@Test
public void givenValue_whenGetKey_thenMappedKey() {
BidiMap<String, String> map = new DualHashBidiMap<>();
map.put("key1", "value1");
assertEquals(map.getKey("value1"), "key1");
}
}