Advertisement
Guest User

Espacio class

a guest
Feb 23rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package fp.grados.tipos;
  2.  
  3. import fp.grados.excepciones.ExcepcionEspacioNoValido;
  4.  
  5. public class EspacioImpl implements Espacio {
  6.    
  7.     public TipoEspacio tipo;
  8.     public String nombre;
  9.     public Integer capacidad;
  10.     public Integer planta;
  11.    
  12.     public EspacioImpl(TipoEspacio tipo, String nombre, Integer capacidad, Integer planta){
  13.         checkCapacidad(capacidad);
  14.         this.tipo = tipo;
  15.         this.nombre = nombre;
  16.         this.capacidad = capacidad;
  17.         this.planta = planta;
  18.     }
  19.  
  20.     //Checks
  21.     public void checkCapacidad(Integer c){
  22.         if(c <= 0){
  23.             throw new ExcepcionEspacioNoValido("Capacidad debe ser mayor que 0");
  24.         }
  25.     }
  26.     @Override
  27.     public TipoEspacio getTipo() {
  28.         return tipo;
  29.     }
  30.  
  31.     @Override
  32.     public String getNombre() {
  33.         return nombre;
  34.     }
  35.  
  36.     @Override
  37.     public Integer getCapacidad() {
  38.         return capacidad;
  39.     }
  40.  
  41.     @Override
  42.     public Integer getPlanta() {
  43.         return planta;
  44.     }
  45.  
  46.     @Override
  47.     public void setTipo(TipoEspacio tipo) {
  48.         this.tipo = tipo;
  49.  
  50.     }
  51.  
  52.     @Override
  53.     public void setNombre(String nombre) {
  54.         this.nombre = nombre;
  55.  
  56.     }
  57.  
  58.     @Override
  59.     public void setCapacidad(Integer capacidad) {
  60.         checkCapacidad(capacidad);
  61.         this.capacidad = capacidad;
  62.  
  63.     }
  64.    
  65.     public String toString() {
  66.         String s = nombre + " (" + "planta " + planta + ")";
  67.         return s;
  68.     }
  69.     //Equals
  70.     public boolean equals(Object o){
  71.         boolean r = false;
  72.         if(o instanceof Espacio){
  73.             Espacio p = (Espacio) o;
  74.             r = this.getNombre().equals(p.getNombre()) && this.getPlanta().equals(p.getPlanta());
  75.         }
  76.         return r;
  77.     }
  78.    
  79.     //Hashcode
  80.     public int hashCode(){
  81.         return this.getNombre().hashCode()*31 + this.getPlanta().hashCode();
  82.     }
  83.  
  84.     //Orden
  85.     @Override
  86.     public int compareTo(Espacio l) {
  87.         int res = this.getPlanta().compareTo(l.getPlanta());
  88.         if (res == 0){
  89.             res = this.getNombre().compareToIgnoreCase(l.getNombre());
  90.         }
  91.         return res;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement