Skip to content
Snippets Groups Projects
Commit cc71308f authored by Daniel Ratiu's avatar Daniel Ratiu
Browse files

a new utility method pickInstanceOf(Collection<Class> targetClasses, List<S> sourceElements)

refs 311
parent 6e5c24ce
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
import java.util.Collection;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
......@@ -28,7 +30,7 @@ import org.eclipse.emf.common.util.EList;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: BB06B0A08486E75019A90CE8468CCDCA
* @ConQAT.Rating YELLOW Hash: 51B869B8A1DFDD5FB34EB9FE8677057F
*/
public class EcoreUtils {
......@@ -73,6 +75,37 @@ public class EcoreUtils {
return ECollections.unmodifiableEList(result);
}
/**
* From a given EList with source objects of type S create another
* unmodifiable EList with objects of one of the types given by the
* parameter targetClasses, whereby those types are a sub-type of S. The
* resulting EList is unmodifiable thereby it represents only a view over
* the source list.
*
* @param targetClasses
* - a collection of classes representing types of elements to be
* picked
* @param sourceList
* - an EList with objects of type S
* @return an unmodifiable EList of objects of type S containing only the
* targetClasses instances
*/
public static <S> EList<S> pickInstanceOf(
Collection<Class<?>> targetClasses, EList<S> sourceList) {
if (sourceList == null)
return null;
EList<S> result = new BasicEList<S>();
for (S sourceElement : sourceList) {
Class<?> sourceClass = sourceElement.getClass();
for (Class<?> targetClass : targetClasses) {
if (targetClass.isAssignableFrom(sourceClass)) {
result.add(sourceElement);
}
}
}
return ECollections.unmodifiableEList(result);
}
/**
* From a given EList with source objects of type S pick the first object
* with type T, whereby T is a sub-type of S.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment