Android Open Source - observer Task Bin






From Project

Back to project page observer.

License

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.

Java Source Code

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();
  }
}




Java Source Code List

uk.ac.horizon.observer.model.Observation.java
uk.ac.horizon.observer.model.Place.java
uk.ac.horizon.observer.model.Places.java
uk.ac.horizon.observer.model.Stop.java
uk.ac.horizon.observer.model.TaskBin.java
uk.ac.horizon.observer.model.Task.java
uk.ac.horizon.observer.vc.PlacesActivity.java
uk.ac.horizon.observer.vc.PlacesFragment.java
uk.ac.horizon.observer.vc.SettingsActivity.java
uk.ac.horizon.observer.vc.SettingsFragment.java
uk.ac.horizon.observer.vc.TaskFragment.java
uk.ac.horizon.observer.vc.TasksActivity.java