Cedric and Cameron do some code


Cedric and Cameron do some code

Well, I guess I’ll start with the Java 1.5 action…

First I’ll note that Cedric mentioned that people might change the guys code to make it return false as soon as it found one that wasn’t in the collection. Although the original code did not do this, I suspect that the original code should have done this and the original code was just wrong all around. So I am going to continue on the assumption that the code was in a collection that wanted to find out if it had all the items passed in already.

Cameron’s version:

public boolean containsAll(Collection c) {
 for(Iterator iter = c.iterator(); iter.hasNext();) {
 if (!contains(iter.next()) {
 return false;
 }
 }
 return true;


Of course in the new world order this looks like:

public boolean containsAll(Collection c) {
 for(Object o : c) {
 if (!contains(o)) return false;
 }
 return true;
}

I think I am going to like programming in Java 1.5.