diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java index bf92b05b41844fd6feea39ead31c7c99c3aa4425..0b89465337467f64b8016159e9c19fe88d39ebc3 100644 --- a/src/es/markse/Contenedor.java +++ b/src/es/markse/Contenedor.java @@ -11,7 +11,7 @@ import java.util.List; * @author victorm */ public abstract class Contenedor { - private final List<Trayecto> trayectos = new ArrayList<>(); + protected final List<Trayecto> trayectos = new ArrayList<>(); private ISO6346 codigo; private float pesoTara; @@ -117,12 +117,12 @@ public abstract class Contenedor { * @param costePorMilla El coste por milla recorrida en un trayecto * @return el precio total del transporte del contenedor */ - public double precioTransporteTotalContenedor(double costeDiarioTrayecto, double costePorMilla) { + public double precioTransporteTotalContenedor() { if (this.trayectos.isEmpty()) return 0.0; double precioTotal = 0.0; for (Trayecto t : this.trayectos) { - precioTotal += t.precioTrayectoEnEuros(costeDiarioTrayecto, costePorMilla); + precioTotal += t.precioTrayectoEnEuros(); } return precioTotal; } @@ -138,26 +138,26 @@ public abstract class Contenedor { * @throws IllegalStateException si la fecha fin del ultimo trayecto es superior a la de inicio del nuevo trayecto * @throws IllegalStateException si el puerto/muelle destinos del ultimo trayecto no son los de origen del nuevo. */ - public void anyadirTrayecto(Trayecto t) { - if (t == null) - throw new IllegalArgumentException("El trayecto no puede ser nulo"); - if (this.trayectos.isEmpty()) - this.trayectos.add(t); - else { - Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1); - //Si la fecha fin es mayor a la de inicio del nuevo - if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch()) - throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); - //Si el puerto destino no es el origen del nuevo - if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto())) - throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto"); - //Si el muelle de destino no es el de origen del nuevo - if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador())) - throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto"); - this.trayectos.add(t); - } + public abstract void anyadirTrayecto(Trayecto t); + + + + + protected void comprobarDatosContenedor(Trayecto t) { + Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1); + //Si la fecha fin es mayor a la de inicio del nuevo + if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch()) + throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); + //Si el puerto destino no es el origen del nuevo + if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto())) + throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto"); + //Si el muelle de destino no es el de origen del nuevo + if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador())) + throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto"); + this.trayectos.add(t); } + /** * Metodo que devuelve si un contenedor tiene techo * @return si tiene techo (true) o si no lo tiene (false) diff --git a/src/es/markse/Estandar.java b/src/es/markse/Estandar.java index eaaa93d10d068ab10253c9c9b2c2743f8f759b12..f63909c672653685f29186a9d501c8ede88c7d9f 100644 --- a/src/es/markse/Estandar.java +++ b/src/es/markse/Estandar.java @@ -6,5 +6,19 @@ public class Estandar extends Contenedor { pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); } + @Override + public void anyadirTrayecto(Trayecto t) { + if (t==null) { + throw new IllegalArgumentException("h"); + } + if (this.trayectos.isEmpty()) { + this.anyadirTrayecto(t); + } + else { + comprobarDatosContenedor(t); + } + } + + } diff --git a/src/es/markse/FlatRack.java b/src/es/markse/FlatRack.java index 56ceaf81738e1ce990b389a56f0672b99c841954..b8540192cec55a1d90cf7d0e9d9bd9a8191e5082 100644 --- a/src/es/markse/FlatRack.java +++ b/src/es/markse/FlatRack.java @@ -5,7 +5,29 @@ public class FlatRack extends Contenedor{ public FlatRack(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual, pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); - // TODO Auto-generated constructor stub + } + @Override + public void anyadirTrayecto(Trayecto t) { + if (t==null) { + throw new IllegalArgumentException("h"); + } + + if (t instanceof TCamion) { + throw new IllegalArgumentException("No"); + } + + if (t instanceof TPackCamionBarco) { + throw new IllegalArgumentException("No"); + } + + if (t instanceof TPackCamionTren) { + throw new IllegalArgumentException("No"); + } + + comprobarDatosContenedor(t); + } + + } diff --git a/src/es/markse/Refrigerado.java b/src/es/markse/Refrigerado.java index 4eaa62be98fc316a746d1a262f34364666090206..fbf514eca2c6602ccc49f19bd5480e5cead16c34 100644 --- a/src/es/markse/Refrigerado.java +++ b/src/es/markse/Refrigerado.java @@ -5,7 +5,32 @@ public class Refrigerado extends Contenedor{ public Refrigerado(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual, pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); - } -} + @Override + public void anyadirTrayecto(Trayecto t) { + if (t==null) { + throw new IllegalArgumentException("h"); + } + + if (t instanceof TTren) { + throw new IllegalArgumentException("No"); + } + + if (t instanceof TPackCamionBarco) { + throw new IllegalArgumentException("No"); + } + + if (t instanceof TPackCamionTren) { + throw new IllegalArgumentException("No"); + } + comprobarDatosContenedor(t); + + + } + + + + + +} \ No newline at end of file diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java index 573f76fe8eb09822c6abcb7c780cd47a142b7f36..f8929976668cf99c1de1ffe62c6e6711531be31a 100644 --- a/uses/es/markse/ContenedorTest.java +++ b/uses/es/markse/ContenedorTest.java @@ -21,7 +21,7 @@ public class ContenedorTest { @Test public void testContenedor() { ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); - Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); + Contenedor c1 = new Estandar(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); assertEquals("ZREJ0567310", c1.getCodigo()); assertEquals(100.0f, c1.obtenerPesoKilos(), 0.001f); assertEquals(400.0f, c1.cargaUtilContenedorKilos(), 0.001f);