CollectionUtils::removeAll() Commons Collections 3.2.1Java Commons Collezioni removeAll
devo andare pazzo, becuase sembra che questo metodo sta facendo l'inverso di ciò che la documentazione dello stato:
Removes the elements in remove from collection. That is, this method returns a collection containing all the elements in c that are not in remove.
Questo piccolo JUnit prova
@Test
public void testCommonsRemoveAll() throws Exception {
String str1 = "foo";
String str2 = "bar";
String str3 = "qux";
List<String> collection = Arrays.asList(str1, str2, str3);
System.out.println("collection: " + collection);
List<String> remove = Arrays.asList(str1);
System.out.println("remove: " + remove);
Collection result = CollectionUtils.removeAll(collection, remove);
System.out.println("result: " + result);
assertEquals(2, result.size());
}
Non funziona con
java.lang.AssertionError: expected:<2> but was:<1>
e stampe
collection: [foo, bar, qux]
remove: [foo]
result: [foo]
Dalla mia lettura dei documenti devo aspettarmi [bar, qux]
. Cosa mi sono perso?
Ho aggiornato il mio post per riflettere questo dato che qualcuno me lo ha ricordato, ma Apache Commons Collections 4.0 è stato rilasciato a novembre 2013, con una correzione per questo problema. – birryree