1 23 24 package org.objectweb.fractal.adl; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.NoSuchElementException ; 30 31 import org.objectweb.deployment.scheduling.core.api.Task; 32 33 36 37 public class BasicTaskMap extends HashMap implements TaskMap { 38 39 private List values = new ArrayList (); 40 41 45 public Task[] getTasks () { 46 return (Task[])values.toArray(new Task[size()]); 47 } 48 49 public Task getTask (final String type, final Object id) 50 throws NoSuchElementException 51 { 52 Task t = (Task)get(new Key(type, id)); 53 if (t == null) { 54 throw new NoSuchElementException (); 55 } 56 return t; 57 } 58 59 public void addTask (final String type, final Object id, final Task task) { 60 Key key = new Key(type, id); 61 if (get(key) == null) { 62 put(key, task); 63 values.add(task); 64 } 65 } 66 67 71 static class Key { 72 73 public final String type; 74 75 public final Object id; 76 77 public Key (final String type, final Object id) { 78 this.type = type; 79 this.id = id; 80 } 81 82 public boolean equals (final Object o) { 83 if (o instanceof Key) { 84 Key k = (Key)o; 85 return k.type.equals(type) && k.id.equals(id); 86 } 87 return false; 88 } 89 90 public int hashCode () { 91 return type.hashCode()*id.hashCode(); 92 } 93 } 94 } 95 | Popular Tags |