Back to project page observer.
The source code is released under:
GNU General Public License
If you think the Android project observer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package uk.ac.horizon.observer.model; /*from w ww .j a va 2 s.co m*/ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import android.content.Context; /** * A singleton Map of Tasks. * @author pszjmb * */ public class TaskBin { private static TaskBin instance = null; private Map<String, Task> taskBin; private TaskBin(){ taskBin = new HashMap<String, Task>(); } public static TaskBin getInstance(){ if(null == instance){ instance = new TaskBin(); } return instance; } /** * Ensures that only one task with the given name is added. If * a second entry is attempted to be added, then the first is removed, * and none are added. * @param t */ public Task addTask(Task t){ if(!taskBin.containsKey(t.getName())){ return taskBin.put(t.getName(), t); }else{ return removeTask(t); } } private Task removeTask(Task t){ return taskBin.remove(t.getName()); } /** * Adds all task observations and then clears the tasks. * @param context */ public void reset(Context context){ for(Entry<String, Task> entry : taskBin.entrySet()){ entry.getValue().addObservation(context); } taskBin.clear(); } }