package example;

import java.util.ArrayList;
import java.util.Observer;
import java.util.Observable;

public class EmployeeObserver implements Observer {
  private ArrayList<Employee> myEmployees = new ArrayList<Employee>();
  private String id;

  public EmployeeObserver(String id) {
    this.id = id;
  }

  public void addObservable( Employee e ) {
    myEmployees.add(e);
  }

  public void removeObservable( Employee e ) {
    myEmployees.remove(e);
  }

  public void update( Observable obj, Object arg ) {
    Employee e = (Employee) obj;
    if( myEmployees.contains(e) ) {
      System.out.println(id + ": ocorreu uma mudança em " + e.getName() + 
                         " e o novo salario eh " +  e.getSalary());
    }
  }
}
