[Mmil-commits] r80 - in trunk/src/fr/loria/talaris/mmil: . iterators

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


Author: alexandredenis
Date: 2010-12-14 19:45:57 +0100 (Tue, 14 Dec 2010)
New Revision: 80

Added:
   trunk/src/fr/loria/talaris/mmil/iterators/
   trunk/src/fr/loria/talaris/mmil/iterators/IndexMMILIterator.java
   trunk/src/fr/loria/talaris/mmil/iterators/MMILIterator.java
   trunk/src/fr/loria/talaris/mmil/iterators/PostfixMMILIterator.java
Removed:
   trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java
   trunk/src/fr/loria/talaris/mmil/MMILIterator.java
   trunk/src/fr/loria/talaris/mmil/PostfixMMILIterator.java
Modified:
   trunk/src/fr/loria/talaris/mmil/DefaultMMILComponent.java
Log:
Created a new package fr.loria.talaris.mmil.iterators

Modified: trunk/src/fr/loria/talaris/mmil/DefaultMMILComponent.java
===================================================================
--- trunk/src/fr/loria/talaris/mmil/DefaultMMILComponent.java	2010-12-14 18:44:23 UTC (rev 79)
+++ trunk/src/fr/loria/talaris/mmil/DefaultMMILComponent.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -2,6 +2,8 @@
 
 import java.util.*;
 
+import fr.loria.talaris.mmil.iterators.PostfixMMILIterator;
+
 /**
  * Default implementation of the MMILComponent interface.
  * @author Alexandre Denis

Deleted: trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java
===================================================================
--- trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java	2010-12-14 18:44:23 UTC (rev 79)
+++ trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -1,56 +0,0 @@
-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();
-	}
-}

Deleted: trunk/src/fr/loria/talaris/mmil/MMILIterator.java
===================================================================
--- trunk/src/fr/loria/talaris/mmil/MMILIterator.java	2010-12-14 18:44:23 UTC (rev 79)
+++ trunk/src/fr/loria/talaris/mmil/MMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -1,12 +0,0 @@
-package fr.loria.talaris.mmil;
-
-import java.util.Iterator;
-
-/**
- * A MMILIterator iterates over MMILEntities.
- * @author Alexandre Denis
- */
-public interface MMILIterator extends Iterator<MMILEntity>
-{
-
-}

Deleted: trunk/src/fr/loria/talaris/mmil/PostfixMMILIterator.java
===================================================================
--- trunk/src/fr/loria/talaris/mmil/PostfixMMILIterator.java	2010-12-14 18:44:23 UTC (rev 79)
+++ trunk/src/fr/loria/talaris/mmil/PostfixMMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -1,95 +0,0 @@
-package fr.loria.talaris.mmil;
-
-import java.util.*;
-
-/**
- * A PostfixMMILIterator iterates through the entities of a component in a postfix order.
- * @author Alexandre Denis
- */
-public class PostfixMMILIterator implements MMILIterator
-{
-	private int currentIndex;
-	private MMILComponent mmil;
-	private List<MMILEntity> iteratorEntities;
-
-
-	/**
-	 * Creates a PostfixMMILIterator over the entities of the given component. The component must
-	 * have a main event otherwise a MMILException is thrown.
-	 * @param mmil
-	 */
-	public PostfixMMILIterator(MMILComponent mmil)
-	{
-		if (!mmil.hasMainEvent())
-			throw new MMILException("Unable to create a PostfixMMILIterator "
-					+ "on following component because it does not contain a main event:\n" + mmil);
-		else
-		{
-			this.mmil = mmil;
-			this.currentIndex = 0;
-			this.iteratorEntities = new ArrayList<MMILEntity>();
-			traverse(mmil.getMainEvent(), new HashSet<MMILEntity>());
-		}
-	}
-
-
-	/**
-	 * Returns the children of the given entity in their index order. The children are all connected
-	 * entities without the visited entities.
-	 * @param entity
-	 * @param visited
-	 * @return
-	 */
-	private List<MMILEntity> getChildren(MMILEntity entity, Set<MMILEntity> visited)
-	{
-		List<MMILEntity> ret = new ArrayList<MMILEntity>(mmil.getEntitiesConnectedTo(entity));
-		ret.removeAll(visited);
-		Collections.sort(ret, new Comparator<MMILEntity>()
-		{
-			@Override
-			public int compare(MMILEntity o1, MMILEntity o2)
-			{
-				return o1.getIndex() - o2.getIndex();
-			}
-		});
-		return ret;
-	}
-
-	/**
-	 * Traverses the given entity and updates the iterator entities list in a postfix order.
-	 * @param entity
-	 * @param visited
-	 */
-	private void traverse(MMILEntity entity, Set<MMILEntity> visited)
-	{
-		visited.add(entity);
-
-		for(MMILEntity child : getChildren(entity, visited))
-			traverse(child, visited);
-
-		iteratorEntities.add(entity);
-	}
-
-
-	@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();
-	}
-}

