ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/AbstractCollection.java
(Generate patch)

Comparing jsr166/src/main/java/util/AbstractCollection.java (file contents):
Revision 1.1 by dl, Sun Nov 20 15:37:12 2005 UTC vs.
Revision 1.2 by jsr166, Wed Nov 23 05:33:25 2005 UTC

# Line 104 | Line 104 | public abstract class AbstractCollection
104          Object[] r = new Object[size()];
105          int i = 0;
106          Iterator it = iterator();
107 <        while (i < r.length && it.hasNext())
107 >        while (i < r.length && it.hasNext())
108              r[i++] = it.next();
109          // Trim if overallocated; expand if underallocated
110          if (i < r.length || it.hasNext())
# Line 134 | Line 134 | public abstract class AbstractCollection
134                    .newInstance(a.getClass().getComponentType(), size);
135          int i = 0;
136          Iterator it = iterator();
137 <        while (i < r.length && it.hasNext())
137 >        while (i < r.length && it.hasNext())
138              r[i++] = (T)it.next();
139          // Trim if overallocated; expand if underallocated
140          if (it.hasNext() || (r != a && i < r.length))
141              return resizeAndFinishToArray(r, i, it);
142 <        if (i < r.length)
142 >        if (i < r.length)
143              r[i] = null; // null-terminate if provided array is too big
144          return r;
145      }
# Line 154 | Line 154 | public abstract class AbstractCollection
154       * @return larger array containing same elements
155       */
156      private static <T> T[] resizeAndFinishToArray(T[] r, int i, Iterator it) {
157 <        while (it.hasNext()) {
157 >        while (it.hasNext()) {
158              int cap = r.length;
159              if (i < cap)
160                  r[i++] = (T)it.next();
# Line 167 | Line 167 | public abstract class AbstractCollection
167                  throw new OutOfMemoryError("Required array size too large");
168          }
169          // trim if overallocated
170 <        return i == r.length? r : Arrays.copyOf(r, i);
170 >        return i == r.length? r : Arrays.copyOf(r, i);
171      }
172  
173      // Modification Operations

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines