Michael Ludwig avatar Michael Ludwig committed 40b4358

Update tasks API to no longer use TypeId

Comments (0)

Files changed (4)


 import java.util.Map;
 import java.util.Set;
-import com.lhkbob.entreri.TypeId;
+import com.lhkbob.entreri.ComponentData;
 public class Job implements Runnable {
     private final Task[] tasks;
     private final Map<Class<? extends Result>, List<ResultReporter>> resultMethods;
     private final boolean needsExclusiveLock;
-    private final List<TypeId<?>> locks;
+    private final List<Class<? extends ComponentData<?>>> locks;
     private final Scheduler scheduler;
     private final String name;
         resultMethods = new HashMap<Class<? extends Result>, List<ResultReporter>>();
         boolean exclusive = false;
-        Set<TypeId<?>> typeLocks = new HashSet<TypeId<?>>();
+        Set<Class<? extends ComponentData<?>>> typeLocks = new HashSet<Class<? extends ComponentData<?>>>();
         for (int i = 0; i < tasks.length; i++) {
             this.tasks[i] = tasks[i];
             if (tasks[i] instanceof ParallelAware) {
                 ParallelAware pa = (ParallelAware) tasks[i];
                 exclusive |= pa.isEntitySetModified();
-                typeLocks.addAll(pa.getAccessedComponentes());
+                typeLocks.addAll(pa.getAccessedComponents());
             } else {
                 // must assume it could touch anything
                 exclusive = true;
             locks = null;
         } else {
             needsExclusiveLock = false;
-            locks = new ArrayList<TypeId<?>>(typeLocks);
+            locks = new ArrayList<Class<? extends ComponentData<?>>>(typeLocks);
             // give locks a consistent ordering
-            Collections.sort(locks, new Comparator<TypeId<?>>() {
+            Collections.sort(locks, new Comparator<Class<? extends ComponentData<?>>>() {
-                public int compare(TypeId<?> o1, TypeId<?> o2) {
-                    return o1.getId() - o2.getId();
+                public int compare(Class<? extends ComponentData<?>> o1,
+                                   Class<? extends ComponentData<?>> o2) {
+                    return o1.getName().compareTo(o2.getName());


 import java.util.Set;
-import com.lhkbob.entreri.TypeId;
+import com.lhkbob.entreri.ComponentData;
 public interface ParallelAware {
     // FIXME make sure to document that these cannot change for an instance
-    public Set<TypeId<?>> getAccessedComponentes();
+    public Set<Class<? extends ComponentData<?>>> getAccessedComponents();
     public boolean isEntitySetModified();


 import java.util.concurrent.locks.ReentrantLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import com.lhkbob.entreri.ComponentData;
 import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.TypeId;
 public class Scheduler {
     private final ThreadGroup schedulerGroup;
     // locks per component data type, this map is filled
     // dynamically the first time each type is requested
-    private final ConcurrentHashMap<TypeId<?>, ReentrantLock> typeLocks;
+    private final ConcurrentHashMap<Class<? extends ComponentData<?>>, ReentrantLock> typeLocks;
     private final EntitySystem system;
         schedulerGroup = new ThreadGroup("job-scheduler");
         exclusiveLock = new ReentrantReadWriteLock();
-        typeLocks = new ConcurrentHashMap<TypeId<?>, ReentrantLock>();
+        typeLocks = new ConcurrentHashMap<Class<? extends ComponentData<?>>, ReentrantLock>();
     public EntitySystem getEntitySystem() {
         return exclusiveLock;
-    ReentrantLock getTypeLock(TypeId<?> id) {
+    ReentrantLock getTypeLock(Class<? extends ComponentData<?>> id) {
         ReentrantLock lock = typeLocks.get(id);
         if (lock == null) {
             // this will either return the newly constructed lock, or 


 import com.lhkbob.entreri.ComponentData;
 import com.lhkbob.entreri.ComponentIterator;
 import com.lhkbob.entreri.EntitySystem;
-import com.lhkbob.entreri.TypeId;
 public abstract class SimpleTask implements Task {
         if (iterator == null) {
             iterator = new ComponentIterator(system);
             for (int i = 0; i < optional.length; i++) {
-                ComponentData<?> data = system.createDataInstance(TypeId.get((Class) processMethod.getParameterTypes()[i]));
+                ComponentData<?> data = system.createDataInstance((Class) processMethod.getParameterTypes()[i]);
                 if (optional[i]) {
                 } else {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.