## collections/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java:430-480
430:      * @param object The object to remove
431:      * @return true if the bag changed
432:      */
433:     @Override
434:     public boolean remove(final Object object) {
435:         final MutableInteger mut = map.get(object);
436:         if (mut == null) {
437:             return false;
438:         }
439:         modCount++;
440:         map.remove(object);
441:         size -= mut.value;
442:         return true;
443:     }
444: 
445:     /**
446:      * Removes a specified number of copies of an object from the bag.
447:      *
448:      * @param object The object to remove
449:      * @param nCopies The number of copies to remove
450:      * @return true if the bag changed
451:      */
452:     @Override
453:     public boolean remove(final Object object, final int nCopies) {
454:         final MutableInteger mut = map.get(object);
455:         if (mut == null) {
456:             return false;
457:         }
458:         if (nCopies <= 0) {
459:             return false;
460:         }
461:         modCount++;
462:         if (nCopies < mut.value) {
463:             mut.value -= nCopies;
464:             size -= nCopies;
465:         } else {
466:             map.remove(object);
467:             size -= mut.value;
468:         }
469:         return true;
470:     }
471: 
472:     /**
473:      * Removes objects from the bag according to their count in the specified
474:      * collection.
475:      *
476:      * @param coll The collection to use
477:      * @return true if the bag changed
478:      */
479:     @Override
480:     public boolean removeAll(final Collection<?> coll) {

## collections/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java:780-808
780: 
781:     @Override
782:     public V put(final K key, final V value) {
783:         if (normalMap.containsKey(key)) {
784:             reverseMap.remove(normalMap.get(key));
785:         }
786:         if (reverseMap.containsKey(value)) {
787:             normalMap.remove(reverseMap.get(value));
788:         }
789:         final V obj = normalMap.put(key, value);
790:         reverseMap.put(value, key);
791:         return obj;
792:     }
793: 
794:     @Override
795:     public void putAll(final Map<? extends K, ? extends V> map) {
796:         for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
797:             put(entry.getKey(), entry.getValue());
798:         }
799:     }
800: 
801:     @Override
802:     public V remove(final Object key) {
803:         V value = null;
804:         if (normalMap.containsKey(key)) {
805:             value = normalMap.remove(key);
806:             reverseMap.remove(value);
807:         }
808:         return value;

## collections/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java:524-558
524:     void testBidiPut() {
525:         if (!isPutAddSupported() || !isPutChangeSupported()) {
526:             return;
527:         }
528: 
529:         final BidiMap<K, V> map = makeObject();
530:         final BidiMap<V, K> inverse = map.inverseBidiMap();
531:         assertEquals(0, map.size());
532:         assertEquals(map.size(), inverse.size());
533: 
534:         map.put((K) "A", (V) "B");
535:         assertEquals(1, map.size());
536:         assertEquals(map.size(), inverse.size());
537:         assertEquals("B", map.get("A"));
538:         assertEquals("A", inverse.get("B"));
539: 
540:         map.put((K) "A", (V) "C");
541:         assertEquals(1, map.size());
542:         assertEquals(map.size(), inverse.size());
543:         assertEquals("C", map.get("A"));
544:         assertEquals("A", inverse.get("C"));
545: 
546:         map.put((K) "B", (V) "C");
547:         assertEquals(1, map.size());
548:         assertEquals(map.size(), inverse.size());
549:         assertEquals("C", map.get("B"));
550:         assertEquals("B", inverse.get("C"));
551: 
552:         map.put((K) "E", (V) "F");
553:         assertEquals(2, map.size());
554:         assertEquals(map.size(), inverse.size());
555:         assertEquals("F", map.get("E"));
556:         assertEquals("E", inverse.get("F"));
557:     }
558: 

## collections/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java:260-300
260:     @Test
261:     @SuppressWarnings("unchecked")
262:     void testBagContainsAll() {
263:         if (!isAddSupported()) {
264:             return;
265:         }
266: 
267:         final Bag<T> bag = makeObject();
268:         final List<String> known = new ArrayList<>();
269:         final List<String> known1A = new ArrayList<>();
270:         known1A.add("A");
271:         final List<String> known2A = new ArrayList<>();
272:         known2A.add("A");
273:         known2A.add("A");
274:         final List<String> known1B = new ArrayList<>();
275:         known1B.add("B");
276:         final List<String> known1A1B = new ArrayList<>();
277:         known1A1B.add("A");
278:         known1A1B.add("B");
279: 
280:         assertTrue(bag.containsAll(known), "Bag containsAll of empty");
281:         assertFalse(bag.containsAll(known1A), "Bag does not containsAll of 1 'A'");
282:         assertFalse(bag.containsAll(known2A), "Bag does not containsAll of 2 'A'");
283:         assertFalse(bag.containsAll(known1B), "Bag does not containsAll of 1 'B'");
284:         assertFalse(bag.containsAll(known1A1B), "Bag does not containsAll of 1 'A' 1 'B'");
285: 
286:         bag.add((T) "A");  // bag 1A
287:         assertTrue(bag.containsAll(known), "Bag containsAll of empty");
288:         assertTrue(bag.containsAll(known1A), "Bag containsAll of 1 'A'");
289:         assertFalse(bag.containsAll(known2A), "Bag does not containsAll of 2 'A'");
290:         assertFalse(bag.containsAll(known1B), "Bag does not containsAll of 1 'B'");
291:         assertFalse(bag.containsAll(known1A1B), "Bag does not containsAll of 1 'A' 1 'B'");
292: 
293:         bag.add((T) "A");  // bag 2A
294:         assertTrue(bag.containsAll(known), "Bag containsAll of empty");
295:         assertTrue(bag.containsAll(known1A), "Bag containsAll of 1 'A'");
296:         assertTrue(bag.containsAll(known2A), "Bag containsAll of 2 'A'");
297:         assertFalse(bag.containsAll(known1B), "Bag does not containsAll of 1 'B'");
298:         assertFalse(bag.containsAll(known1A1B), "Bag does not containsAll of 1 'A' 1 'B'");
299: 
300:         bag.add((T) "A");  // bag 3A
