Formats { public void intersection(Formats other, Formats intersection) { intersection.list.clear(); for (Format f1 : list) { for (Format f2 : other.list) { if (f1.matches(f2)) intersection.list.add(f2); } } } Formats();  Formats(int size); void add(Format format); void addAll(Formats other); void remove(Format format); Format get(int i); boolean contains(Format format); int size(); boolean isEmpty(); void clean(); void intersection(Formats other, Formats intersection); @Override String toString(); final static int DEFAULT_SIZE; }
@Test public void testIntersection() { Formats f1 = new Formats(); Formats f2 = new Formats(); Formats f3 = new Formats(); AudioFormat pcma = FormatFactory.createAudioFormat("pcma", 8000, 8, 1); AudioFormat linear = FormatFactory.createAudioFormat("linear", 8000, 16, 1); f1.add(pcma); f1.add(linear); f2.add(pcma); f1.intersection(f2, f3); assertEquals(1, f3.size()); assertTrue("pcma expected", pcma.matches(f3.get(0))); }