Advertisement
Guest User

despacho class

a guest
Feb 23rd, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package fp.grados.tipos;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5.  
  6. import fp.grados.excepciones.ExcepcionDespachoNoValido;
  7.  
  8. public class DespachoImpl extends EspacioImpl implements Despacho {
  9.    
  10.     public Set<Profesor> profesores;
  11.    
  12.     public DespachoImpl(TipoEspacio tipo, String nombre, Integer capacidad,
  13.             Integer planta, Set<Profesor> profesores){
  14.         super(tipo, nombre, capacidad, planta);
  15.         tipo = TipoEspacio.OTRO;
  16.         checkNumeroProfesores(profesores, capacidad);
  17.         this.profesores = profesores;
  18.         checkTipo(tipo);
  19.  
  20.     }  
  21.    
  22.     public DespachoImpl(TipoEspacio tipo, String nombre, Integer capacidad,
  23.             Integer planta, Profesor profesor){
  24.         super(tipo, nombre, capacidad, planta);
  25.         tipo = TipoEspacio.OTRO;
  26.         this.profesores = new HashSet<Profesor>();
  27.         this.profesores.add(profesor);
  28.         checkNumeroProfesores(profesores, capacidad);
  29.         checkTipo(tipo);
  30.  
  31.     }
  32.    
  33.     public DespachoImpl(TipoEspacio tipo, String nombre, Integer capacidad,
  34.             Integer planta){
  35.         super(tipo, nombre, capacidad, planta);
  36.         tipo = TipoEspacio.OTRO;
  37.         profesores = new HashSet<Profesor>();
  38.     }
  39.    
  40.     //Checks
  41.     public void checkNumeroProfesores(Set<Profesor> p, Integer c) {
  42.         if(p.size() > c){
  43.             throw new ExcepcionDespachoNoValido("Capacidad de despacho superada");
  44.         }
  45.     }
  46.    
  47.     public void checkTipo(TipoEspacio tipo){
  48.         if(!(tipo.equals(TipoEspacio.OTRO))){
  49.             throw new ExcepcionDespachoNoValido("Tipo invalido de espacio");
  50.         }
  51.     }
  52.    
  53.    
  54.     @Override
  55.     public void setTipo(TipoEspacio t){
  56.         throw new UnsupportedOperationException("No se debe cambiar el tipo de despacho");
  57.     }
  58.  
  59.     public Set<Profesor> getProfesores() {
  60.         return profesores;
  61.     }
  62.     @Override
  63.     public String toString(){
  64.         String s;
  65.         s = super.toString() + profesores.toString();
  66.         return s;
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement