[jboss-svn-commits] JBoss Common SVN: r2586 - common-old/branches/Branch_1_0/src/main/org/jboss/util/collection.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 25 11:34:52 EDT 2007
Author: dimitris at jboss.org
Date: 2007-09-25 11:34:51 -0400 (Tue, 25 Sep 2007)
New Revision: 2586
Modified:
common-old/branches/Branch_1_0/src/main/org/jboss/util/collection/WeakSet.java
Log:
JBCOMMON-24, handle null values and multiple invocations of hasNext()
Modified: common-old/branches/Branch_1_0/src/main/org/jboss/util/collection/WeakSet.java
===================================================================
--- common-old/branches/Branch_1_0/src/main/org/jboss/util/collection/WeakSet.java 2007-09-25 15:34:16 UTC (rev 2585)
+++ common-old/branches/Branch_1_0/src/main/org/jboss/util/collection/WeakSet.java 2007-09-25 15:34:51 UTC (rev 2586)
@@ -1,33 +1,32 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.util.collection;
import java.lang.ref.ReferenceQueue;
-
-import java.util.Set;
+import java.util.AbstractSet;
import java.util.HashSet;
-import java.util.AbstractSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.util.Set;
import org.jboss.util.NullArgumentException;
import org.jboss.util.WeakObject;
@@ -117,10 +116,16 @@
/** The set's iterator */
Iterator iter = set.iterator();
+ /** JBCOMMON-24, handle null values and multiple invocations of hasNext() */
+ Object UNKNOWN = new Object();
+
/** The next available object. */
- Object next = null;
+ Object next = UNKNOWN;
public boolean hasNext() {
+ if (next != UNKNOWN) {
+ return true;
+ }
while (iter.hasNext()) {
WeakObject weak = (WeakObject)iter.next();
Object obj = null;
@@ -128,21 +133,18 @@
// object has been reclaimed by the GC
continue;
}
-
next = obj;
return true;
}
-
return false;
}
public Object next() {
- if ((next == null) && !hasNext()) {
+ if ((next == UNKNOWN) && !hasNext()) {
throw new NoSuchElementException();
}
-
Object obj = next;
- next = null;
+ next = UNKNOWN;
return obj;
}
More information about the jboss-svn-commits
mailing list