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

fixing the Simple Traffic Lights controller test + beautifying the code

refs 222
parent e2f75bb4
No related branches found
No related tags found
No related merge requests found
......@@ -72,4 +72,25 @@ public class EcoreUtils {
result.add((T) 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.
*
* @param targetClass
* - a class representing type T
* @param sourceList
* - an EList with objects of type S
* @return an object of type T or null if none exists
*/
@SuppressWarnings("unchecked")
public static <S, T extends S> T pickFirstInstanceOf(Class<T> targetClass,
EList<S> sourceList) {
if (sourceList == null)
return null;
for (S sourceElement : sourceList)
if (targetClass.isAssignableFrom(sourceElement.getClass()))
return (T) sourceElement;
return null;
}
}
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