[Mmil-commits] r79 - trunk/src/fr/loria/talaris/mmil

alexandredenis at users.gforge.inria.fr alexandredenis at users.gforge.inria.fr
Mar 14 Déc 19:44:23 CET 2010


Author: alexandredenis
Date: 2010-12-14 19:44:23 +0100 (Tue, 14 Dec 2010)
New Revision: 79

Added:
   trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java
Log:
Added an IndexMMILIterator

Added: trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java
===================================================================
--- trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java	                        (rev 0)
+++ trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java	2010-12-14 18:44:23 UTC (rev 79)
@@ -0,0 +1,56 @@
+package fr.loria.talaris.mmil;
+
+import java.util.*;
+
+/**
+ * A IndexMMILIterator iterates through the entities of a component in their
+ * index order.
+ * @author Alexandre Denis
+ */
+public class IndexMMILIterator implements MMILIterator
+{
+	private int currentIndex;
+	private List<MMILEntity> iteratorEntities;
+
+
+	/**
+	 * Creates an IndexMMILIterator over the entities of the given component.
+	 * @param mmil
+	 */
+	public IndexMMILIterator(MMILComponent mmil)
+	{
+		currentIndex = 0;
+		iteratorEntities = new ArrayList<MMILEntity>(mmil.getEntities());
+		Collections.sort(iteratorEntities, new Comparator<MMILEntity>()
+		{
+			@Override
+			public int compare(MMILEntity o1, MMILEntity o2)
+			{
+				return o1.getIndex() - o2.getIndex();
+			}
+		});
+	}
+
+
+	@Override
+	public boolean hasNext()
+	{
+		return currentIndex < iteratorEntities.size();
+	}
+
+
+	@Override
+	public MMILEntity next()
+	{
+		if (hasNext())
+			return iteratorEntities.get(currentIndex++);
+		else throw new NoSuchElementException();
+	}
+
+
+	@Override
+	public void remove()
+	{
+		throw new UnsupportedOperationException();
+	}
+}




More information about the Mmil-commits mailing list