Browse Source

Merge pull request #181 from abies/IterableGeometryList

Added Iterable<Geometry> support for GeometryList
shadowislord 11 năm trước cách đây
mục cha
commit
e15b86d0ba

+ 28 - 1
jme3-core/src/main/java/com/jme3/renderer/queue/GeometryList.java

@@ -31,6 +31,9 @@
  */
 package com.jme3.renderer.queue;
 
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
 import com.jme3.renderer.Camera;
 import com.jme3.scene.Geometry;
 import com.jme3.util.ListSort;
@@ -43,7 +46,7 @@ import com.jme3.util.ListSort;
  * @author Three Rings - better sorting alg.
  * @author Kirill Vainer
  */
-public class GeometryList {
+public class GeometryList implements Iterable<Geometry>{
 
     private static final int DEFAULT_SIZE = 32;
 
@@ -145,4 +148,28 @@ public class GeometryList {
             listSort.sort(geometries,comparator);
         }
     }
+
+    public Iterator<Geometry> iterator() {
+        return new Iterator<Geometry>() {
+
+            int index = 0;
+            
+            public boolean hasNext() {
+                return index < size();
+            }
+
+            
+            public Geometry next() {
+                if ( index >= size() ) {
+                    throw new NoSuchElementException("Geometry list has only " + size() + " elements");
+                }
+                return get(index++);
+            }
+            
+            public void remove() {
+                throw new UnsupportedOperationException("Geometry list doesn't support iterator removal");
+            }
+            
+        };
+    }
 }