From 9484f1f4b422eee819c75f6283c5092efc23223f Mon Sep 17 00:00:00 2001 From: abies Date: Sun, 12 Oct 2014 22:02:58 +0200 Subject: [PATCH] Added Iterable support for GeometryList, so it can be use with foreach statements --- .../com/jme3/renderer/queue/GeometryList.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/queue/GeometryList.java b/jme3-core/src/main/java/com/jme3/renderer/queue/GeometryList.java index 692674291..5529ac84e 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/queue/GeometryList.java +++ b/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{ private static final int DEFAULT_SIZE = 32; @@ -145,4 +148,28 @@ public class GeometryList { listSort.sort(geometries,comparator); } } + + public Iterator iterator() { + return new Iterator() { + + 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"); + } + + }; + } } \ No newline at end of file