Lines Matching defs:biMap
35 * Common tests for any {@code BiMap}.
42 protected abstract BiMap<Integer, String> create();
44 protected BiMap<Integer, String> bimap;
50 bimap = create();
51 entrySet = bimap.entrySet();
55 bimap.clear();
56 assertTrue(bimap.isEmpty());
58 bimap.clear();
59 assertTrue(bimap.isEmpty());
63 assertFalse(bimap.containsKey(null));
64 assertFalse(bimap.containsKey(1));
65 assertFalse(bimap.containsKey("one"));
67 bimap.put(1, "one");
68 assertTrue(bimap.containsKey(1));
70 bimap.put(null, null);
71 assertTrue(bimap.containsKey(null));
75 assertFalse(bimap.containsValue(null));
76 assertFalse(bimap.containsValue(1));
77 assertFalse(bimap.containsValue("one"));
79 bimap.put(1, "one");
80 assertTrue(bimap.containsValue("one"));
82 bimap.put(null, null);
83 assertTrue(bimap.containsValue(null));
87 BiMap<Integer, String> biMap = create();
88 assertEquals(biMap, biMap);
89 assertEquals(create(), biMap);
90 biMap.put(1, null);
91 assertFalse(create().equals(biMap));
95 assertNull(bimap.get(1));
96 assertNull(bimap.get(null));
97 assertNull(bimap.get("bad"));
99 bimap.put(1, "one");
100 bimap.put(0, null);
101 bimap.put(null, "nothing");
102 assertEquals("one", bimap.get(1));
103 assertNull(bimap.get(0));
104 assertEquals("nothing", bimap.get(null));
105 assertNull(bimap.get("bad"));
107 bimap.forcePut(null, null);
108 assertNull(bimap.get(null));
109 bimap.remove(null);
110 assertNull(bimap.get(null));
114 BiMap<String, Integer> inverse = bimap.inverse();
115 bimap.put(1, "one");
116 bimap.put(2, "two");
120 assertSame(bimap, inverse.inverse());
124 BiMap<String, Integer> inverse = bimap.inverse();
125 bimap.put(1, "one");
126 bimap.inverse().put("two", 2);
128 assertEquals(ImmutableMap.of(1, "one", 2, "two"), bimap);
132 assertTrue(bimap.isEmpty());
133 bimap.put(1, "one");
134 assertFalse(bimap.isEmpty());
135 bimap.remove(1);
136 assertTrue(bimap.isEmpty());
140 bimap.put(1, "one");
141 assertEquals(ImmutableMap.of(1, "one"), bimap);
143 bimap.put(2, "two");
144 assertEquals(ImmutableMap.of(1, "one", 2, "two"), bimap);
146 bimap.put(2, "two");
147 assertEquals(ImmutableMap.of(1, "one", 2, "two"), bimap);
149 bimap.put(1, "ONE");
150 assertEquals(ImmutableMap.of(1, "ONE", 2, "two"), bimap);
153 bimap.put(3, "two");
157 assertEquals(ImmutableMap.of(1, "ONE", 2, "two"), bimap);
159 bimap.put(-1, null);
160 bimap.put(null, "null");
167 assertEquals(expected, bimap);
169 bimap.remove(-1);
170 bimap.put(null, null);
175 assertEquals(expected, bimap);
179 bimap.put(-1, null);
180 assertTrue(bimap.containsValue(null));
181 bimap.put(1, "one");
182 assertTrue(bimap.containsValue(null));
186 bimap.put(1, "one");
188 bimap.putAll(newEntries);
189 assertEquals(ImmutableMap.of(1, "one", 2, "two", 3, "three"), bimap);
193 assertNull(bimap.forcePut(1, "one"));
194 assertEquals(ImmutableMap.of(1, "one"), bimap);
195 assertEquals("one", bimap.forcePut(1, "one"));
196 assertEquals(ImmutableMap.of(1, "one"), bimap);
197 assertEquals("one", bimap.forcePut(1, "ONE"));
198 assertEquals(ImmutableMap.of(1, "ONE"), bimap);
199 assertNull(bimap.forcePut(-1, "ONE")); // key 1 disappears without a trace
200 assertEquals(ImmutableMap.of(-1, "ONE"), bimap);
201 assertNull(bimap.forcePut(2, "two"));
202 assertEquals(ImmutableMap.of(-1, "ONE", 2, "two"), bimap);
203 assertEquals("two", bimap.forcePut(2, "ONE"));
204 assertEquals(ImmutableMap.of(2, "ONE"), bimap);
213 bimap.putAll(map);
214 assertNull(bimap.remove(0));
217 assertEquals(map, bimap);
219 assertEquals("null", bimap.remove(null));
220 assertEquals(Collections.singletonMap(1, "one"), bimap);
222 assertNull(bimap.remove(15));
224 assertEquals("one", bimap.remove(1));
225 assertTrue(bimap.isEmpty());
229 assertEquals(0, bimap.size());
230 bimap.put(1, "one");
231 assertEquals(1, bimap.size());
232 bimap.put(1, "ONE");
233 assertEquals(1, bimap.size());
234 bimap.put(2, "two");
235 assertEquals(2, bimap.size());
236 bimap.forcePut(1, "two");
237 assertEquals(1, bimap.size());
241 bimap.put(1, "one");
242 bimap.put(2, "two");
244 String string = bimap.toString();
248 assertEquals(expected, bimap.toString());
272 assertTrue(bimap.isEmpty());
276 assertTrue(bimap.isEmpty());
281 bimap.put(1, "one");
289 bimap.put(null, null);
297 bimap.put(null, "null");
298 bimap.put(0, null);
311 bimap.put(1, "one");
313 bimap.remove(1);
319 assertTrue(bimap.containsKey(1));
320 assertTrue(bimap.containsValue("one"));
322 assertFalse(bimap.containsKey(1));
323 assertFalse(bimap.containsValue("one"));
324 assertEquals(2, bimap.size());
325 assertEquals(2, bimap.inverse().size());
328 assertEquals(2, bimap.size());
329 assertEquals(2, bimap.inverse().size());
334 assertTrue(bimap.containsKey(1));
335 assertTrue(bimap.containsValue("one"));
338 assertFalse(bimap.containsKey(1));
339 assertFalse(bimap.containsValue("one"));
340 assertEquals(2, bimap.size());
341 assertEquals(2, bimap.inverse().size());
345 bimap.put(1, "one");
346 Entry<Integer, String> entry = bimap.entrySet().iterator().next();
347 bimap.put(2, "two");
349 bimap.put(1, "one");
351 assertEquals("one", bimap.get(1));
352 assertEquals(Integer.valueOf(1), bimap.inverse().get("one"));
353 bimap.put(1, "uno");
355 assertEquals("uno", bimap.get(1));
356 assertEquals(Integer.valueOf(1), bimap.inverse().get("uno"));
357 assertEquals(2, bimap.size());
358 assertEquals(2, bimap.inverse().size());
364 assertEquals("uno", bimap.get(1));
365 assertEquals(Integer.valueOf(1), bimap.inverse().get("uno"));
366 assertEquals(2, bimap.size());
367 assertEquals(2, bimap.inverse().size());
371 bimap.put(1, "a");
372 Entry<Integer, String> entry = bimap.entrySet().iterator().next();
373 bimap.clear();
378 assertEquals(0, bimap.size());
379 assertEquals(0, bimap.inverse().size());
383 bimap.put(1, null);
384 Entry<Integer, String> entry = bimap.entrySet().iterator().next();
385 bimap.clear();
390 assertEquals(0, bimap.size());
391 assertEquals(0, bimap.inverse().size());
395 bimap.put(1, "a");
396 Entry<Integer, String> entry = bimap.entrySet().iterator().next();
397 bimap.clear();
398 bimap.put(1, "a");
403 assertEquals(1, bimap.size());
404 assertEquals("a", bimap.get(1));
405 assertEquals(1, bimap.inverse().size());
406 assertEquals((Integer) 1, bimap.inverse().get("a"));
411 Iterator<Integer> iterator = bimap.keySet().iterator();
414 assertEquals(2, bimap.size());
415 assertEquals(2, bimap.inverse().size());
420 Set<Integer> keySet = bimap.keySet();
422 assertEquals(1, bimap.size());
428 Set<Integer> keySet = bimap.keySet();
430 assertEquals(1, bimap.size());
436 Iterator<Entry<Integer, String>> iterator = bimap.entrySet().iterator();
439 assertEquals(2, bimap.size());
440 assertEquals(2, bimap.inverse().size());
445 Set<Map.Entry<Integer, String>> entries = bimap.entrySet();
448 assertEquals(1, bimap.size());
449 assertTrue(bimap.containsKey(2));
454 Iterator<String> iterator = bimap.values().iterator();
457 assertEquals(2, bimap.size());
458 assertEquals(2, bimap.inverse().size());
462 bimap.put(1, "one");
465 assertSame(array, bimap.values().toArray(array));
471 bimap.put(1, "one");
472 assertEquals("[one]", bimap.values().toString());
477 bimap.put(1, "one");
478 bimap.put(2, "two");
479 bimap.put(3, "three");
480 bimap.put(null, null);
482 BiMap<Integer, String> copy =
483 SerializableTester.reserializeAndAssert(bimap);
484 assertEquals(bimap.inverse(), copy.inverse());
488 bimap.put(1, "one");
489 bimap.put(2, "two");
490 bimap.put(3, "three");
495 final BiMap<Integer, String> forward;
496 final BiMap<String, Integer> backward;
498 BiMapPair(BiMap<Integer, String> original) {
508 bimap.put(1, "one");
509 bimap.put(2, "two");
510 bimap.put(3, "three");
511 bimap.put(null, null);
513 BiMapPair pair = new BiMapPair(bimap);
534 * The sameness checks ensure that a bimap and its inverse remain consistent,
541 bimap.put(1, "one");
542 bimap.put(2, "two");
543 bimap.put(3, "three");
544 bimap.put(null, null);
546 BiMapPair pair = new BiMapPair(bimap);