Copied: trunk/src/fr/loria/talaris/mmil/iterators/IndexMMILIterator.java (from rev 79, trunk/src/fr/loria/talaris/mmil/IndexMMILIterator.java)
===================================================================
--- trunk/src/fr/loria/talaris/mmil/iterators/IndexMMILIterator.java	                        (rev 0)
+++ trunk/src/fr/loria/talaris/mmil/iterators/IndexMMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -0,0 +1,58 @@
+package fr.loria.talaris.mmil.iterators;
+
+import java.util.*;
+
+import fr.loria.talaris.mmil.*;
+
+/**
+ * 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();
+	}
+}

Copied: trunk/src/fr/loria/talaris/mmil/iterators/MMILIterator.java (from rev 78, trunk/src/fr/loria/talaris/mmil/MMILIterator.java)
===================================================================
--- trunk/src/fr/loria/talaris/mmil/iterators/MMILIterator.java	                        (rev 0)
+++ trunk/src/fr/loria/talaris/mmil/iterators/MMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -0,0 +1,14 @@
+package fr.loria.talaris.mmil.iterators;
+
+import java.util.Iterator;
+
+import fr.loria.talaris.mmil.MMILEntity;
+
+/**
+ * A MMILIterator iterates over MMILEntities.
+ * @author Alexandre Denis
+ */
+public interface MMILIterator extends Iterator<MMILEntity>
+{
+
+}

Copied: trunk/src/fr/loria/talaris/mmil/iterators/PostfixMMILIterator.java (from rev 78, trunk/src/fr/loria/talaris/mmil/PostfixMMILIterator.java)
===================================================================
--- trunk/src/fr/loria/talaris/mmil/iterators/PostfixMMILIterator.java	                        (rev 0)
+++ trunk/src/fr/loria/talaris/mmil/iterators/PostfixMMILIterator.java	2010-12-14 18:45:57 UTC (rev 80)
@@ -0,0 +1,97 @@
+package fr.loria.talaris.mmil.iterators;
+
+import java.util.*;
+
+import fr.loria.talaris.mmil.*;
+
+/**
+ * A PostfixMMILIterator iterates through the entities of a component in a postfix order.
+ * @author Alexandre Denis
+ */
+public class PostfixMMILIterator implements MMILIterator
+{
+	private int currentIndex;
+	private MMILComponent mmil;
+	private List<MMILEntity> iteratorEntities;
+
+
+	/**
+	 * Creates a PostfixMMILIterator over the entities of the given component. The component must
+	 * have a main event otherwise a MMILException is thrown.
+	 * @param mmil
+	 */
+	public PostfixMMILIterator(MMILComponent mmil)
+	{
+		if (!mmil.hasMainEvent())
+			throw new MMILException("Unable to create a PostfixMMILIterator "
+					+ "on following component because it does not contain a main event:\n" + mmil);
+		else
+		{
+			this.mmil = mmil;
+			this.currentIndex = 0;
+			this.iteratorEntities = new ArrayList<MMILEntity>();
+			traverse(mmil.getMainEvent(), new HashSet<MMILEntity>());
+		}
+	}
+
+
+	/**
+	 * Returns the children of the given entity in their index order. The children are all connected
+	 * entities without the visited entities.
+	 * @param entity
+	 * @param visited
+	 * @return
+	 */
+	private List<MMILEntity> getChildren(MMILEntity entity, Set<MMILEntity> visited)
+	{
+		List<MMILEntity> ret = new ArrayList<MMILEntity>(mmil.getEntitiesConnectedTo(entity));
+		ret.removeAll(visited);
+		Collections.sort(ret, new Comparator<MMILEntity>()
+		{
+			@Override
+			public int compare(MMILEntity o1, MMILEntity o2)
+			{
+				return o1.getIndex() - o2.getIndex();
+			}
+		});
+		return ret;
+	}
+
+	/**
+	 * Traverses the given entity and updates the iterator entities list in a postfix order.
+	 * @param entity
+	 * @param visited
+	 */
+	private void traverse(MMILEntity entity, Set<MMILEntity> visited)
+	{
+		visited.add(entity);
+
+		for(MMILEntity child : getChildren(entity, visited))
+			traverse(child, visited);
+
+		iteratorEntities.add(entity);
+	}
+
+
+	@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